[Pywikipedia-l] SVN: [6267] trunk/pywikipedia/wikipedia.py
russblau at svn.wikimedia.org
russblau at svn.wikimedia.org
Sun Jan 18 23:56:26 UTC 2009
Revision: 6267
Author: russblau
Date: 2009-01-18 23:56:25 +0000 (Sun, 18 Jan 2009)
Log Message:
-----------
A different approach to category redirect detection.
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2009-01-18 22:23:28 UTC (rev 6266)
+++ trunk/pywikipedia/wikipedia.py 2009-01-18 23:56:25 UTC (rev 6267)
@@ -834,6 +834,10 @@
self._redirarg = redirtarget
else:
raise IsRedirectPage(redirtarget)
+ elif self.isCategoryRedirect(): # sets _redirarg
+ if not get_redirect:
+ self._getexception = IsRedirectPage
+ raise IsRedirectPage, self._redirarg
if self.section():
# TODO: What the hell is this? Docu please.
m = re.search("\.3D\_*(\.27\.27+)?(\.5B\.5B)?\_*%s\_*(\.5B\.5B)?(\.27\.27+)?\_*\.3D" % re.escape(self.section()), sectionencode(text,self.site().encoding()))
@@ -1082,6 +1086,23 @@
"""Return True if this is an image description page, False otherwise."""
return self.namespace() == 6
+ def isCategoryRedirect(self):
+ """Return True if this is a category redirect page."""
+
+ if not self.isCategory():
+ return False
+ if not hasattr(self, "_catredirect"):
+ catredirs = self.site().category_redirects()
+ for (t, args) in self.templatesWithParams():
+ if t in catredirs:
+ self._catredirect = True
+ # Get target (first template argument)
+ self._redirarg = self.site().namespace(14) + ":" + args[0]
+ break
+ else:
+ self._catredirect = False
+ return self._catredirect
+
def isDisambig(self):
"""Return True if this is a disambiguation page, False otherwise.
More information about the Pywikipedia-l
mailing list