http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10987
Revision: 10987
Author: xqt
Date: 2013-01-27 10:47:27 +0000 (Sun, 27 Jan 2013)
Log Message:
-----------
enable shorten links for namespaces with subpage and return the right page with
linkedPage() (bug #3602219)
Modified Paths:
--------------
trunk/pywikipedia/family.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/family.py
===================================================================
--- trunk/pywikipedia/family.py 2013-01-26 17:23:40 UTC (rev 10986)
+++ trunk/pywikipedia/family.py 2013-01-27 10:47:27 UTC (rev 10987)
@@ -3234,6 +3234,8 @@
#},
}
+ self.namespacesWithSubpage = [2] + range(1, 16, 2)
+
# letters that can follow a wikilink and are regarded as part of
# this link
# This depends on the linktrail setting in LanguageXx.php and on
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-01-26 17:23:40 UTC (rev 10986)
+++ trunk/pywikipedia/wikipedia.py 2013-01-27 10:47:27 UTC (rev 10987)
@@ -2717,6 +2717,14 @@
for match in Rlink.finditer(thistxt):
title = match.group('title')
title = title.replace("_", " ").strip(" ")
+ if self.namespace() in self.site.namespacesWithSubpage:
+ # convert relative link to absolute link
+ if title.startswith(".."):
+ parts = self.title().split('/')
+ parts.pop()
+ title = u'/'.join(parts) + title[2:]
+ elif title.startswith("/"):
+ title = u'%s/%s' % (self.title(), title[1:])
if title.startswith("#"):
# this is an internal section link
continue