jenkins-bot has submitted this change and it was merged.
Change subject: [bug 60564] Re-enable pageName for summary message
......................................................................
[bug 60564] Re-enable pageName for summary message
- pageName is extracted from command option handled by pagegenerators
if availlable. Otherwise we ask for the message.
- -images option is deprecated. -imagelinks from pagegenerators is
used. We just append the right option command to the option list
- deprecated setAction() is removed
- docu replacement from pagegenerators
Change-Id: Ie65f05430e14d4b18060b26577232a47ea51b78d
---
M scripts/delete.py
1 file changed, 47 insertions(+), 44 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/delete.py b/scripts/delete.py
index cf8c3d4..60c9ed8 100644
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -3,20 +3,20 @@
This script can be used to delete and undelete pages en masse.
Of course, you will need an admin account on the relevant wiki.
-Syntax: python delete.py [-category categoryName]
+These command line parameters can be used to specify which pages to work on:
-Command line options:
+¶ms;
--page: Delete specified page
--cat: Delete all pages in the given category.
--links: Delete all pages linked from a given page.
--file: Delete all pages listed in a text file.
--ref: Delete all pages referring from a given page.
--images: Delete all images used on a given page.
--always: Don't prompt to delete pages, just do it.
--summary: Supply a custom edit summary.
--undelete: Actually undelete pages instead of deleting.
- Obviously makes sense only with -page and -file.
+Furthermore, the following command line parameters are supported:
+
+-always: Don't prompt to delete pages, just do it.
+
+-summary: Supply a custom edit summary.
+
+-undelete: Actually undelete pages instead of deleting.
+ Obviously makes sense only with -page and -file.
+
+Usage: python delete.py [-category categoryName]
Examples:
@@ -25,7 +25,7 @@
python delete.py -cat:"To delete" -always
"""
#
-# (C) Pywikibot team, 2013
+# (c) Pywikibot team, 2014
#
# Distributed under the terms of the MIT license.
#
@@ -36,36 +36,45 @@
from pywikibot import i18n
from pywikibot import pagegenerators
+# This is required for the text that is shown when you run this script
+# with the parameter -help.
+docuReplacements = {
+ '¶ms;': pagegenerators.parameterHelp,
+}
+
class DeletionRobot:
""" This robot allows deletion of pages en masse. """
def __init__(self, generator, summary, always=False, undelete=True):
- """ Arguments:
- * generator - A page generator.
- * always - Delete without prompting?
+ """
+ Arguments:
+ * generator - A page generator.
+ * always - Delete without prompting?
"""
self.generator = generator
self.summary = summary
- self.always = always
+ self.prompt = not always
self.undelete = undelete
def run(self):
- """ Starts the robot's action. """
- #Loop through everything in the page generator and delete it.
+ """ Starts the robot's action:
+ Loop through everything in the page generator and delete it.
+
+ """
for page in self.generator:
pywikibot.output(u'Processing page %s' % page.title())
if self.undelete:
- page.undelete(self.summary, throttle=True)
+ page.undelete(self.summary)
else:
- page.delete(self.summary, not self.always, throttle=True)
+ page.delete(self.summary, self.prompt)
def main():
genFactory = pagegenerators.GeneratorFactory()
pageName = ''
- summary = ''
+ summary = None
always = False
doImages = False
undelete = False
@@ -84,17 +93,18 @@
else:
summary = arg[len('-summary:'):]
elif arg.startswith('-images'):
- doImages = True
- if len(arg) == len('-images'):
- pageName = pywikibot.input(
- u'Enter the page with the images to delete:')
- else:
- pageName = arg[len('-images'):]
+ pywikibot.output('\n\03{lightred}-image option is deprecated. '
+ 'Please use -imagelinks instead.\03{default}\n')
+ localargs.append('-imagelinks' + arg[7:])
elif arg.startswith('-undelete'):
undelete = True
else:
genFactory.handleArg(arg)
- if not summary:
+ found = arg.find(':') + 1
+ if found:
+ pageName = arg[found:]
+
+ if pageName and not summary:
if arg.startswith('-category'):
summary = i18n.twtranslate(mysite, 'delete-from-category',
{'page': pageName})
@@ -104,30 +114,23 @@
elif arg.startswith('-ref'):
summary = i18n.twtranslate(mysite, 'delete-referring-pages',
{'page': pageName})
+ elif arg.startswith('-imagelinks'):
+ summary = i18n.twtranslate(mysite, 'delete-images',
+ {'page': pageName})
elif arg.startswith('-file'):
summary = i18n.twtranslate(mysite, 'delete-from-file')
-
- if doImages:
- if not summary:
- summary = i18n.twtranslate(mysite, 'delete-images',
- {'page': pageName})
- page = pywikibot.Page(mysite, pageName)
- generator = pagegenerators.ImagesPageGenerator(page)
- if not summary:
+ if summary is None:
summary = pywikibot.input(u'Enter a reason for the %sdeletion:'
% ['', 'un'][undelete])
- if not generator:
- generator = genFactory.getCombinedGenerator()
- if not generator:
- # syntax error, show help text from the top of this file
- pywikibot.showHelp('delete')
- return
+ generator = genFactory.getCombinedGenerator()
if generator:
- pywikibot.setAction(summary)
# We are just deleting pages, so we have no need of using a preloading
# page generator to actually get the text of those pages.
bot = DeletionRobot(generator, summary, always, undelete)
bot.run()
+ else:
+ # Show help text from the top of this file
+ pywikibot.showHelp()
if __name__ == "__main__":
--
To view, visit
https://gerrit.wikimedia.org/r/110153
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie65f05430e14d4b18060b26577232a47ea51b78d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Pyfisch <pyfisch(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>