Revision: 6830 Author: russblau Date: 2009-05-05 17:10:40 +0000 (Tue, 05 May 2009)
Log Message: ----------- Fix bug 2785994: Page.backlinks cannot work well on some pages
Modified Paths: -------------- branches/rewrite/pywikibot/page.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2009-05-05 17:00:40 UTC (rev 6829) +++ branches/rewrite/pywikibot/page.py 2009-05-05 17:10:40 UTC (rev 6830) @@ -83,6 +83,8 @@ nsindex = source.ns_index(title[ :pos]) if nsindex: self._ns = nsindex + # normalize namespace, in case an alias was used + title = source.namespace(nsindex) + title[pos: ] if u"#" in title: title, self._section = title.split(u"#", 1) else:
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2009-05-05 17:00:40 UTC (rev 6829) +++ branches/rewrite/pywikibot/site.py 2009-05-05 17:10:40 UTC (rev 6830) @@ -1116,16 +1116,23 @@ # really redirects to this page redirgen = api.PageGenerator("backlinks", gbltitle=bltitle, site=self, gblfilterredir="redirects") - genlist = [blgen] + genlist = {None: blgen} for redir in redirgen: + if redir == page: + # if a wiki contains pages whose titles contain + # namespace aliases that existed before those aliases + # were defined (example: [[WP:Sandbox]] existed as a + # redirect to [[Wikipedia:Sandbox]] before the WP: alias + # was created) they can be returned as redirects to + # themselves; skip these + continue if redir.getRedirectTarget() == page: - genlist.append( - self.pagebacklinks( - redir, followRedirects=True, - filterRedirects=filterRedirects, - namespaces=namespaces)) + genlist[redir.title()] = self.pagebacklinks( + redir, followRedirects=True, + filterRedirects=filterRedirects, + namespaces=namespaces) import itertools - return itertools.chain(*genlist) + return itertools.chain(*genlist.values()) return blgen
def page_embeddedin(self, page, filterRedirects=None, namespaces=None):
pywikipedia-svn@lists.wikimedia.org