jenkins-bot has submitted this change and it was merged.
Change subject: replace.py: fix handling of addedCat
......................................................................
replace.py: fix handling of addedCat
In ReplaceRobot, with addedCat set, get categories from wikitext
instead of API, otherwise all categories will be then added.
Change-Id: Ie68e148d50ac057f8919277606e05c99ffacc609
---
M scripts/replace.py
1 file changed, 11 insertions(+), 5 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/replace.py b/scripts/replace.py
index b815609..2aa2d34 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -425,6 +425,7 @@
replaced.
* addedCat - If set to a value, add this category to every page
touched.
+ It can be a string or a Category object.
Structure of the exceptions dictionary:
This dictionary can have these keys:
@@ -462,10 +463,13 @@
self.recursive = recursive
if site:
self.site = site
+
if addedCat:
- cat_ns = site.category_namespaces()[0]
- self.addedCat = pywikibot.Page(self.site,
- cat_ns + ':' + addedCat)
+ if isinstance(addedCat, pywikibot.Category):
+ self.addedCat = addedCat
+ else:
+ self.addedCat = pywikibot.Category(self.site, addedCat)
+
self.sleep = sleep
self.summary = summary
self.changed_pages = 0
@@ -595,8 +599,10 @@
pywikibot.output(u'No changes were necessary in %s'
% page.title(asLink=True))
break
- if hasattr(self, "addedCat"):
- cats = page.categories(nofollow_redirects=True)
+ if hasattr(self, 'addedCat'):
+ # Fetch only categories in wikitext, otherwise the others will
+ # be explicitly added.
+ cats = textlib.getCategoryLinks(original_text)
if self.addedCat not in cats:
cats.append(self.addedCat)
new_text = textlib.replaceCategoryLinks(new_text,
--
To view, visit
https://gerrit.wikimedia.org/r/214647
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie68e148d50ac057f8919277606e05c99ffacc609
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>