User:Mo0/monobook.js

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Mo0 (talk | contribs) at 07:44, 25 July 2006 (Okay, let's see if I fixed it.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Big thanks to User:JesseW for leading me to:
// [[Wikipedia:WikiProject_User_scripts/Techniques#Onload_Structure]]
// and to User:Sasquatch for the if(document.get ... code
//
// Working version done: Nov 2 2005 @ 7:44 PM EST
// Shortens edit, protect, talk and delete tabs
//
// References:
// http://en.wikipedia.org/wiki/MediaWiki:Monobook.js
// User:JesseW/monobook.js --- User:Drini/monobook.js
// Mo0 just basically stole this version from User:RoyBoy's monobook.

//	<pre><nowiki>

//////////////////////////////////////////
//AfD closer stuff
//Stolen from Drini, who I think stole it from ABCD or Celestianpower, not sure
//////////////////////////////////////////
function closeafd(bold, notbold){
   var form = document.editform;
   var txt = form.wpTextbox1;
   txt.value = "{{subst:at}} '''" + bold + "'''" + notbold + ". ~~~~\n" + txt.value + "\n{{subst:ab}}\n";
   form.wpSummary.value = "Closing AfD discussion: " + bold + notbold;
   form.wpWatchthis.checked = false;
}

function afdresult(){
   var res = prompt("Result?");
   if(!res) return;
   var form = document.editform;
   form.wpSummary.value = 'AFD result';
   var txt = form.wpTextbox1;
   txt.value += '{{oldafdfull|date={{subst:CURRENTDAY}} {{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}|result=' + res + '|votepage={{subst:PAGENAME}}}}';
   txt.focus();
}

function afddelete(){
   document.forms.deleteconfirm.wpReason.value = '[[Wikipedia:Articles for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')).replace(/^(Talk|Wikipedia( talk)?):/, '') + ']]' + ' ' + '--' + ' ' + 'Result was DELETE.';
}

function fairusedelete(){
   document.forms.deleteconfirm.wpReason.value = 'Orphaned fair use image tagged for 7 days.';
}


function replace(){
   var s = prompt("Search regexp?");
   if(s){
       var r = prompt("Replace regexp?");
       if(!r && r != '') return;
       var txt = document.editform.wpTextbox1;
       txt.value = txt.value.replace(new RegExp(s, "g"), r);
   }
}

function afdresult(){
   var res = prompt("Result?");
   if(!res) return;
   var form = document.editform;
   form.wpSummary.value = 'AFD result';
   var txt = form.wpTextbox1;
   txt.value = '{{oldafdfull|date={{subst:CURRENTDAY}} {{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}|result=' + res + '|votepage={{subst:PAGENAME}}}}' + txt.value;
   txt.focus();
}

//////////////////////////////////////////
// Tabs by Korath
// returns <li><a href="url">name</a></li>
/////////////////////////////////////////
function addlilink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

  var li = document.createElement('li');
  li.appendChild(na);
  return li;
}

// appends msg to the currently-editted page, sets the summary to summ,
// and marks or unmarks the Watch this page checkbox according to watch.
function edit_summary_watch(msg, summ, watch)
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += msg;
  f.wpSummary.value = summ;
}

function test()
{
  var f = document.editform, t = f.wpTextbox1;
  var page = prompty("Vandalism to which article?")
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "test-n|" + page + "}} + "-" + "~" + "~" + "~" + "~";
  f.wpSummary.value = "Thanks for testing out Wikipedia!";
}

function testn(number)
{
  var page = prompt("Vandalism to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "test" + number + "-n|" + page + "}} -" + " " + "~" + "~" + "~" + "~";
  if (t.value > 2)
    f.wpSummary.value = "Vandalism to [[" + page + "]] - warning " + number;
  else   
    f.wpSummary.value = "Please stop vandalising [[" + page + "]].";
}

function blankwarn(number)
{
  var page = prompt("Vandalism to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "test2a-n|" + page + "}} -" + " " + "~" + "~" + "~" + "~";
  f.wpSummary.value = "Please stop blanking [[" + page + "]].";
}

function bvn(number)
{
  var page = prompt("Vandalism to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "bv-n|" + page + "}} -" + " " + "~" + "~" + "~" + "~";
  f.wpSummary.value = "Stop vandalising [[" + page + "]].";
}

function repeatvandal(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   txt.value = "{{subst:repeat vandal}} ~~~~ \n" + txt.value;
   form.wpSummary.value = "Repeated vandalism. Block on sight upon further vandalism attempts.";
}


function usernameblock(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   txt.value = "{{subst:usernameblock}} ~~~~ \n" + txt.value;
   form.wpSummary.value = "Username block. Please choose another.";
}

function vandalblock(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   if (txt.value.length > 0)
     txt.value += '\n';
   txt.value += "{{subst:vandalblock}} ~~~~ \n\n";
   form.wpSummary.value = "This account is only being used for vandalism, and has been permanently blocked.";
}

function indefblocked(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   txt.value = "{{subst:indefblocked}}";
   form.wpSummary.value = "This user has been indefinitely blocked.";
}

function indefblock(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   txt.value = txt.value + "{{subst:vpblock}}" + " ~~~~";
   form.wpSummary.value = "You have been indefinitely blocked for violation of Wikipedia policy.";
}

function impostor(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   var imped = prompt("Impostor of who?");
   txt.value = "{{impostor-m|" + imped + "}}\n\n" + txt.value;
   form.wpSummary.value = "This user appears to be an impostor of [[User:" + imped + "]], and has been blocked indefinitely.";
}

function vandalismonly(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   txt.value = "{{subst:indef-vandal}}\n\n" + txt.value;
   form.wpSummary.value = "This account appears to have been created solely for the purpose of vandalism, and has been blocked indefinitely.";
}

function attackuser(){
   var form = document.editform;
   var txt = form.wpTextbox1;
   var attacked = prompt("Who's being attacked?");
   txt.value = "{{attackuser-m|" + attacked + "}}\n" + txt.value;
   form.wpSummary.value = "This username exists solely to attack or disparage [[User:" + attacked + "]], and has been blocked indefinitely.";
}

// adds various tabs to call the above
function add_tabs()
{
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

  // Only add for pages with "Editing User talk:" somewhere in the title
  if (document.title.indexOf("Editing User talk:") != -1)
    {
      //change "move" tab to "m" for more room
      if(document.getElementById('ca-move'))
        document.getElementById('ca-move').firstChild.innerHTML = 'm';
      if(document.getElementById('ca-history'))
        document.getElementById('ca-history').firstChild.innerHTML = 'h';

      //change "user page" tab to "anon" to put them in their place, HA!
      //if(document.getElementById('ca-nstab-user'))     
      //document.getElementById('ca-nstab-user').firstChild.innerHTML = 'anon';

      tabs.appendChild(addlilink('javascript:edit_summary_watch("{{" + "subst:anon}} -" + " " + "~" + "~" + "~" + "~", "{{" + "anon}}", false, 0)',"Anon"));
      tabs.appendChild(addlilink('javascript:edit_summary_watch("{{" + "subst:welcome}} -" + " " + "~" + "~" + "~" + "~", "Welcome!", false, 0)',"Welcome!"));
     
      tabs.appendChild(addlilink('javascript:testn(1)',"1"));
      tabs.appendChild(addlilink('javascript:testn(2)',"2"));
      tabs.appendChild(addlilink('javascript:blankwarn(2)',"2a"));
      tabs.appendChild(addlilink('javascript:testn(3)',"3"));
      tabs.appendChild(addlilink('javascript:testn(4)',"4"));
      tabs.appendChild(addlilink('javascript:bvn(1)',"bv"));
      tabs.appendChild(addlilink('javascript:edit_summary_watch("{{" + "subst:vblock" + "|" + prompt("Time?") + "|" + " " + "~" + "~" + "~" + "~" + "}}", "Blocked user!", true, 1)',"block"));
      tabs.appendChild(addlilink('javascript:indefblock()',"indef"));
      tabs.appendChild(addlilink('javascript:repeatvandal()',"repeat"));
      tabs.appendChild(addlilink('javascript:usernameblock()',"username"));
      tabs.appendChild(addlilink('javascript:vandalblock()',"vandal"));

    }
	
if (document.title.indexOf("Editing Wikipedia:Articles for deletion") != -1)
    {
        tabs.appendChild(addlilink('javascript:closeafd("KEEP", "")', 'Keep', ''));
        tabs.appendChild(addlilink('javascript:closeafd("DELETE", "")', 'Delete', ''));
        tabs.appendChild(addlilink('javascript:closeafd(prompt("Result?"), "")', 'Other', ''));
    }

if (document.title.indexOf("Editing Talk:") != -1)
    {
        tabs.appendChild(addlilink('javascript:afdresult()',"Result"));
    }

if (document.title.indexOf("Editing User:") != -1)
    {
      tabs.appendChild(addlilink('javascript:impostor()',"impostor"));
      tabs.appendChild(addlilink('javascript:attackuser()',"attackuser"));
      tabs.appendChild(addlilink('javascript:vandalismonly()',"vandal"));
      tabs.appendChild(addlilink('javascript:indefblocked()',"indef"));
    }


if (document.title.indexOf("Confirm delete") != -1)
    {
        tabs.appendChild(addlilink('javascript:afddelete()',"AfD"));
        tabs.appendChild(addlilink('javascript:fairusedelete()',"fairuse"));
    }
}

function addEditSection0() {
  ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page'];
  if (!document.getElementById) return;
  x = document.getElementById('ca-edit');
  if(!x) return;
  y = document.createElement('LI');
  y.id = 'ca-edit-0';
  if (x.className == 'selected') {
    if (/&action=edit&section=0$/.test(window.location.href)) {
      x.className = 'istalk';
      y.className = 'selected';
    } else {
      x.className = 'selected istalk';
    }
  } else if (x.className == 'selected istalk') {
    if (/&action=edit&section=0$/.test(window.location.href)) {
      x.className = 'istalk';
      y.className = 'selected istalk';
    } else {
      y.className = 'istalk';
    }
  } else {
    y.className = x.className;
    x.className = 'istalk';
  }
  z = document.createElement('A');
  if (x.children) {
    z.href = x.children[0].href + '&section=0';
    z.appendChild(document.createTextNode('0'));
    y.appendChild(z);
    document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling);
  } else {
    z.href = x.childNodes[0].href + '&section=0';
    z.appendChild(document.createTextNode('0'));
    y.appendChild(z);
    document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling);
  }
}

function shortTabs() {
  if(document.getElementById('ca-edit'))
    document.getElementById('ca-edit').firstChild.innerHTML = 'edit';

  if(document.getElementById('ca-protect'))
    document.getElementById('ca-protect').firstChild.innerHTML = 'pro';

  if(document.getElementById('ca-talk'))
    document.getElementById('ca-talk').firstChild.innerHTML = 'talk';

  if(document.getElementById('ca-delete'))
    document.getElementById('ca-delete').firstChild.innerHTML = 'del';

  if(document.getElementById('ca-unwatch'))
    document.getElementById('ca-unwatch').firstChild.innerHTML = 'unw';

  if(document.getElementById('ca-watch'))
    document.getElementById('ca-watch').firstChild.innerHTML = 'w';
}

// ***** Window Load ******

window.onload = Main;

function Main()
{
  shortTabs();
  add_tabs();

  if (document.title.indexOf("Editing User talk:") = -1)
    addEditSection0();
}

//	</nowiki></pre>

// Script from [[User:Lupin/recent2.js]]
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/recent2.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// 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) {
  if (navigator.userAgent.toLowerCase().indexOf('msie')+1)
  {
  bodyContent.innerHTML = "This counter does not currently work in Internet Explorer.  Please <a href='http://www.getfirefox.com'>get Firefox</a> or use <a href='http://en.wikipedia.org/wiki/Wikipedia:WikiProject_edit_counters/Flcelloguy%27s_Tool'>Flcelloguy's Tool</a> instead.";
  }
  else
  {
  bodyContent.innerHTML =
            "<form><table><tr><td>Username <td><input maxlength=128 name=username value='' id=username title='username'>" +
            "             <tr><td>         <td><input type=submit value='Submit'>" +
            "</table></form>";

  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"].replace(/\+/g, " "),
		"", 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"].replace(/\+/g, " "));
	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 = "<br><br>Retrieving data<blink>...</blink>";
	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<page_list.length; i++) total_len += page_list[i].length;
	//alert("parsing " + page_list.length + " pages comprising " + total_len + " total bytes");

	var last_history_ent = [];
	last_history_ent["title"] = "";
	last_history_ent["oldid"] = "";

	var edit_history = new Array();
	for (var pagecnt=0; pagecnt<page_list.length; pagecnt++) {
		var matches = page_list[pagecnt].match( /^<li>[^(]+\(<a href="[^"]+action=history.*/gim );
		//dump_lines(matches);
		for (var matchcnt=0; matchcnt<matches.length; matchcnt++) {
			var history_text = matches[matchcnt];

			var history_entry = new Array();
			history_entry["date_text"] = history_text.match( /^<li>([^(<]+)/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 class="autocomment">.*?<\/span> ?/, "");
			history_entry["comment"] = ifmatch(find_comment.match( /<span class='comment'>(.*?)<\/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<list.length; i++) {
    ret[i] = handler( list[i] );
    // ret.push( handler( list[i] ) );
  }
  return ret;
}

// see http://search.cpan.org/dist/perl/pod/perlfunc.pod#keys
function keys (obj) {
	var ret = new Array();
	for (var key in obj) {
		ret.push(key);
	}
	return ret;
}


function ifmatch(ary) {
	if (ary && ary.length >= 2) {
		return ary[1];
	} else {
		return "";
	}
}

//Interiot's javascript edit counter
if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
  document.write('<script type="text/javascript" src="' 
    + 'http://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js' 
    + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); }