http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11351
Revision: 11351 Author: xqt Date: 2013-04-07 10:31:07 +0000 (Sun, 07 Apr 2013) Log Message: ----------- new page method: Page.getMovedTarget()
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2013-04-07 09:29:26 UTC (rev 11350) +++ trunk/pywikipedia/wikipedia.py 2013-04-07 10:31:07 UTC (rev 11351) @@ -901,8 +901,10 @@ else: # search for messages with no "view source" (aren't used in new versions) if self.site().mediawiki_message('whitelistedittitle') in text: - raise NoPage(u'Page editing is forbidden for anonymous users.') - elif self.site().has_mediawiki_message('nocreatetitle') and self.site().mediawiki_message('nocreatetitle') in text: + raise NoPage(u'Page editing is forbidden for anonymous ' + u'users.') + elif self.site().has_mediawiki_message('nocreatetitle') and \ + self.site().mediawiki_message('nocreatetitle') in text: raise NoPage(self.site(), unicode(self)) # Bad title elif 'var wgPageName = "Special:Badtitle";' in text \ @@ -2867,6 +2869,20 @@ else: raise IsNotRedirectPage(self)
+ def getMovedTarget(self): + """Return a Page object for the target this Page was moved to. + + If this page was not moved, it will raise a NoPage exception. + + """ + gen = self.site.logpages(number=1, mode='move', title=self.title(), + dump=True) + try: + lastmove = gen.next()['move'] + except StopIteration: + raise NoPage(self.site(), unicode(self)) + return Page(self.site, lastmove['new_title']) + def getVersionHistory(self, forceReload=False, reverseOrder=False, getAll=False, revCount=500): """Load the version history page and return history information. @@ -4413,7 +4429,8 @@ data['query'] = {'pages': data['entities']} for pageid in data['entities'].keys(): if pageid == "-1": - raise NoPage(self.site(), unicode(self),"API query error, no pages found: %s" % data) + raise NoPage(self.site(), unicode(self), + "API query error, no pages found: %s" % data) params1['titles'] = pageid ndata=query.GetData(params1, self.site(), sysop=sysop) data['entities'].update(ndata['query']['pages']) @@ -4421,7 +4438,8 @@ if 'error' in data: raise RuntimeError("API query error: %s" % data) if not 'pages' in data['query']: - raise NoPage(self.site(), unicode(self),"API query error, no pages found: %s" % data) + raise NoPage(self.site(), unicode(self), + "API query error, no pages found: %s" % data) pageInfo = ndata['query']['pages'].values()[0] if data['query']['pages'].keys()[0] == "-1": if 'missing' in pageInfo: