User:Jac16888/vector.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. |
The accompanying .css page for this skin is at User:Jac16888/vector.css. |
importScript('User:Animum/massdelete.js');
importScript('User:Doug/closetfd.js');
importScript('User:King of Hearts/closeffd.js');
importScript('User:King of Hearts/closecfd.js');
importScript('User:King of Hearts/closerfd.js');
importScript('User:Doug/closemfd.js');
importScript('User:Mr.Z-man/moverevert.js');
/*
*Swap Diff & Hist
*/
function contReverseMain() {
var me = this;
this.init = function () {
if ( ( mw.config.get('wgAction') == 'view' ) && ( mw.config.get('wgPageName') == 'Special:Contributions' ) ) {
var bodyContent = document.getElementById ( 'bodyContent' );
regTest = /\(((?:<a href=[^<>]+?>)?diff(?:<\/a>)?)(?: | )\| (<a href=[^<>]+?>hist<\/a>)\)/ig;
bodyContent.innerHTML = bodyContent.innerHTML.replace ( regTest, "($2 | $1)" );
}
}
}
var contReverse = new contReverseMain ();
$(window).on( 'load', contReverse.init );
/*
* Will pop-up a confirmation dialog when rollback link is clicked from Watchlist.
* Hit the "cancel" button if you had clicked Rollback accidentally and the edit will not be reverted.
* To install add importScript('User:Zvn/confirmwatchlistrollback.js'); to your monobook.js.
*/
if(mw.config.get("wgCanonicalSpecialPageName")==="Watchlist") jQuery(function($){
$(".mw-rollback-link a").click(function(event){
if(confirm("Are you sure you want to rollback this edit?")) return;
event.preventDefault();
});
});
//<Catwatch
var cwwpajax;
// From [[WP:US]] mainpage (wpajax renamed to cwwpajax)
cwwpajax={
download:function(bundle) {
// mandatory: bundle.url
// mandatory: bundle.async
// optional: bundle.onSuccess (xmlhttprequest, bundle)
// optional: bundle.onFailure (xmlhttprequest, bundle)
// optional: bundle.otherStuff OK too, passed to onSuccess and onFailure
var x = window.XMLHttpRequest ? new XMLHttpRequest() // Firefox, Safari, Opera, IE7
: window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") // IE6
: false;
if (x) {
x.onreadystatechange=function() {
x.readyState==4 && cwwpajax.downloadComplete(x,bundle);
};
x.open("GET",bundle.url,bundle.async);
x.send(null);
}
return x;
},
downloadComplete:function(x,bundle) {
x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true )
|| ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText));
}
};
function cwOntoWatchlist(xmlreq, data)
{
var a=xmlreq.responseText;
var c=data.catname;
var i;
var diag="";
if(a.indexOf("<categorymembers/>")!=-1) return; //cat is empty, nothing to do here
if(a.indexOf('title="')==-1) return; // this error happens sometimes, just do nothing here
var latesttime=0;
var latestpage="";
var temp, temp2;
latestpage=a.split('title="')[1].split('" timestamp=')[0];
latesttime=a.split('timestamp="')[1].split('"/>')[0];
a=document.getElementsByTagName("h4"); //get dates in the watchlist
var monthname=new Array();
monthname['01']="January";
monthname['02']="February";
monthname['03']="March";
monthname['04']="April";
monthname['05']="May";
monthname['06']="June";
monthname['07']="July";
monthname['08']="August";
monthname['09']="September";
monthname['10']="October";
monthname['11']="November";
monthname['12']="December";
latesttime=new String(latesttime);
var mn1, mn2, mn3, mn4;
// Allow for different date styles:
// January 29, 2001
mn1=""+monthname[latesttime.substr(5,2)]+" "+new Number(latesttime.substr(8,2))+
", "+latesttime.substr(0,4);
// 29 January 2001
mn2=""+new Number(latesttime.substr(8,2))+" "+monthname[latesttime.substr(5,2)]+
" "+latesttime.substr(0,4);
// 2001 January 29
mn3=""+latesttime.substr(0,4)+" "+monthname[latesttime.substr(5,2)]+
" "+new Number(latesttime.substr(8,2));
// 2001-01-29
mn4=""+latesttime.substr(0,4)+"-"+latesttime.substr(5,2)+"-"+latesttime.substr(8,2);
i=a.length;
while(i--)
{
if(a[i].innerHTML==mn1||a[i].innerHTML==mn2||a[i].innerHTML==mn3||a[i].innerHTML==mn4)
{
diag+=a[i].innerHTML+":";
temp=a[i].nextSibling.firstChild;
if(temp==null) temp=a[i].nextSibling.nextSibling.firstChild;
while(temp!=null)
{
diag+=temp.tagname+"!";
if(temp.tagName!=null)
if(temp.tagName.toLowerCase()=="li")
{
temp2=temp.innerHTML.match(/; ([0-9][0-9]):([0-9][0-9])(:[0-9][0-9])? \. \./);
temp2=new Number(temp2[1])*100+new Number(temp2[2]);
diag+=temp2+",";
if(temp2<new Number(latesttime.substr(11,2)+latesttime.substr(14,2))) {temp2=temp; break;}
}
temp2=temp; temp=temp.nextSibling;
if(temp==null) break;
}
temp=document.createElement("li");
if(temp2==null) {return;}
if(a[i].nextSibling.firstChild!=null) // IE-like whitespace handling
a[i].nextSibling.insertBefore(temp,temp2);
else // Firefox-like whitespace handling
a[i].nextSibling.nextSibling.insertBefore(temp,temp2);
temp.innerHTML="(diff) (hist) . . <a "+
"href='http://en.wikipedia.org/wiki/Category:"+
encodeURI(c)+
"'>Category:"+c+"</a>; "+latesttime.substr(11,2)+":"+latesttime.substr(14,2)+
" . . (+ <a "+
"href='http://en.wikipedia.org/wiki/"+
encodeURI(latestpage)+"'>"+latestpage+"</a> "+
"(<a href='http://en.wikipedia.org/w/index.php?title="+encodeURI(latestpage)+
"&diff=last'>last</a>))";
return;
}
}
}
var WatchedCategories;
//An example of a query to check a category would be
//http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmcategory=Wikipedia%20protected%20edit%20requests&cmlimit=1&cmprop=title|timestamp&cmsort=timestamp&cmdir=desc&format=xml
$(function(){
//DHTMLloadscript( 'http://en.wikipedia.org/w/index.php?title=User:'+mw.config.get('wgUserName')
// +'/WatchedCategories.js&action=raw&ctype=text/javascript');
if(mw.config.get('wgPageName')=="Special:Watchlist")
{
// load the script using AJAX, because DHTML fails in Firefox and document.write fails in Safari
var sru='http://en.wikipedia.org/w/index.php?title=User:'+mw.config.get('wgUserName')+'/WatchedCategories2.js&action=raw&ctype=text/javascript';
var sr=cwwpajax.download({url:sru,async:false});
eval(sr.responseText);
if(WatchedCategories==undefined)
{
if(confirm("You don't have a category watchlist yet. Do you want to create one?\n\n"+
"(Please provide the following debug information when reporting a problem if "+
"this message comes up when you already have a category watchlist: "+
(sr.responseText.length<50 ? "responseText='"+sr.responseText+"'" :
"responseText.length="+sr.responseText.length)+", statusText='"+sr.statusText
+"'.)"))
location.href='http://en.wikipedia.org/w/index.php?title=User:'+mw.config.get('wgUserName')+
'/WatchedCategories2.js&action=edit&preload=User:Ais523/WatchedCategoriesTemplate.js';
}
else
{
var i;
for(i=0; i<WatchedCategories.length; i++)
{
var a=WatchedCategories[i];
cwwpajax.download({url:'http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&'
+'cmtitle=Category:'+encodeURI(a)+'&cmlimit=1&cmprop=title'
+'|timestamp&cmsort=timestamp&cmdir=desc&format=xml',
onSuccess:cwOntoWatchlist,
catname:a, async:true});
}
}
}
});
//</source>
$(function () {
var rights_isAdmin = (mw.config.get('wgUserGroups').toString().indexOf('sysop') != -1);
if (!rights_isAdmin)
return; //Restrict to admins.
if (mw.config.get('wgNamespaceNumber') != "2" && mw.config.get('wgNamespaceNumber') != "3")
return; // restrict to User and User talk
var title = mw.config.get('wgTitle');
mw.util.addPortletLink('p-tb', '/wiki/Special:Userrights/'+title,
'User rights', 't-userrights', 'User rights for "'+title+'"');
});
if (mw.config.get('wgPageName') == "Special:Log") {
function addmoveRevertTab() {
mw.util.addPortletLink('p-cactions', 'javascript:moverevert2_main()', "Revert moves", "ca-moverevert", "Revert");
}
$(addmoveRevertTab);
function moverevert2_main() {
jsMsg('<div id="movervinfo"></div>');
if (mw.config.get('wgPageName') == "Special:Log" && document.URL.indexOf('&page=') != -1) {
var user = document.URL.substring(document.URL.indexOf('&user=')+6,document.URL.indexOf('&page='));
} else if (mw.config.get('wgPageName') == "Special:Log"){
var user = document.URL.substring(document.URL.indexOf('&user=')+6);
} else {
var user = encodeURIComponent(mw.config.get('wgTitle'));
}
btoken = gwp_getBlockToken(user);
gwp_blockUser(user, btoken);
token = gwp_getToken();
moves = gwp_getMoveLog(user);
for (var i=0; i<moves.length; i++) {
if(moves[i])
gwp_revertMove(moves[i][1], moves[i][0], token);
}
document.getElementById('movervinfo').innerHTML += '<li id="Gwp_moves">Done</li>';
}
function gwp_getToken() {
document.getElementById('movervinfo').innerHTML += '<li id="Gwp_gettoken">Getting token</li>';
var req = sajax_init_object();
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&prop=info&indexpageids=1&intoken=edit&format=json&titles=Foo", false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response['query']['pageids'][0];
token = response['query']['pages'][pageid]['edittoken'];
delete req;
document.getElementById('Gwp_gettoken').innerHTML = 'Got token';
return token;
}
function gwp_getMoveLog(user) {
document.getElementById('movervinfo').innerHTML += '<li id="Gwp_moves">Getting moves from user ' + user +'</li>';
var url = mw.config.get('wgScriptPath') + "/api.php?action=query&list=logevents&leuser="+user+"&letype=move&lelimit=50&leprop=title|details&format=json"
var req = sajax_init_object();
req.open("GET", url, false);
req.send(null);
var response = eval('(' + req.responseText + ')');
var moves = new Array();
for (var i=0; i<response['query']['logevents'].length; i++) {
if(response['query']['logevents'][i]['move'])
moves[i] = new Array(response['query']['logevents'][i]['title'], response['query']['logevents'][i]['move']['new_title']);
}
delete req;
document.getElementById('Gwp_moves').innerHTML = 'Got moves';
return moves;
}
function gwp_revertMove(movefrom, moveto, token) {
document.getElementById('movervinfo').innerHTML += '<li id="Gwp_move'+escape(movefrom)+'">Moving '+movefrom+' to '+moveto+'</li>';
var req = sajax_init_object();
var params = "action=move&from="+encodeURIComponent(movefrom)+"&to="+encodeURIComponent(moveto)+"&token="+encodeURIComponent(token)+"&reason=Pagemove%20vandalism%20cleanup&noredirect=1&format=json";
url = mw.config.get('wgScriptPath') + "/api.php";
req.open("POST", url, false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
if (response['move']['to']) {
document.getElementById('Gwp_move'+escape(movefrom)).innerHTML = 'Moved '+movefrom+' to '+moveto;
gwp_deletePage(movefrom.replace(/'/g, "\\'").replace(/"/g, '\\"') , encodeURIComponent(token) );
}
} catch(err) {
document.getElementById('Gwp_move'+escape(movefrom)).innerHTML = 'Move from '+movefrom+' to '+moveto+' failed. Error info:' +response['error']['code'] + ' : ' + response['error']['info'];
if (response['error']['code'] == "articleexists") {
setTimeout("gwp_deletePage('"+movefrom.replace(/'/g, "\\'").replace(/"/g, '\\"')+"', '"+encodeURIComponent(token)+"')", 500);
}
}
}
}
req.send(params)
}
function gwp_getBlockToken(user) {
document.getElementById('movervinfo').innerHTML += '<li id="Gwp_btoken">Getting block token</li>';
var req = sajax_init_object();
var params = "action=block&user=" + encodeURIComponent(user) + "&gettoken=1&format=json";
req.open("POST", mw.config.get('wgScriptPath') + "/api.php?", false);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.send(params);
response = eval('(' + req.responseText + ')');
token = response['block']['blocktoken'];
delete req;
document.getElementById('Gwp_btoken').innerHTML = 'Got block token';
return token;
}
function gwp_blockUser(user, token) {
document.getElementById('movervinfo').innerHTML+= "<li id='blocking'>Blocking " + user + "</li>";
var req = sajax_init_object();
var params = "action=block&format=json&token="+encodeURIComponent(token)+"&user="+user+"&expiry=never&reason=abuse&nocreate=1&autoblock=1&noemail=1";
url = mw.config.get('wgScriptPath') + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
document.getElementById('blocking').innerHTML+= response['block']['user']+" has been blocked";
} catch(err) {
document.getElementById('blocking').innerHTML+= " - Error " + response['error']['info'];
}
delete req;
}
}
req.send(params)
}
function gwp_deletePage(title, token) {
document.getElementById('movervinfo').innerHTML += '<li id="Gwp_delete'+escape(title)+'">Deleting '+title+'</li>';
var req = sajax_init_object();
var params = "action=delete&format=json&token="+token+"&title="+encodeURIComponent(title)+"&reason=pagemove%20vandalism%20cleanup";
url = mw.config.get('wgScriptPath') + "/api.php";
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
response = eval('(' + req.responseText + ')');
try {
if (response['delete']['title']) {
document.getElementById('Gwp_delete'+escape(title)).innerHTML = 'Deleted '+title;
}
} catch(err) {
document.getElementById('Gwp_delete'+escape(title)).innerHTML = 'Deletion error on '+title+ ' : ' +response['error']['info'];
}
}
}
req.send(params)
}
}
//<!--[[Category:Wikipedia scripts]]-->