pywikipedia r10954 - Code Review

Jump to: navigation, search
Repository:pywikipedia
Revision:r10953‎ | r10954 (on ViewVC)‎ | r10955 >
Date:12:57, 19 January 2013
Author:multichill
Status:new
Tags:
Comment:
Implement some logic to update links when a category at Commons gets deleted. If a category is moved and the deleting admin provided a decent deletion summary, the bot will use this to update links.
I hope this will fix a lot of broken links to Commons.
Modified paths:

Diff [purge]

Index: trunk/pywikipedia/commonscat.py
@@ -501,14 +501,30 @@
502502 if pywikibot.verbose:
503503 pywikibot.output("getCommonscat: " + name )
504504 try:
 505+ commonsSite = pywikibot.getSite("commons", "commons")
505506 #This can throw a pywikibot.BadTitle
506 - commonsPage = pywikibot.Page(pywikibot.getSite("commons", "commons"),
507 - "Category:" + name)
 507+ commonsPage = pywikibot.Page(commonsSite, "Category:" + name)
508508
509509 if not commonsPage.exists():
510 - if pywikibot.verbose:
511 - pywikibot.output(u"getCommonscat: The category doesnt exist.")
512 - return u''
 510+ logpages = commonsSite.logpages(mode='delete', title=commonsPage.title())
 511+ try:
 512+ logitem = logpages.next()
 513+ (logpage, loguser, logtimestamp, logcomment) = logitem
 514+ # Some logic to extract the target page.
 515+ regex = u'moved to \[\[\:?Category:(?P<newcat1>[^\|\}]+)(\|[^\}]+)?\]\]|Robot: Changing Category:(.+) to Category:(?P<newcat2>.+)'
 516+ m = re.search(regex, logcomment)
 517+ if m:
 518+ if m.group('newcat1'):
 519+ return self.checkCommonscatLink(m.group('newcat1'))
 520+ elif m.group('newcat2'):
 521+ return self.checkCommonscatLink(m.group('newcat2'))
 522+ else:
 523+ pywikibot.output(u'getCommonscat: Deleted by %s. Couldn\'t find move target in \" %s \"' % (loguser, logcomment))
 524+ return u''
 525+ except StopIteration:
 526+ if pywikibot.verbose:
 527+ pywikibot.output(u"getCommonscat: The category doesnt exist and nothing found in the deletion log.")
 528+ return u''
513529 elif commonsPage.isRedirectPage():
514530 if pywikibot.verbose:
515531 pywikibot.output(u"getCommonscat: The category is a redirect")