http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9362
Revision: 9362 Author: xqt Date: 2011-07-10 16:35:04 +0000 (Sun, 10 Jul 2011) Log Message: ----------- bug fix: don't add duplicate categories to an article, update from rewrite r8953 (bug #3115233)
Modified Paths: -------------- trunk/pywikipedia/category_redirect.py
Modified: trunk/pywikipedia/category_redirect.py =================================================================== --- trunk/pywikipedia/category_redirect.py 2011-07-10 15:23:46 UTC (rev 9361) +++ trunk/pywikipedia/category_redirect.py 2011-07-10 16:35:04 UTC (rev 9362) @@ -14,21 +14,23 @@ """
# -# (C) Pywikipedia team, 2008-2009 +# (C) Pywikipedia team, 2008-2011 # __version__ = '$Id$' # # Distributed under the terms of the MIT license. #
-import wikipedia as pywikibot -import catlib, query, pagegenerators import cPickle import math import re import sys, traceback import time from datetime import datetime, timedelta +import wikipedia as pywikibot +import pagegenerators +import catlib, query +from pywikibot import i18n
class APIError(Exception): @@ -227,7 +229,12 @@
""" oldtext = article.get(get_redirect=True, force=True) - newtext = pywikibot.replaceCategoryInPlace(oldtext, oldCat, newCat) + 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