http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9132
Revision: 9132 Author: jayvdb Date: 2011-03-26 06:43:33 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Add Page.watch() and unwatch()
Modified Paths: -------------- trunk/pywikipedia/family.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/family.py =================================================================== --- trunk/pywikipedia/family.py 2011-03-24 00:50:12 UTC (rev 9131) +++ trunk/pywikipedia/family.py 2011-03-26 06:43:33 UTC (rev 9132) @@ -3923,6 +3923,12 @@ def edit_address(self, code, name): return '%s?title=%s&action=edit&useskin=monobook' % (self.path(code), name)
+ def watch_address(self, code, name): + return '%s?title=%s&action=watch&useskin=monobook' % (self.path(code), name) + + def unwatch_address(self, code, name): + return '%s?title=%s&action=unwatch&useskin=monobook' % (self.path(code), name) + def purge_address(self, code, name): return '%s?title=%s&redirect=no&action=purge&useskin=monobook' % (self.path(code), name)
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2011-03-24 00:50:12 UTC (rev 9131) +++ trunk/pywikipedia/wikipedia.py 2011-03-26 06:43:33 UTC (rev 9132) @@ -245,6 +245,8 @@ botMayEdit (*) : True if bot is allowed to edit page put(newtext) : Saves the page put_async(newtext) : Queues the page to be saved asynchronously + watch : Add the page to the watchlist + unwatch : Remove the page from the watchlist move : Move the page to another title delete : Deletes the page (requires being logged in) protect : Protect or unprotect a page (requires sysop status) @@ -2907,6 +2909,31 @@ users = set([edit[2] for edit in edits]) return users
+ def watch(self, unwatch=False): + """Add this page to the watchlist""" + if self.site().has_api: + params = { + 'action': 'watch', + 'title': self.title() + } + if unwatch: + params['unwatch'] = '' + + data = query.GetData(params, self.site()) + if 'error' in data: + raise RuntimeError("API query error: %s" % data['error']) + else: + urlname = self.urlname() + if not unwatch: + address = self.site().watch_address(urlname) + else: + address = self.site().unwatch_address(urlname) + response = self.site().getUrl(address) + return response + + def unwatch(self): + self.watch(unwatch=True) + def move(self, newtitle, reason=None, movetalkpage=True, movesubpages=False, sysop=False, throttle=True, deleteAndMove=False, safe=True, fixredirects=True, leaveRedirect=True): """Move this page to new title given by newtitle. If safe, don't try @@ -7134,6 +7161,14 @@ """Return URL path for edit form for page titled 's'.""" return self.family.edit_address(self.lang, s)
+ def watch_address(self, s): + """Return URL path for watching the titled 's'.""" + return self.family.watch_address(self.lang, s) + + def unwatch_address(self, s): + """Return URL path for unwatching the titled 's'.""" + return self.family.unwatch_address(self.lang, s) + def purge_address(self, s): """Return URL path to purge cache and retrieve page 's'.""" return self.family.purge_address(self.lang, s)