Revision: 4615 Author: russblau Date: 2007-11-29 16:01:45 +0000 (Thu, 29 Nov 2007)
Log Message: ----------- Fix bug that was creating double sections in some redirect targets, remove unused variable, and add check for redirect loops
Modified Paths: -------------- trunk/pywikipedia/redirect.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/redirect.py =================================================================== --- trunk/pywikipedia/redirect.py 2007-11-28 21:11:00 UTC (rev 4614) +++ trunk/pywikipedia/redirect.py 2007-11-29 16:01:45 UTC (rev 4615) @@ -264,9 +264,6 @@ 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.' @@ -285,8 +282,16 @@ u"Page %s is a redirect to a different site (%s)" % (secondRedir.aslink(), secondTargetPage.aslink())) continue + # watch out for redirect loops + if secondTargetPage.sectionFreeTitle() == secondRedir.sectionFreeTitle() \ + or secondTargetPage.sectionFreeTitle() == redir.sectionFreeTitle(): + continue oldText = redir.get(get_redirect=True) - text = mysite.redirectRegex().sub('#%s [[%s]]' % ( mysite.redirect( True ), secondTargetPage.title() ), oldText) + text = mysite.redirectRegex().sub( + '#%s [[%s]]' % + (mysite.redirect( True ), + secondTargetPage.title()), + oldText) wikipedia.showDiff(oldText, text) if self.prompt(u'Do you want to accept the changes?'): try:
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2007-11-28 21:11:00 UTC (rev 4614) +++ trunk/pywikipedia/wikipedia.py 2007-11-29 16:01:45 UTC (rev 4615) @@ -747,7 +747,7 @@ m = self.site().redirectRegex().match(text[i1:i2]) if m: # page text matches the redirect pattern - if self.section(): + if self.section() and not "#" in m.group(1): redirtarget = "%s#%s" % (m.group(1), self.section()) else: redirtarget = m.group(1)