| Index: trunk/pywikipedia/commonscat.py |
| — | — | @@ -501,14 +501,30 @@ |
| 502 | 502 | if pywikibot.verbose: |
| 503 | 503 | pywikibot.output("getCommonscat: " + name ) |
| 504 | 504 | try: |
| | 505 | + commonsSite = pywikibot.getSite("commons", "commons") |
| 505 | 506 | #This can throw a pywikibot.BadTitle |
| 506 | | - commonsPage = pywikibot.Page(pywikibot.getSite("commons", "commons"), |
| 507 | | - "Category:" + name) |
| | 507 | + commonsPage = pywikibot.Page(commonsSite, "Category:" + name) |
| 508 | 508 | |
| 509 | 509 | 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'' |
| 513 | 529 | elif commonsPage.isRedirectPage(): |
| 514 | 530 | if pywikibot.verbose: |
| 515 | 531 | pywikibot.output(u"getCommonscat: The category is a redirect") |