Revision: 4545 Author: russblau Date: 2007-11-14 22:54:12 +0000 (Wed, 14 Nov 2007)
Log Message: ----------- Fixed bug #1830917 "Redirect.py cannot handle meta links and crashes"
Modified Paths: -------------- trunk/pywikipedia/redirect.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/redirect.py =================================================================== --- trunk/pywikipedia/redirect.py 2007-11-14 18:55:41 UTC (rev 4544) +++ trunk/pywikipedia/redirect.py 2007-11-14 22:54:12 UTC (rev 4545) @@ -256,18 +256,34 @@ except wikipedia.NoPage: wikipedia.output(u'%s doesn't exist.' % redir.aslink()) else: + if secondRedir.site() != redir.site(): + wikipedia.output( + u'Skipping %s; redirect target (%s) is on a different site.' + % (redir.aslink(), secondRedir.aslink())) + continue try: secondTargetPage = secondRedir.getRedirectTarget() anchorMatch = re.search(u'#(?P<section>.*)$', secondRedir.title()) if anchorMatch and not u'#' in secondTargetPage.title(): secondTarget = wikipedia.Page(mysite, '%s#%s' % (secondTargetPage.sectionFreeTitle(), anchorMatch.group('section'))) except wikipedia.SectionError: - wikipedia.output(u'Warning: Redirect target section %s doesn't exist.' % secondRedir.aslink()) + wikipedia.output( + u'Warning: Redirect target section %s doesn't exist.' + % secondRedir.aslink()) except wikipedia.IsNotRedirectPage: - wikipedia.output(u'Redirect target %s is not a redirect.' % secondRedir.aslink()) + wikipedia.output( + u'Redirect target %s is not a redirect.' + % secondRedir.aslink()) except wikipedia.NoPage: - wikipedia.output(u'Redirect target %s doesn't exist.' % secondRedir.aslink()) + wikipedia.output( + u'Redirect target %s doesn't exist.' + % secondRedir.aslink()) else: + if secondTargetPage.site() != secondRedir.site(): + wikipedia.output( + u"Page %s is a redirect to a different site (%s)" + % (secondRedir.aslink(), secondTargetPage.aslink())) + continue oldText = redir.get(get_redirect=True) text = mysite.redirectRegex().sub('#REDIRECT [[%s]]' % secondTargetPage.title(), oldText) wikipedia.showDiff(oldText, text)
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2007-11-14 18:55:41 UTC (rev 4544) +++ trunk/pywikipedia/wikipedia.py 2007-11-14 22:54:12 UTC (rev 4545) @@ -373,16 +373,16 @@ # This page is from a different family output(u"Target link '%s' has different family '%s'" % (title, lowerNs)) otherlang = self.site().lang - if lowerNs in ['commons']: - otherlang = lowerNs familyName = self.site().family.get_known_families(site = self.site())[lowerNs] + if familyName in ['commons', 'meta']: + otherlang = familyName try: self._site = getSite(otherlang, familyName) except ValueError: raise NoPage("""\ %s is not a local page on %s, and the %s family is not supported by PyWikipediaBot!""" - % (title, self.site(), familyName)) + % (title, self.site(), familyName)) t = m.group(2) else: # If there's no recognized interwiki or namespace,