Revision: 4215 Author: cydeweys Date: 2007-09-08 18:17:35 +0000 (Sat, 08 Sep 2007)
Log Message: ----------- Making it so that the inPlace parameter works for category removal as well as category renaming.
Modified Paths: -------------- trunk/pywikipedia/category.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/category.py =================================================================== --- trunk/pywikipedia/category.py 2007-09-08 11:23:23 UTC (rev 4214) +++ trunk/pywikipedia/category.py 2007-09-08 18:17:35 UTC (rev 4215) @@ -454,13 +454,14 @@ 'sv':u'Robot: Tar bort från %s', }
- def __init__(self, catTitle, batchMode = False, editSummary = '', useSummaryForDeletion = False, titleRegex = None): + def __init__(self, catTitle, batchMode = False, editSummary = '', useSummaryForDeletion = False, titleRegex = None, inPlace = False): self.editSummary = editSummary self.cat = catlib.Category(wikipedia.getSite(), 'Category:' + catTitle) # get edit summary message self.useSummaryForDeletion = useSummaryForDeletion self.batchMode = batchMode self.titleRegex = titleRegex + self.inPlace = inPlace if self.editSummary: wikipedia.setAction(self.editSummary) else: @@ -473,14 +474,14 @@ else: for article in articles: if not self.titleRegex or re.search(self.titleRegex,article.title()): - catlib.change_category(article, self.cat, None) + catlib.change_category(article, self.cat, None, inPlace = self.inPlace) # Also removes the category tag from subcategories' pages subcategories = self.cat.subcategoriesList(recurse = 0) if len(subcategories) == 0: wikipedia.output(u'There are no subcategories in category %s' % self.cat.title()) else: for subcategory in subcategories: - catlib.change_category(subcategory, self.cat, None) + catlib.change_category(subcategory, self.cat, None, inPlace = self.inPlace) if self.cat.exists() and self.cat.isEmpty(): if self.useSummaryForDeletion: reason = self.editSummary @@ -809,7 +810,7 @@ elif action == 'remove': if (fromGiven == False): oldCatTitle = wikipedia.input(u'Please enter the name of the category that should be removed:') - bot = CategoryRemoveRobot(oldCatTitle, batchMode, editSummary, useSummaryForDeletion) + bot = CategoryRemoveRobot(oldCatTitle, batchMode, editSummary, useSummaryForDeletion, inPlace = inPlace) bot.run() elif action == 'move': if (fromGiven == False):
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2007-09-08 11:23:23 UTC (rev 4214) +++ trunk/pywikipedia/wikipedia.py 2007-09-08 18:17:35 UTC (rev 4215) @@ -2866,9 +2866,15 @@
catNamespace = '|'.join(site.category_namespaces()) categoryR = re.compile(r'[[\s*(%s)\s*:%s]]' % (catNamespace, oldcat.titleWithoutNamespace())) - text = replaceExcept(oldtext, categoryR, '[[Category:%s]]' % newcat.titleWithoutNamespace(), ['nowiki', 'comment', 'math', 'pre']) + if newcat is None: + text = replaceExcept(oldtext, categoryR, '', ['nowiki', 'comment', 'math', 'pre']) + else: + text = replaceExcept(oldtext, categoryR, '[[Category:%s]]' % newcat.titleWithoutNamespace(), ['nowiki', 'comment', 'math', 'pre']) categoryR = re.compile(r'[[\s*(%s)\s*:%s]]' % (catNamespace, oldcat.titleWithoutNamespace().replace(' ','_'))) - text = replaceExcept(text, categoryR, '[[Category:%s]]' % newcat.titleWithoutNamespace(), ['nowiki', 'comment', 'math', 'pre']) + if newcat is None: + text = replaceExcept(text, categoryR, '', ['nowiki', 'comment', 'math', 'pre']) + else: + text = replaceExcept(text, categoryR, '[[Category:%s]]' % newcat.titleWithoutNamespace(), ['nowiki', 'comment', 'math', 'pre']) return text
def replaceCategoryLinks(oldtext, new, site = None):