User:Cynical/wikiwatch.js

// User:Quarl/wikiwatch.js - utility functions for manipulating watchlist

// quarl 2006-01-09 (initial asynchronous implementation at unwatch.js) // quarl 2006-02-03 factored out to utility library

// depends: wikipage.js, util.js

//

var wikiwatch = new Object;

wikiwatch.unwatchAsync = function(wp, callback, statusNode, statusText) { wp = wp.notalkPage; var url = wp.qurl + '&action=unwatch'; buttonShowStatus(statusNode, statusText); asyncDownloadXML(url, wikiwatch._unwatchDownloaded, {page: wp.page, callback: callback, statusNode: statusNode}); }

wikiwatch.watchAsync = function(wp, callback, statusNode, statusText) { wp = wp.notalkPage; var url = wp.qurl + '&action=watch'; buttonShowStatus(statusNode, statusText); asyncDownloadXML(url, wikiwatch._watchDownloaded, {page: wp.page, callback: callback, statusNode: statusNode}); }

wikiwatch._unwatchDownloaded = function(req) { buttonRestoreStatus(req.statusNode); var m1; var m2; if ((req.status == 200) &&       (m1= req.responseText.match(/The page "(.*?)" has been removed from your watchlist/)) &&        (m2= req.responseText.match(/ Return to <a href="(\/wiki\/[^\"]+)"/)))    {        // for some reason, request.article_title is "null" randomly 10% of the time        //var article = req.article_title;        //var article = unwatch_remove_talk_ns(m1[1]);

var wp = new WikiPage(m2[1]); if (req.callback) { req.callback(wp); }   } else { alert("Unwatch '"+req.page+"'failed!"); } }

wikiwatch._watchDownloaded = function(req) { buttonRestoreStatus(req.statusNode); var m1; var m2; if ((req.status == 200) &&       (m1= req.responseText.match(/The page "(.*?)" has been added to your/)) &&        (m2= req.responseText.match(/ Return to <a href="(\/wiki\/[^\"]+)"/)))    {        var wp = new WikiPage(m2[1]);        if (req.callback) {            req.callback(wp);        }    } else {        alert("Watch '"+req.page+"'failed!");    } }

//