/*
* Lists updates to watchlisted pages in a box at the top of [[Special:Watchlist]] after clicking on the "auto-update" tab
*
* Only works on watchlists with fewer than 500 pages
*
* If you add a new page to your watchlist after the script has been initiated, you will have to reload your watchlist and
* re-initiate the script for it to detect the new page.
*
* Checks, by default, every 5 seconds
*
* This can be custom-set by adding this line to your JavaScript file ([[Special:MyPage/[skin-name].js]]) after the importScript
* declaration for this script (importScript("User:Animum/watchlistUpdate.js");) (e.g., setting timeout to 10 seconds):
importScript("User:Animum/watchlistUpdate.js");
var updateSeconds = 10;
*
*/
if(typeof(updateSeconds) == "undefined") var updateSeconds = 5;
var isSysop = /sysop/.test(mw.config.get('wgUserGroups'));
var isRollbacker = /rollbacker/.test(mw.config.get('wgUserGroups'));
function watchlistUpdate() {}
watchlistUpdate.clearContainer = function() {
getElementsByClassName(document, "div", "mw-js-message-watchlistUpdateContainer")[0].getElementsByTagName("ul")[0].innerHTML = "";
}
watchlistUpdate.isIP = function(ip) { //From [[MediaWiki:Sysop.js]]
return /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/.test(ip);
}
watchlistUpdate.init = function() {
if(getElementsByClassName(document, "div", "mw-js-message-watchlistUpdateContainer")[0]) return; //User has already initiated the script once; abort.
jsMsg("Any updates to your watchlisted pages will appear below (<a href=\"javascript:watchlistUpdate.clearContainer()\">clear list</a>):\n<ul></ul>", "watchlistUpdateContainer");
var req = sajax_init_object();
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&format=json&list=watchlist&wllimit=500&wlprop=ids|title", false);
req.send(null);
var pagelist = eval("(" + req.responseText + ")").query.watchlist;
var pages = new Array();
var revids = new Array();
for(i=0; i<pagelist.length; i++) {
var page = pagelist[i];
var addData = function() {
pages.push(page.title);
revids.push(page.revid);
}
if(typeof WatchlistConfig != "undefined") {
if(typeof WatchlistConfig.ignorePages != "undefined") {
if(WatchlistConfig.ignorePages.length > 0) {
if(WatchlistConfig.ignorePages.indexOf(page.title) == -1) { //Remove pages that [[User:Gary King/hide pages in watchlist.js]] ignores
addData(); //Populates the "pages" array with the links (exludes special pages)
}
} else {
addData();
}
} else { //User has hide_pages_in_watchlist.js installed but does not have a list of pages to ignore.
addData();
}
} else { //User doesn't use hide_pages_in_watchlist.js.
addData();
}
}
window.setInterval(function() { watchlistUpdate.doUpdate(pages, revids); }, updateSeconds*1000);
delete req;
}
watchlistUpdate.formatSummary = function(comment, title) {
comment = comment.replace("<", "<").replace(">", ">"); //Preliminary replacement to prevent formatting errors
if(comment.search(/\/\*.*\*\//) != -1) { //Section name
var section = comment.split(/\/\* ?/)[1].split(/ ?\*\//)[0];
comment = comment.replace(/\/\*.*\*\//g, "<span class=\"autocomment\"><a href=\"" + mw.config.get('wgScript') + "?title=" + encodeURIComponent(title.replace(/ /g, "_")) + "#" + encodeURIComponent(section.replace(/ /g, "_")).replace(/\%/g, ".") + "\" target=\"_blank\">→</a>" + section + (comment.split(/ ?\*\//)[1].length > 0 ? ":" : "") + "</span>");
}
comment = comment.replace(/\[\[([^\|\]]+)\|?(.*?)\]\]/g, function (ignore, link, display) { return "<a href=\"" + mw.config.get('wgScript') + "?title=" + encodeURIComponent(link.replace(/ /g, "_")) + "\" target=\"_blank\">" + (display || link) + "</a>"}); //Stolen from amelvand.js (yes, I'm lazy)
return comment;
}
watchlistUpdate.doUpdate = function(pages, revids) {
var container = getElementsByClassName(document, "div", "mw-js-message-watchlistUpdateContainer")[0];
if(!container) { //If, for some reason, another jsMsg has overtaken ours...
jsMsg("Any updates to your watchlisted pages will appear below (<a href=\"javascript:watchlistUpdate.clearContainer()\">clear list</a>):\n<ul></ul>", "watchlistUpdateContainer");
container = getElementsByClassName(document, "div", "mw-js-message-watchlistUpdateContainer")[0]; //Error-catcher
}
var req = sajax_init_object();
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&format=json&prop=revisions&rvtoken=rollback&titles=" + pages.join("|").toString(), false);
req.send(null);
var info_ = eval("(" + req.responseText + ")").query.pages;
for (var index in info_) {
var info = info_[index];
var revision = info.revisions[0];
if(revids[pages.indexOf(info.title)] != revision.revid) {
var title = info.title;
var user = revision.user;
var timestamp = revision.timestamp.split("T")[1].split("Z")[0].split(":");
var summary = revision.comment;
var encoded = {
"title": encodeURIComponent(title.replace(/ /g, "_")),
"user" : encodeURIComponent(user.replace(/ /g, "_")),
"token": encodeURIComponent(revision.rollbacktoken)
};
container.getElementsByTagName("ul")[0].innerHTML += "<li> <tt>" + timestamp[0] + ":" + timestamp[1]
+ (typeof(revision.minor) == "string" ? " <b>m" + (typeof(revision.bot) == "string" ? "b</b>" : "</b>") : "") + " </tt>"
+ "<a href=\"/wiki/" + encoded.title + "\" target=\"_blank\">" + title + "</a> "
+ "(<a href=\"" + mw.config.get('wgScript') + "?title=" + encoded.title + "&curid=" + info.pageid + "&diff=" + revision.revid + "&oldid=" + revision.parentid + "\" target=\"_blank\">diff</a>)"
+ " by <a href=\"/wiki/" + (this.isIP(user) ? "Special:Contributions/" : "User:") + encoded.user + "\" target=\"_blank\">" + user + "</a>"
+ " (<a href=\"/wiki/User_talk:" + encoded.user + "\" target=\"_blank\">talk</a>" + (this.isIP(user) ? (isSysop ? " | <a href=\"/wiki/Special:Block" + encoded.user + "\" target=\"_blank\">block</a>)" : ")") : " | <a href=\"/wiki/Special:Contributions/" + encoded.user + "\" target=\"_blank\">contribs</a>" + (isSysop ? " | <a href=\"/wiki/Special:Block/" + encoded.user + "\" target=\"_blank\">block</a>)" : ")"))
+ (summary ? " <span class=\"comment\">(" + this.formatSummary(summary, title) + ")</span>" : "")
+ (isSysop || isRollbacker ? " <span class=\"mw-rollback-link\">[<a href=\"" + mw.config.get('wgScript') + "?title=" + encoded.title + "&action=rollback&from=" + encoded.user + "&token=" + encoded.token + "\" target=\"_blank\">rollback</a>]</span>" : "") + "</li>";
revids[pages.indexOf(info.title)] = revision.revid;
}
}
delete req;
}
$(function() {
if(mw.config.get('wgCanonicalSpecialPageName') == "Watchlist" && document.title == "My watchlist - Wikipedia, the free encyclopedia") { //document.title is included to catch things such as editing the raw watchlist.
mw.util.addPortletLink("p-cactions", "javascript:watchlistUpdate.init()", "auto-update", "ca-watchlistupdate", "Automatically reports changes to pages in your watchlist");
}
});
importScript( "User:Davidgothberg/clock.js" );
importScript('User:Drilnoth/assessortags.js'); //See [[User:Drilnoth/assessortags.js/doc]] for details
// Stub tag tab. Original version by [[User:ais523]], on a request by [[User:thesublime514]].
// Enhancements made on requests by [[User:Alai]] and [[User:jj137]].
// ([[User:ais523/stubtagtab2.js]])
// <source lang="javascript">
$(function(){
if(mw.config.get('wgNamespaceNumber')==0&&wgAction=="view")
{
if(document.getElementById("ca-edit"))
mw.util.addPortletLink('p-cactions', 'javascript:stubtagtab()', 'stub', 'ca-stubtag',
'Add a stub tag to this page', '');
}
if(location.href.indexOf("&autoaddstubtag=")!=-1&&document.getElementById('wpTextbox1')!=null)
{
var x=decodeURIComponent(location.href.split("&autoaddstubtag=")[1]);
if(x.indexOf("-stub")==-1) x+="-stub";
document.getElementById('wpTextbox1').value+="\n{"+"{"+x+"}}"; //add to the end of the article
document.getElementById('wpSummary').value=
"Tagging with {"+"{"+x+"}} using [[WP:US/S|user scripts]]";
document.getElementById('wpPreview').click();
}
});
function stubtagtab()
{
var h;
// A list of subpages of WikiProject Stub sorting/Stub types/ that are relevant to this
var a=['Commerce','Culture','Education','Geography','Government, law, and politics','History',
'Leisure','Military and weaponry','Miscellaneous','Organizations','People',
'Religion, mythology, faiths, and beliefs','Science','Sports','Technology','Transport'];
var i=0;
h="<div style='color:#000000; background-color:#fff8f8;'>• ";
while(i<a.length)
{
h+="<a href='javascript:stubtagmenu(\""+a[i]+"\");'>"+a[i]+"</a> • ";
i++;
}
h+="</div><div id='stubtagmenudiv' style='color:#000000; background-color:#fffff8;'></div>";
document.getElementById("contentSub").innerHTML=h;
}
function stubtagmenurender(a)
{
if(a.responseText.indexOf("<text>")==-1)
{
document.getElementById('stubtagmenudiv').innerHTML=
"<i>Loading, please wait...</i>";
return;
}
var s=a.responseText.split("<text>")[1].split("</text>")[0];
s=s.split("<").join("<").split(">").join(">");
s=s.split(""").join('"').split("&").join('&');
s=s.split('<a href="/wiki/Template:');
var i=s.length;
while(--i) s[i]=s[i].split('" title').join('\');" title');
s=s.join('<a temphref="javascript:stubtagwith(\'');
s=s.split('<a href=').join('<a style="color:#000000;" notanhref=');
s=s.split('<a temphref=').join('<a href=');
document.getElementById('stubtagmenudiv').innerHTML=s;
}
function stubtagmenu(x)
{
//Fetch the relevant subpage of the WikiProject
var a = sajax_init_object();
a.open('GET', mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/api.php?action=parse&prop=text&text='+
encodeURIComponent('__NOTOC____NOEDITSECTION__{{Wikipedia:WikiProject Stub sorting/Stub types/'+
x+'}}')+'&format=xml');
a.onreadystatechange = function(){stubtagmenurender(a)};
a.send('');
}
function stubtagwith(x)
{
if(x==null||x=="") return;
location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+
"&action=edit&autoaddstubtag="+encodeURIComponent(x);
}
// </source> <!--[[Category:Wikipedia scripts]]-->
importScript('User:Lupin/recent2.js');