Xqt has submitted this change and it was merged.
Change subject: Adding option of following redirects
......................................................................
Adding option of following redirects
Bug: 55310
Change-Id: Ie84aa0292270f8a45c0e104a61e037b869f40850
---
M category.py
1 file changed, 11 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
diff --git a/category.py b/category.py
index b9471a1..2061a65 100644
--- a/category.py
+++ b/category.py
@@ -18,6 +18,7 @@
Options for "add" action:
* -person - sort persons by their last name
* -create - If a page doesn't exist, do not skip it, create it instead
+ * -redirect - Follow redirects
If action is "add", the following options are supported:
@@ -229,10 +230,11 @@
'''A robot to mass-add a category to a list of pages.'''
def __init__(self, generator, sort_by_last_name=False, create=False,
- editSummary='', dry=False):
+ editSummary='', follow_redirects = False, dry=False):
self.generator = generator
self.sort = sort_by_last_name
self.create = create
+ self.follow_redirects = follow_redirects
self.site = pywikibot.getSite()
self.always = False
self.dry = dry
@@ -303,7 +305,10 @@
% page.title(asLink=True))
except pywikibot.IsRedirectPage, arg:
redirTarget = pywikibot.Page(self.site, arg.args[0])
- pywikibot.warning(u"Page %s is a redirect to %s; skipping."
+ if self.follow_redirects:
+ text = redirTarget.get()
+ else:
+ pywikibot.warning(u"Page %s is a redirect to %s; skipping."
% (page.title(asLink=True),
redirTarget.title(asLink=True)))
else:
@@ -886,6 +891,7 @@
sort_by_last_name = False
restore = False
create_pages = False
+ follow_redirects = False
deleteEmptySourceCat = True
for arg in pywikibot.handleArgs(*args):
if arg == 'add':
@@ -938,6 +944,8 @@
pagesonly = True
elif arg == '-create':
create_pages = True
+ elif arg =='-redirect':
+ follow_redirects = True
elif arg == '-hist':
withHistory = True
else:
@@ -957,7 +965,7 @@
# pages from the wiki simultaneously.
gen = pagegenerators.PreloadingGenerator(
genFactory.getCombinedGenerator())
- bot = AddCategory(gen, sort_by_last_name, create_pages, editSummary)
+ bot = AddCategory(gen, sort_by_last_name, create_pages, editSummary,
follow_redirects)
bot.run()
elif action == 'remove':
if (fromGiven == False):
--
To view, visit
https://gerrit.wikimedia.org/r/91641
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie84aa0292270f8a45c0e104a61e037b869f40850
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot