Revision: 6325
Author: russblau
Date: 2009-02-05 13:59:48 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
port category redirect methods from trunk
Modified Paths:
--------------
branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2009-02-04 17:20:55 UTC (rev 6324)
+++ branches/rewrite/pywikibot/page.py 2009-02-05 13:59:48 UTC (rev 6325)
@@ -408,6 +408,29 @@
"""Return True if this is a redirect, False if not or not
existing."""
return self.site().page_isredirect(self)
+ def isCategoryRedirect(self):
+ """Return True if this is a category redirect page, False
otherwise."""
+
+ if not self.isCategory():
+ return False
+ if not hasattr(self, "_catredirect"):
+ catredirs = self.site().category_redirects()
+ for (template, args) in self.templatesWithParams():
+ if template.title(withNamespace=False) in catredirs:
+ # Get target (first template argument)
+ self._catredirect = self.site().namespace(14) \
+ + ":" + args[0]
+ break
+ else:
+ self._catredirect = False
+ return bool(self._catredirect)
+
+ def getCategoryRedirectTarget(self):
+ """If this is a category redirect, return the target category
title."""
+ if self.isCategoryRedirect():
+ return Category(self.site(), self._catredirect)
+ raise pywikibot.ErrorIsNotRedirectPage
+
def isEmpty(self):
"""Return True if the page text has less than 4 characters.
@@ -793,7 +816,8 @@
for name in named:
positional.append("%s=%s" % (name, named[name]))
result.append((pywikibot.Page(
- pywikibot.Link(template[0], self.site())),
+ pywikibot.Link(template[0], self.site(),
+ defaultNamespace=10)),
positional))
return result
@@ -1305,7 +1329,7 @@
"""All parameters are the same as for Page() constructor.
"""
- Page.__init__(self, source, title, 14)
+ Page.__init__(self, source, title, ns=14)
if self.namespace() != 14:
raise ValueError(u"'%s' is not in the category namespace!"
% title)
Show replies by date