User:Phoenix/monobook.js

function addInfoTab { //do things mw.util.addPortletLink(		'p-cactions', 		wgScript + "?title=" + wgPageName + "&action=info",		'Info',		'ca-info',		'Information and statistics about this page',		'i',		document.getElementById('ca-history').nextSibling	);

//fix the excessively stupid visual bug document.getElementById('ca-info').parentNode.insertBefore(document.createTextNode("\n"), document.getElementById('ca-info'));

//if this is the info page, highlight it	if (wgAction == "info") { document.getElementById('ca-info').className += "selected"; }

}

addOnloadHook( addInfoTab );

var rclogs = new XMLHttpRequest; rclogs.open("GET", "http://www.mariowiki.com/api.php?action=query&list=recentchanges&rclimit=500&rctype=log&rcprop=loginfo|user|title|timestamp&format=json", true); rclogs.setRequestHeader('Api-User-Agent', 'Test/1.0'); rclogs.onreadystatechange = function { if (!(this.readyState == 4 && this.status == 200)) { return; } var parsedRCLogs = JSON.parse(this.responseText); parsedRCLogs.getNext = function { this.index++; return this.query.recentchanges[this.index - 1]; } parsedRCLogs.index = 0; var lists = document.getElementsByClassName("mw-special-Recentchanges")[0] .getElementsByClassName("special");

for (var i = 0; i < lists.length; i++) { var listitems = lists[i].getElementsByTagName("li"); for (var j = 0; j < listitems.length; j++) { processListItem(listitems[j], parsedRCLogs); } } }

if (document.getElementsByClassName("mw-special-Recentchanges").length != 0) { rclogs.send; }

function processListItem (item, logdata) { var firstLinkRef = item.getElementsByTagName("a")[0].getAttribute("href"); var matches = firstLinkRef.match(/Special:Log\/(.*)/); if (matches) { var itemData = logdata.getNext; if (itemData.logtype == "block") { processBlockLog(item, itemData); } else if (itemData.logtype == "delete") { processDeleteLog(item, itemData); } else if (itemData.logtype == "move") { processMoveLog(item, itemData); } else if (itemData.logtype == "protect") { processProtectLog(item, itemData); } } }

function processBlockLog(item, itemData) { if (itemData.logaction == "unblock") { return; } var username = itemData.title.substring(5); item.appendChild(createLogeventActionlink([{text:"unblock", title: "Special:Unblock/" + username, href: "/Special:Unblock/" + username}, {text:"change block", title: "Special:Block/" + username, href: "/Special:Block/" + username}])); }

function processDeleteLog(item, itemData) { if (itemData.logaction == "restore") { return; } else if (itemData.logaction == "revision") { if (!itemData[1].match(/,/)) { item.appendChild(createLogeventActionlink([{text:"diff", title: itemData.title, href: "/index.php?title=" + itemData.title + "&diff=" + itemData[1] + "&unhide=1"}, {text:"change visibility", title: "Special:RevisionDelete", href: "/index.php?title=Special:RevisionDelete&target=" + mediawikiURIEncode(itemData.title) + "&type=revision&ids=" + itemData[1]}])); } else { item.appendChild(createLogeventActionlink([{text:"change visibility", title: "Special:RevisionDelete", href: "/index.php?title=Special:RevisionDelete&target=" + mediawikiURIEncode(itemData.title) + "&type=revision&ids=" + itemData[1]}])); } } else if (itemData.logaction == "event") { item.appendChild(createLogeventActionlink([{text:"change visibility", title: "Special:RevisionDelete", href: "/index.php?title=Special:RevisionDelete&target=" + mediawikiURIEncode(itemData.title) + "&type=logging&ids=" + itemData[0]}])); } else if (itemData.logaction == "delete") { item.appendChild(createLogeventActionlink([{text:"view/restore", title: "Special:Undelete", href: "/index.php?title=Special:Undelete&target=" + mediawikiURIEncode(itemData.title)}])); } }

function processMoveLog(item, itemData) { if (itemData.logaction == "move_redir") { return; } item.appendChild(createLogeventActionlink([{text:"revert", title: "Special:MovePage", href: "/index.php?title=Special:MovePage&wpOldTitle=" + mediawikiURIEncode(itemData.move.new_title) + "&wpNewTitle=" + mediawikiURIEncode(itemData.title) + "&wpReason=revert&wpMovetalk=0"}])); }

function processProtectLog(item, itemData) { if (itemData.logaction == "move_prot") { return; } var matches = itemData.timestamp.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z/); var processedDateString = matches[1] + matches[2] + matches[3] + matches[4] + matches[5] + matches[6]; item.appendChild(createLogeventActionlink([{text:"hist", title: itemData.title, href: "/index.php?title=" + mediawikiURIEncode(itemData.title) + "&action=history&offset=" + processedDateString}, {text:"change", title: itemData.title, href: "/index.php?title=" + mediawikiURIEncode(itemData.title) + "&action=protect"}])); }

function mediawikiURIEncode(string) { return string.replace(/\ /g, "_"). replace(/\(/g, "%28").               replace(/\)/g, "%29"). replace(/\//g, "%2F"). replace(/\:/g, "%3A"); }

function createLogeventActionlink (linkArray) { var actionlink = document.createElement("span") actionlink.setAttribute("class", "mw-logevent-actionlink"); actionlink.appendChild(document.createTextNode(" (")); for (var i = 0; i < linkArray.length; i++) {    var link = document.createElement("a");    link.appendChild(document.createTextNode(linkArray[i].text))    link.setAttribute("title", linkArray[i].title);    link.setAttribute("href", linkArray[i].href);    actionlink.appendChild(link);    if (i + 1 != linkArray.length) {      actionlink.appendChild(document.createTextNode(" | "));    }  }   actionlink.appendChild(document.createTextNode(")")); return actionlink; }