jenkins-bot has submitted this change and it was merged.
Change subject: (bug 59119) Revert "Rm change_category func from
category_redirect.py"
......................................................................
(bug 59119) Revert "Rm change_category func from category_redirect.py"
This reverts commit 682382fbd74d94a6776bd545b3292cf7aa7eb236.
Change-Id: I07f2755a6006d8583e4dd9d5f988de38bee844d3
---
M scripts/category_redirect.py
1 file changed, 57 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index 1a018d4..fa7474b 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -79,6 +79,59 @@
self.edit_request_item = i18n.twtranslate(
self.site.lang, 'category_redirect-edit-request-item')
+ def change_category(self, article, oldCat, newCat, comment=None,
+ sortKey=None):
+ """Given an article in category oldCat, moves it to category
newCat.
+ Moves subcategories of oldCat as well. oldCat and newCat should be
+ Category objects. If newCat is None, the category will be removed.
+
+ This is a copy of portions of [old] catlib.change_category(), with
+ some changes.
+
+ """
+ oldtext = article.get(get_redirect=True, force=True)
+ if newCat in article.categories() or newCat == article:
+ newtext = pywikibot.replaceCategoryInPlace(oldtext, oldCat, None,
+ site=self.site)
+ else:
+ newtext = pywikibot.replaceCategoryInPlace(oldtext, oldCat, newCat,
+ site=self.site)
+ try:
+ # even if no changes, still save the page, in case it needs
+ # an update due to changes in a transcluded template
+ article.put(newtext, comment)
+ if newtext == oldtext:
+ pywikibot.output(u'No changes made in page %s.'
+ % article.title(asLink=True))
+ return False
+ return True
+ except pywikibot.EditConflict:
+ pywikibot.output(u'Skipping %s because of edit conflict'
+ % article.title(asLink=True))
+ except pywikibot.LockedPage:
+ pywikibot.output(u'Skipping locked page %s'
+ % article.title(asLink=True))
+ self.edit_requests.append({
+ 'title': article.title(asLink=True, textlink=True),
+ 'oldcat': oldCat.title(asLink=True, textlink=True),
+ 'newcat': newCat.title(asLink=True, textlink=True)})
+ except pywikibot.SpamfilterError as error:
+ pywikibot.output(
+ u'Changing page %s blocked by spam filter (URL=%s)'
+ % (article.title(asLink=True), error.url))
+ except pywikibot.NoUsername:
+ pywikibot.output(
+ u"Page %s not saved; sysop privileges required."
+ % article.title(asLink=True))
+ self.edit_requests.append({
+ 'title': article.title(asLink=True, textlink=True),
+ 'oldcat': oldCat.title(asLink=True, textlink=True),
+ 'newcat': newCat.title(asLink=True, textlink=True)})
+ except pywikibot.PageNotSaved as error:
+ pywikibot.output(u"Saving page %s failed: %s"
+ % (article.title(asLink=True), error))
+ return False
+
def move_contents(self, oldCatTitle, newCatTitle, editSummary):
"""The worker function that moves pages out of oldCat into
newCat"""
while True:
@@ -95,8 +148,8 @@
found, moved = 0, 0
for article in oldCat.members():
found += 1
- changed = article.change_category(oldCat, newCat,
- comment=comment)
+ changed = self.change_category(article, oldCat, newCat,
+ comment=comment)
if changed:
moved += 1
@@ -111,8 +164,8 @@
old_text = doc.get()
except pywikibot.Error:
continue
- changed = doc.change_category(oldCat, newCat,
- comment=comment)
+ changed = self.change_category(doc, oldCat, newCat,
+ comment=comment)
if changed:
moved += 1
--
To view, visit
https://gerrit.wikimedia.org/r/104505
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I07f2755a6006d8583e4dd9d5f988de38bee844d3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot