User:Master of Puppets/monobook.js

//Debugged by Voice of All, two incs commented out due to redundancy //SRC written script set to timeout rather than infinitely (bad) recure //END function inc (file) { mw.loader.load('/w/index.php?title='+file+'&action=raw&ctype=text/javascript&dontcountme=s'); } inc("User:Topaz/init.js"); inc("User:Topaz/util.js"); inc("User:Topaz/editcountutil.js"); inc("User:Topaz/comm.js"); inc("User:Topaz/wputil.js"); //inc("User:Topaz/statuschanger.js"); inc("User:Master of Puppets/statuschanger.js");; //inc("Wikipedia:WikiProject User scripts/Scripts/Time"); inc("User:VoA/monobook.js");

// see http://paperlined.org/apps/wikipedia/Tool2/ for instructions on adding this to your monobook.js

// To run this tool on other servers: //	1. copy this script to the target server (this is required because of javascript cross-site security restrictions)

//	2. update the following URL //		for example: "User:Interiot/Tool2/code.js" var tool2_url = "User:Interiot/Tool2/code.js";

//	3. update this namespace list, extracted from something like http://en.wikiquote.org/wiki/Special:Export// //			These *should not* have colons after them. var namespaces = [ "Talk", "User", "User talk", "Wikiquote", "Wikiquote talk", "Image", "Image talk", "MediaWiki", "MediaWiki talk", "Template", "Template talk", "Help", "Help talk", "Category", "Category talk", // 3b. these two project project entries are not added by Special:Export, and might or might not need to be updated "Wikipedia", "Wikipedia talk" ];

//	4. update this date-parser to match the format and language of your specific wiki. Feel free to contact Interiot regarding this, if you can't find another //		copy of this script that uses the same language. // input: a text string from Special:Contributions. output: a javascript Date object // documentation: http://www.quirksmode.org/js/introdate.html#parse, http://www.elated.com/tutorials/programming/javascript/dates/ function date_parse(text) { var matches = text.match(/^([0-9:]+), +([0-9]+) +([a-z]+) +([0-9]+)$/i); if (!matches) { //dump_text("XXX");			// for debugging return matches; }

parseme = matches[3] + ", " + matches[2] + " " + matches[4] + " " + matches[1] + ":00";

//dump_text(parseme);				// for debugging

var dt = new Date; dt.setTime( Date.parse(parseme));

//dump_text(dt.toLocaleString);		// for debugging

return dt; }

// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ end of server-specific configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

// TODO: //	- the current document.location method doesn't work when the page is accessed sans-mod_rewrite //	- test with non-ASCII characters //		- non-ascii usernames //		- ??

var prefix = ""; var params = parse_params;

addOnloadFunction(function { var path_len = document.location.pathname.length;  // trigger once we view the right page  if (document.location.pathname.substring(path_len - tool2_url.length, path_len) == tool2_url) {    // get the prefix (needs to be fixed to work sans-mod_rewrite prefix = document.location.protocol + "//" + document.location.host + "/" + document.location.pathname.substring(1, path_len - tool2_url.length);

// blank the inner contents of the page var bodyContent = document.getElementById("bodyContent"); while (bodyContent.childNodes.length > 0) bodyContent.removeChild(bodyContent.lastChild);

if (document.location.search.length == 0) { generate_input_form(bodyContent); } else { generate_main_report(bodyContent); } } });

function generate_input_form(bodyContent) { bodyContent.innerHTML = " ";

var form = bodyContent.getElementsByTagName("form")[0]; form.method = "get"; form.action = document.location;

document.getElementById("username").focus; }

function generate_main_report { fetch_data(params["username"], "", output_main_report, 0, []); }

function add_stats_row(left_col, right_col) { var row = document.createElement("tr"); var left = document.createElement("td"); var right = document.createElement("td"); document.getElementById("basic_stats").appendChild(row); row.appendChild(left); row.appendChild(right); //left.innerHTML = left_col; left.appendChild( document.createTextNode(left_col) ); right.appendChild( document.createTextNode(right_col) ); return row; }

function output_main_report(history) { // -- generate summary statistics var unique_articles = new Array; var namespace_numedits = new Array; for (var i=0; i<namespaces.length; i++) { namespace_numedits[ namespaces[i] ] = 0; }	namespace_numedits[""] = 0; for (var i=0; i<history.length; i++) { var h = history[i]; unique_articles[ h["title"] ]++; namespace_numedits[ h["namespace"] ]++; }	var unique_articles_keys = keys(unique_articles);

// -- output report var table = document.createElement("table"); table.id = "basic_stats"; document.getElementById("bodyContent").appendChild(table);

add_stats_row("Username", params["username"]); add_stats_row("Total edits", history.length); add_stats_row("Distinct pages edited", unique_articles_keys.length); add_stats_row("Average edits/page", new Number(history.length / unique_articles_keys.length).toFixed(3)); add_stats_row("First edit", history[ history.length-1 ]["date_text"] );

// add a blank row add_stats_row("", "").childNodes[0].style.height = "1em";

add_stats_row("(main)", namespace_numedits[""]); for (var i=0; i<namespaces.length; i++) { var nmspc = namespaces[i]; if (namespace_numedits[nmspc]) { add_stats_row(nmspc, namespace_numedits[nmspc]); }	} }

// ===================================== HTML-scraping backend =========================================

function add_loading_notice { if (document.getElementById("loading_notice")) return; var loading = document.createElement("div"); loading.id = "loading_notice"; loading.innerHTML = " Retrieving data ... "; document.getElementById("bodyContent").appendChild(loading); } function remove_loading_notice { var loading = document.getElementById("loading_notice"); if (!loading) return; loading.parentNode.removeChild(loading); }

var offset_regexp = /href="[^"]+:Contributions[^"]+offset=(\d+)/gi; function fetch_data(username, end_date, handler, offset, page_list) {	add_loading_notice;	var url = prefix + "Special:Contributions/" + username + "?offset=" + offset + "&limit=5000";	loadXMLDoc(url, 		function (request) {			var next_offset = 0;			if (request.readyState != 4)  return;			if (request.status == 200) {				page_list.push(request.responseText);				//dump_text(request.responseText);

// see if there's another pageful to get var matches = map( function(p){						return p.match( /(\d+)$/ )[0];					}, request.responseText.match( offset_regexp ) ); for (var i=0; i<matches.length; i++) { var v = matches[i] * 1; if (v != 0 && (offset == 0 || v < offset)) { next_offset = v;						break; }				}			}

//next_offset = 0;			// for testing only, retrieve just the first page of results

if (next_offset == 0) { parse_data(page_list, handler); } else { // tail recurse fetch_data(username, end_date, handler, next_offset, page_list); }		}); }

// input: a list of strings, each string containing the HTML from a single page // output: a list, where each individual entry is a specific edit from history function parse_data(page_list, handler) { //var total_len = 0; //for (var i=0; i[^(]+\(([^(<]+)/i )[1]					.replace( / +$/, "");			history_entry["date"] = date_parse( history_entry["date_text"] );			history_entry["title"] = history_text.match( /title="([^"]+)"/i )[1]					.replace( /&quot;/g, "\"")					.replace( /&amp;/g, "&");			var find_comment = history_text.replace(/ .*?<\/span> ?/, "");			history_entry["comment"] = ifmatch(find_comment.match( / (.*?)<\/span>/ ))					.replace(/^\((.*)\)$/, "$1");			history_entry["minor"] = /<span class="minor"/.test(history_text);			history_entry["oldid"] = ifmatch(history_text.match(/oldid=([0-9]+)/i));

history_entry["namespace"] = ""; for (var nmspc_ctr=0; nmspc_ctr<namespaces.length; nmspc_ctr++) { var nmspc = namespaces[nmspc_ctr] + ":"; if (history_entry["title"].substring(0, nmspc.length) == nmspc) { history_entry["namespace"] = namespaces[nmspc_ctr]; break; }			}

//dump_object(history_entry);

if (history_entry["title"] != last_history_ent["title"] || history_entry["oldid"] != last_history_ent["oldid"]) edit_history.push(history_entry); last_history_ent = history_entry; }	}

remove_loading_notice;

handler(edit_history); }

// ===================================== test/debug functions =========================================

function dump_text(text) { //alert("dump_text, with text of size " + text.length);

var pre = document.createElement("pre");

var div = document.createElement("div"); div.style.width = "60em"; div.style.maxHeight = "40em"; div.style.overflow = "auto";

pre.appendChild(document.createTextNode(text)); div.appendChild(pre); document.getElementById("bodyContent").appendChild(div); }

function dump_lines(ary) { dump_text("--> " + ary.join("\n--> ")); }

function dump_object(obj) { var toString = ""; for (var prop in obj) { toString += prop + ": " + obj[prop] + "\n"; }	dump_text(toString); }

// ===================================== utility functions =========================================

function addOnloadFunction(f) { if (window.addEventListener) window.addEventListener("load",f,false); else if (window.attachEvent) window.attachEvent("onload",f); else { var oldOnload='_old_onload_'+addOnloadFunction.uid; addOnloadFunction[oldOnload] = window.onload ? window.onload : function {}; window.onload = function { addOnloadFunction[oldOnload]; f; } ++addOnloadFunction.uid; } }

function parse_params { var pairs = document.location.search.substring(1).split("&"); var ret = []; for (var i=0; i < pairs.length; i++) { var values = pairs[i].split("="); ret[values[0]] = unescape(values[1]); } return ret; }

function loadXMLDoc(url, handler) {   // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req = new XMLHttpRequest; req.onreadystatechange = function {handler(req)}; req.open("GET", url, true); req.send(null); // branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = function {handler(req)}; req.open("GET", url, true); req.send; }   } }

// see http://search.cpan.org/dist/perl/pod/perlfunc.pod#map function map (handler, list) { var ret = new Array; for (var i=0; i= 2) { return ary[1]; } else { return ""; } }

mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js&action=raw&ctype=text/javascript'); // //

importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu'); importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css'); importScript('Wikipedia:WikiProject Deletion sorting/delsort.js');

//this helps automate AfD closing by adding a 'close' tab to AfD debates importScript('User:John254/AFD closure/monobook.js');

// User:Krimpet/CH2.js importScript('User:Krimpet/CH2.js');

//this helps automate AfD closing by adding a 'close' tab to AfD debates //written by User:Johnleemk based on WikiProject User scripts/Scripts/test-n.js by User:Celestianpower

function autoafd_result { var close = prompt("Result of debate?") var f = document.editform, t = f.wpTextbox1; t.value = t.value.split('{{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD').join('{{ns:0'); t.value = "{{subst:" + "at" + "}} " + close + ". " + "~" + "~" + "~" + "~" + '\n' + '\n' + t.value; if (t.value.length > 0) t.value += '\n'; t.value += "{{subst:" + "ab" + "}}"; f.wpSummary.value = "Closing debate; result was " + close; }

function autoafd_relist { var f = document.editform, t = f.wpTextbox1; if (t.value.length > 0) t.value += '\n'; t.value += "{{subst:" + "relist" + "|~" + "~" + "~" + "~}}"; f.wpSummary.value = "Relisting debate"; }

function autoafd_keep { var date = prompt("Nomination was made when?") var votepage = prompt("Vote page is? (Enter 'd' for default.)") var f = document.editform, t = f.wpTextbox1;

// If default votepage... if (votepage=="d") {       var temp = document.editform.action.split("/w/index.php?title="); var temp = temp[1].split("&action=submit"); var temp = temp[0].substring(5); var votepage = temp; }

t.value = "{{" + "oldafdfull" + "|date=" + date + "|votepage=" + votepage + "}}" + '\n' + '\n' + t.value; f.wpSummary.value = "Article survived AfD"; }

function autoafd_no_consensus { var date = prompt("Nomination was made when?") var votepage = prompt("Vote page is? (Enter 'd' for default.)") var f = document.editform, t = f.wpTextbox1;

// If default votepage... if (votepage=="d") {       var temp = document.editform.action.split("/w/index.php?title="); var temp = temp[1].split("&action=submit"); var temp = temp[0].substring(5); var votepage = temp; }

t.value = "{{" + "oldafdfull" + "|date=" + date + "|result=no consensus|votepage=" + votepage + "}}" + '\n' + '\n' + t.value; f.wpSummary.value = "Article survived AfD with no consensus"; }

function autoafd_redirect { var date = prompt("Nomination was made when?") var redirect = prompt("Redirect to?") var votepage = prompt("Vote page is? (Enter 'd' for default.)") var f = document.editform, t = f.wpTextbox1;

// If default votepage... if (votepage=="d") {       var temp = document.editform.action.split("/w/index.php?title="); var temp = temp[1].split("&action=submit"); var temp = temp[0].substring(5); var votepage = temp; }

t.value = "{{" + "oldafdfull" + "|date=" + date + "|result=redirect to " + redirect + "|votepage=" + votepage + "}}" + '\n' + '\n' + t.value; f.wpSummary.value = "Article redirected to " + redirect + " as per AfD"; }

function autoafd_merge { var date = prompt("Nomination was made when?") var redirect = prompt("Merge and redirect to?") var votepage = prompt("Vote page is? (Enter 'd' for default.)") var f = document.editform, t = f.wpTextbox1;

// If default votepage... if (votepage=="d") {       var temp = document.editform.action.split("/w/index.php?title="); var temp = temp[1].split("&action=submit"); var temp = temp[0].substring(5); var votepage = temp; }

t.value = "{{" + "oldafdfull" + "|date=" + date + "|result=merge and redirect to " + redirect + "|votepage=" + votepage + "}}" + '\n' + '\n' + t.value; f.wpSummary.value = "Article merged and redirected to " + redirect + " as per AfD"; }

function autoafd_other { var date = prompt("Nomination was made when?") var result = prompt("Result was?") var votepage = prompt("Vote page is? (Enter 'd' for default.)") var f = document.editform, t = f.wpTextbox1;

// If default votepage... if (votepage=="d") {       var temp = document.editform.action.split("/w/index.php?title="); var temp = temp[1].split("&action=submit"); var temp = temp[0].substring(5); var votepage = temp; }

t.value = "{{" + "oldafdfull" + "|date=" + date + "|result=" + result + "|votepage=" + votepage + "}}" + '\n' + '\n' + t.value; f.wpSummary.value = "AfDed; result was " + result; }

function autoafd_add_afd_tabs { // Only add for pages with the right string somewhere in the title if (document.title.indexOf("Editing Wikipedia:Articles for deletion/") != -1) {     mw.util.addPortletLink('p-cactions', 'javascript:autoafd_result', "close"); mw.util.addPortletLink('p-cactions', 'javascript:autoafd_relist', "relist"); } if (document.title.indexOf("Editing Talk:") != -1) {     mw.util.addPortletLink('p-cactions', 'javascript:autoafd_keep', "keep"); mw.util.addPortletLink('p-cactions', 'javascript:autoafd_no_consensus', "no consensus"); mw.util.addPortletLink('p-cactions', 'javascript:autoafd_redirect', "redirect"); mw.util.addPortletLink('p-cactions', 'javascript:autoafd_merge', "merge"); mw.util.addPortletLink('p-cactions', 'javascript:autoafd_other', "other"); } }

$(autoafd_add_afd_tabs);

//end AfD closing script

//

importScript('User:Mr.Z-man/hideClosedAFD.js');

//////////////////////////////////////////////////////////////// // =-=-=- HELPER FUNCTIONS -=-=-=- function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) {       if(key && title) {           ta[id] = [key, title]; }       else if(key) {           ta[id] = [key, '']; }       else if(title) {           ta[id] = ['', title]; }   }    // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; } function addToolboxLink(url, name, id, title){ var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; addlilink(tb, url, name, id, title); } function addTab(url, name, id, title, key) { return mw.util.addPortletLink('p-cactions', url, name, id, title, key); } function addLink(where, url, name, id, title, key, after){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); var tabs = document.getElementById(where).getElementsByTagName('ul')[0]; if(after) { tabs.insertBefore(li,document.getElementById(after)); } else { tabs.appendChild(li); }   if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title];} }   // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; } function addlimenu(tabs, name, id) {   var na = document.createElement('a'); na.href = '#'; var mn = document.createElement('ul'); na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.id = id; li.className = 'tabmenu'; li.appendChild(na); li.appendChild(mn); tabs.appendChild(li); return li; } function addnavbox_link(URL,Name,ID) { var portlet = document.getElementById('p-navigation'); var links = portlet.getElementsByTagName('ul')[0]; links.innerHTML += '' + Name + ''; }

// ======== QuickBlocks ======= function QuickBlock (expiry,reason,ao,autob,accfreeze,emailblock) { blockForm = document.getElementById('blockip'); inputs = blockForm.getElementsByTagName('input'); for (i=0; i<inputs.length; i++) { if (inputs[i].name == 'wpBlockOther') { inputs[i].value = expiry; continue; }   if (inputs[i].name == 'wpBlockReason') { inputs[i].value = reason; continue; }   if (inputs[i].name == 'wpAnonOnly') { if (ao==1) { inputs[i].checked = 'checked'; }     else if (ao==0) { inputs[i].checked = false; }     continue; }   if (inputs[i].name == 'wpEnableAutoblock') { if (autob==0) { inputs[i].checked=false; }     continue; }   if (inputs[i].name == 'wpCreateAccount') { if (accfreeze==0) { inputs[i].checked=false; }     continue; }   if (inputs[i].name == 'wpEmailBan') { if (emailblock==1) { inputs[i].checked = 'checked'; } continue; } }  blockForm.submit; } $(function{ if (document.title.indexOf("Block user") == -1) return;  else {    //TEMPLATE: addTab('javascript:('+QuickBlock+')("expiry","reason",ao,autob,accfreeze,emailblock)','label','id');    addTab('javascript:('+QuickBlock+')("1 hour","Blocked for one hour, due to recent abuse. To appeal or request help, please contact me or follow the instructions below.",1,1,1,0)','hour','p-block-ab-1h');    addTab('javascript:('+QuickBlock+')("24 hours","Blocked for 24 hours, due to recent abuse. To appeal or request help, please contact me or follow the instructions below.",1,1,1,0)','24h','p-block-ab-24h');    addTab('javascript:('+QuickBlock+')("48 hours","Blocked for 48 hours, due to recent abuse. To appeal or request help, please contact me or follow the instructions below.",1,1,1,0)','48h','p-block-ab-48h'); addTab('javascript:('+QuickBlock+')("1 week","Blocked for one week, due to repeat abuse. To appeal or request help, please contact me or follow the instructions below.",1,1,1,0)','week','p-block-ab-1w'); addTab('javascript:('+QuickBlock+')("1 month","Blocked for one month, due to repeat abuse. To appeal or request help, please contact me or follow the instructions below.",1,1,1,0)','month','p-block-ab-1m'); addTab('javascript:('+QuickBlock+')("indefinite","Blocked indefinitely, due to abuse. To appeal or request help, please contact me or follow the instructions below.",1,1,1,0)','indef','p-block-ab-ind'); addTab('javascript:('+QuickBlock+')("6 months","{{anonblock}}",1,0,1,0)','anon-6m','p-block-anon-6m'); //{{anonblock}} addTab('javascript:('+QuickBlock+')("48 hours","This IP address has recently been used abusively. To appeal or request help, please contact me or follow the instructions below.",0,1,1,0)','48h-hard','p-block-ab-48-hard'); addTab('javascript:('+QuickBlock+')("1 year","{{openproxy}}",0,1,1,0)','proxy','p-block-proxy'); //{{openproxy}} addTab('javascript:('+QuickBlock+')("indefinite","Similar to existing user or recent meme. To appeal or request help, please contact me or follow the instructions below.",1,1,1,0)','sock','p-block-sock-ind'); addTab('javascript:('+QuickBlock+')("indefinite","{{usernameblocked}}",1,0,0,0)','name','p-block-username'); //{{Usernameblocked}} addTab('javascript:('+QuickBlock+')("indefinite","abuse",1,1,1,1)','grawp','p-block-grawp'); } }); //************

importScript('User:M/reword.js'); //