Revision: 8043 Author: cydeweys Date: 2010-03-28 19:52:25 +0000 (Sun, 28 Mar 2010)
Log Message: ----------- Now takes account of whether a target category page is a redirect (and if it is, we abort processing).
Modified Paths: -------------- trunk/pywikipedia/cfd.py
Modified: trunk/pywikipedia/cfd.py =================================================================== --- trunk/pywikipedia/cfd.py 2010-03-27 19:29:29 UTC (rev 8042) +++ trunk/pywikipedia/cfd.py 2010-03-28 19:52:25 UTC (rev 8043) @@ -16,6 +16,15 @@ import re import category
+# The locateion of the CFD working page. +cfdPage = 'Wikipedia:Categories for discussion/Working' + + +# A list of templates that signify that a category is redirected. +# If the category is redirect, we do NOT want to move articles to it. +# The safest thing to do here is abort and wait for human intervention. +redirTemplates = ['Category redirect', 'Categoryredirect', 'CR', 'Catredirect', 'Seecat', 'Cat redirect'] + # 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 @@ -42,7 +51,7 @@ def main(): wikipedia.handleArgs();
- page = wikipedia.Page(wikipedia.getSite(), 'Wikipedia:Categories for discussion/Working') + page = wikipedia.Page(wikipedia.getSite(), cfdPage)
# Variable declarations day = "None" @@ -88,9 +97,14 @@ summary = "Robot - Speedily moving category " + src + " to " + dest + " per [[WP:CFD|CFD]]." else: continue - robot = category.CategoryMoveRobot(oldCatTitle=src, newCatTitle=dest, batchMode=True, - editSummary=summary, inPlace=True, moveCatPage=True, - deleteEmptySourceCat=True) + if categoryIsRedirect(dest): + summary = 'CANCELED. Destination is redirect: ' + summary + wikipedia.output(summary, toStdout=True) + robot = None + else: + robot = category.CategoryMoveRobot(oldCatTitle=src, newCatTitle=dest, batchMode=True, + editSummary=summary, inPlace=True, moveCatPage=True, + deleteEmptySourceCat=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 @@ -112,6 +126,16 @@ summary = "" robot = None
+# Returns true if the category is a redirected category, meaning we should +# NOT run the bot and instead let humans handle the exception. +def categoryIsRedirect(pageTitle): + page = wikipedia.Page(wikipedia.getSite(), "Category:" + pageTitle) + templates = page.templates(get_redirect=True) + for redirTemplate in redirTemplates: + if redirTemplate in templates: + return True + return False + # This function grabs the wiki source of a category page and attempts to # extract a link to the CFD per-day discussion page from the CFD template. # If the CFD template is not there, it will return the value of the second
pywikipedia-svn@lists.wikimedia.org