User:Quarl/wikiwatch.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Quarl/wikiwatch. |
// [[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
// <pre><nowiki>
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(/<p>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(/<p>Return to <a href="(\/wiki\/[^\"]+)"/)))
{
var wp = new WikiPage(m2[1]);
if (req.callback) {
req.callback(wp);
}
} else {
alert("Watch '"+req.page+"'failed!");
}
}
// </nowiki></pre>