Revision: 6726 Author: nicdumz Date: 2009-04-26 08:44:13 +0000 (Sun, 26 Apr 2009)
Log Message: ----------- Page.interwiki() : substitute once {{PAGENAME}} BEFORE parsing for links, instead of parsing for language links, and then recreating a new Page object for each link : Page(oldtitle.replace('{{PAGENAME}}', oldtitle), site) ...
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2009-04-26 08:31:00 UTC (rev 6725) +++ trunk/pywikipedia/wikipedia.py 2009-04-26 08:44:13 UTC (rev 6726) @@ -1734,30 +1734,17 @@ if hasattr(self, "_interwikis"): return self._interwikis
- result = [] - ll = getLanguageLinks(self.get(), insite=self.site(), - pageLink=self.aslink()) - for newSite, newPage in ll.iteritems(): - for pagenametext in self.site().family.pagenamecodes( + text = self.get() + + # Replace {{PAGENAME}} by its value + for pagenametext in self.site().family.pagenamecodes( self.site().language()): - newTitle = newPage.title().replace( - "{{" + pagenametext + "}}", self.title()) - try: - result.append( - self.__class__(newSite, newTitle, insite=self.site())) - except UnicodeError: - output( - u"ERROR: link from %s to [[%s:%s]] is in an invalid encoding?!" - % (self.aslink(), newSite, newTitle)) - except ValueError: - output( - u"ERROR: link from %s to [[%s:%s]] contains invalid unicode reference?!" - % (self.aslink(), newSite, newTitle)) - except InvalidTitle: - output( - u"ERROR: link from %s to [[%s:%s]] is improperly formatted?" - % (self.aslink(), newSite, newTitle)) + text = text.replace(u"{{%s}}" % pagenametext, self.title())
+ ll = getLanguageLinks(text, insite=self.site(), pageLink=self.aslink()) + + result = ll.values() + self._interwikis = result return result
pywikipedia-svn@lists.wikimedia.org