Revision: 8304 Author: cydeweys Date: 2010-06-16 17:54:08 +0000 (Wed, 16 Jun 2010)
Log Message: ----------- Update to handle parsing of date links from CFD template parameters.
Modified Paths: -------------- trunk/pywikipedia/category.py trunk/pywikipedia/cfd.py
Modified: trunk/pywikipedia/category.py =================================================================== --- trunk/pywikipedia/category.py 2010-06-16 15:28:12 UTC (rev 8303) +++ trunk/pywikipedia/category.py 2010-06-16 17:54:08 UTC (rev 8304) @@ -429,7 +429,7 @@ """Robot to move pages from one category to another.""" def __init__(self, oldCatTitle, newCatTitle, batchMode=False, editSummary='', inPlace=False, moveCatPage=True, - deleteEmptySourceCat=True, titleRegex=None): + deleteEmptySourceCat=True, titleRegex=None, useSummaryForDeletion=True): site = pywikibot.getSite() self.editSummary = editSummary self.oldCat = catlib.Category(site, oldCatTitle) @@ -439,6 +439,7 @@ self.batchMode = batchMode self.deleteEmptySourceCat = deleteEmptySourceCat self.titleRegex = titleRegex + self.useSummaryForDeletion = useSummaryForDeletion
def run(self): site = pywikibot.getSite() @@ -450,6 +451,13 @@ except TypeError: self.editSummary = pywikibot.translate(site, msg_change) % self.oldCat.title()
+ if self.useSummaryForDeletion and self.editSummary: + reason = self.editSummary + else: + reason = pywikibot.translate(site, deletion_reason_move) \ + % (self.newCatTitle, self.newCatTitle) + + # Copy the category contents to the new category page copied = False oldMovedTalk = None @@ -459,8 +467,6 @@ pywikibot.translate(site, cfd_templates)) # Also move the talk page if copied: - reason = pywikibot.translate(site, deletion_reason_move) \ - % (self.newCatTitle, self.newCatTitle) oldTalk = self.oldCat.toggleTalkPage() if oldTalk.exists(): newTalkTitle = newCat.toggleTalkPage().title() @@ -494,14 +500,13 @@ if not self.titleRegex or re.search(self.titleRegex, subcategory.title()): 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: if self.oldCat.isEmpty(): - reason = pywikibot.translate(site, deletion_reason_move) \ - % (self.newCatTitle, self.newCatTitle) confirm = not self.batchMode self.oldCat.delete(reason, confirm, mark = True) if oldMovedTalk is not None:
Modified: trunk/pywikipedia/cfd.py =================================================================== --- trunk/pywikipedia/cfd.py 2010-06-16 15:28:12 UTC (rev 8303) +++ trunk/pywikipedia/cfd.py 2010-06-16 17:54:08 UTC (rev 8304) @@ -17,9 +17,13 @@ import re import category
-# The locateion of the CFD working page. +# The location of the CFD working page. cfdPage = 'Wikipedia:Categories for discussion/Working'
+# A list of templates that are used on category pages as part of the CFD +# process that contain information such as the link to the per-day discussion page. +cfdTemplates = ['Cfd full', 'Cfr full'] + # Regular expression declarations # See the en-wiki CFD working page at [[Wikipedia:Categories for discussion/Working]] # to see how these work in context. To get this bot working on other wikis you will @@ -83,13 +87,15 @@ day = "None" elif (m.check(dateheader, line)): day = m.result.group(1) + wikipedia.output("Found day header: %s" % day) elif (m.check(movecat, line)): src = m.result.group(1) dest = m.result.group(2) - if (mode == "Move" and day != "None"): - summary = "Robot - Moving category " + src + " to " + dest + " per [[WP:CFD|CFD]] at " + findDay(src, day) + "." + thisDay = findDay(src, day) + if (mode == "Move" and thisDay != "None"): + summary = "Robot - Moving category " + src + " to " + dest + " per [[WP:CFD|CFD]] at " + thisDay + "." elif (mode == "Speedy"): - summary = "Robot - Speedily moving category " + src + " to " + dest + " per [[WP:CFD|CFD]]." + summary = "Robot - Speedily moving category " + src + " to " + dest + " per [[WP:CFDS|CFDS]]." else: continue # If the category is redirect, we do NOT want to move articles to @@ -104,14 +110,15 @@ else: robot = category.CategoryMoveRobot(oldCatTitle=src, newCatTitle=dest, batchMode=True, editSummary=summary, inPlace=True, moveCatPage=True, - deleteEmptySourceCat=True) + deleteEmptySourceCat=True, useSummaryForDeletion=True) elif (m.check(deletecat, line)): src = m.result.group(1) # I currently don't see any reason to handle these two cases separately, though # if are guaranteed that the category in the "Delete" case is empty, it might be # easier to call delete.py on it. - if ((mode == "Empty" or mode == "Delete") and day != "None"): - summary = "Robot - Removing category " + src + " per [[WP:CFD|CFD]] at " + findDay(src, day) + "." + thisDay = findDay(src, day) + if ((mode == "Empty" or mode == "Delete") and thisDay != "None"): + summary = "Robot - Removing category " + src + " per [[WP:CFD|CFD]] at " + thisDay + "." else: continue robot = category.CategoryRemoveRobot(catTitle=src, batchMode=True, editSummary=summary, @@ -142,7 +149,22 @@ if (m != None): return "[[" + m.group(1) + "]]" else: - wikipedia.output("Could not find CFD day link on Category:" + pageTitle + "\n", toStdout=True) + # Try to parse day link from CFD template parameters. + templates = page.templatesWithParams() + for template in templates: + if template[0] in cfdTemplates: + params = template[1] + (day, month, year) = [None, None, None] + for param in params: + (paramName, paramVal) = param.split('=', 1) + if (paramName == 'day'): + day = paramVal + elif (paramName == 'month'): + month = paramVal + elif (paramName == 'year'): + year = paramVal + if (day and month and year): + return "[[Wikipedia:Categories for discussion/Log/%s %s %s]]" % (year, month, day) return oldDay
if __name__ == "__main__":