http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10725
Revision: 10725 Author: russblau Date: 2012-11-14 18:20:26 +0000 (Wed, 14 Nov 2012) Log Message: ----------- Avoid duplication where page is already in the new category
Modified Paths: -------------- branches/rewrite/scripts/category.py
Modified: branches/rewrite/scripts/category.py =================================================================== --- branches/rewrite/scripts/category.py 2012-11-14 16:56:11 UTC (rev 10724) +++ branches/rewrite/scripts/category.py 2012-11-14 18:20:26 UTC (rev 10725) @@ -395,6 +395,7 @@ def run(self): site = pywikibot.getSite() newCat = catlib.Category(pywikibot.Link('Category:' + self.newCatTitle)) + newcat_contents = set(newCat.members()) # set edit summary message if not self.editSummary: self.editSummary = i18n.twtranslate(site, 'category-replacing',\ @@ -435,9 +436,14 @@ for article in preloadingGen: if not self.titleRegex or re.search(self.titleRegex, article.title()): - catlib.change_category(article, self.oldCat, newCat, + if article in newcat_contents: + catlib.change_category(article, self.oldCat, None, comment=self.editSummary, inPlace=self.inPlace) + else: + catlib.change_category(article, self.oldCat, newCat, + comment=self.editSummary, + inPlace=self.inPlace)
# Move subcategories gen = pagegenerators.SubCategoriesPageGenerator(self.oldCat, @@ -446,9 +452,14 @@ for subcategory in preloadingGen: if not self.titleRegex or re.search(self.titleRegex, subcategory.title()): - catlib.change_category(subcategory, self.oldCat, newCat, + if subcategory in newcat_contents: + catlib.change_category(subcategory, self.oldCat, None, comment=self.editSummary, inPlace=self.inPlace) + else: + catlib.change_category(subcategory, self.oldCat, newCat, + comment=self.editSummary, + inPlace=self.inPlace)
# Delete the old category and its moved talk page if copied and self.deleteEmptySourceCat == True:
pywikipedia-svn@lists.wikimedia.org