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 );

function ListProcessor { this.rcListItemIterator = null; this.rcLogItemIterator = null; this.i18n = {}; if (document.getElementsByClassName("mw-special-Recentchanges").length != 0) { this.setupRcList; } }

ListProcessor.prototype.processRcList = function {

while (this.rcListItemIterator.hasNext) { var item = this.rcListItemIterator.getNext; var firstLinkRef = item.getElementsByTagName("a")[0].getAttribute("href"); var matches = firstLinkRef.match(/Special:Log\/(.*)/);

if (matches) { var itemData = this.rcLogItemIterator.getNext; this.processListItem(item, itemData); }   if (this.rcLogItemIterator.remaining == 0) { this.rcLogItemIterator.getNextContinue(this); return; } } }

ListProcessor.prototype.processListItem = function(item, itemData) { 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); }

}

ListProcessor.prototype.setupRcList = function { if (mw.user.options.get('usenewrc') == 0) { this.rcListItemIterator = new RcListItemIteratorNormal; this.rcLogItemIterator = new RcLogItemIterator(this); } else { this.rcListItemIterator = new RcListItemIteratorEnhanced; this.rcLogItemIterator = new RcLogItemIterator(this); } }

function RcListItemIteratorNormal { this.minorIndex = 0 this.majorIndex = 0 this.lists = document.getElementsByClassName("mw-special-Recentchanges")[0] .getElementsByClassName("special"); this.listitems = this.lists[this.majorIndex].getElementsByTagName("li"); }

RcListItemIteratorNormal.prototype.getNext = function { if (this.minorIndex == this.listitems.length) { this.minorIndex = 0; this.majorIndex++; this.listitems = this.lists[this.majorIndex].getElementsByTagName("li"); } this.minorIndex++; return this.listitems[this.minorIndex - 1]; }

RcListItemIteratorNormal.prototype.hasNext = function { return this.majorIndex < this.lists.length; }

function RcListItemIteratorEnhanced { this.minorIndex = 0 this.majorIndex = 0 this.lists = document.getElementsByClassName("mw-special-Recentchanges")[0] .getElementsByClassName("special"); this.listitems = this.lists[this.majorIndex].getElementsByTagName("li"); }

RcListItemIteratorEnhanced.prototype.getNext = function { if (this.minorIndex == this.listitems.length) { this.minorIndex = 0; this.majorIndex++; this.listitems = this.lists[this.majorIndex].getElementsByTagName("li"); } this.minorIndex++; return this.listitems[this.minorIndex - 1]; }

RcListItemIteratorEnhanced.prototype.hasNext = function { return this.majorIndex < this.lists.length; }

function RcLogItemIterator(callback) { this.parsedRCLogs = null; this.rcLogIndex = 0; var timestamp = document.getElementsByClassName("rcoptions")[0].innerHTML.match(/&amp;from=(\d{14})/)[1]; this.queryApi(timestamp, callback); }

RcLogItemIterator.prototype.getNext = function { this.rcLogIndex++; return this.parsedRCLogs.query.recentchanges[this.rcLogIndex - 1]; }

RcLogItemIterator.prototype.remaining = function { return this.parsedRCLogs.query.recentchanges.length - this.rcLogIndex; }

RcLogItemIterator.prototype.getNextContinue = function(callback) { this.rcLogIndex = 0; var timestamp = this.parsedRCLogs["query-continue"].recentchanges.rccontinue.split("|")[0]; this.queryApi(timestamp, callback); }

RcLogItemIterator.prototype.queryApi = function(timestamp, callback) { //getQueryStringItems("title"); //&hidemyself=1&hideminor=1&hidebots=0&hideanons=1&hideliu=1 var hideTheseElements = ""; if (getQueryStringItems("hideminor") == "0") { } else if (getQueryStringItems("hideminor") == "1") { hideTheseElements += "|!minor"; } else if (mw.user.options.get("hideminor") == 0) { } else if (mw.user.options.get("hideminor") == 1) { hideTheseElements += "|!minor"; } if (getQueryStringItems("hidebots") == "0") { } else if (getQueryStringItems("hidebots") == "1") { hideTheseElements += "|!bot"; } if (getQueryStringItems("hideanons") == "0") { } else if (getQueryStringItems("hideanons") == "1") { hideTheseElements += "|!anon"; } if (getQueryStringItems("hideliu") == "0") { } else if (getQueryStringItems("hideliu") == "1") { hideTheseElements += "|anon"; } if (mw.user.options.get("hidepatrolled") == 0) { } else if (mw.user.options.get("hidepatrolled") == 1) { hideTheseElements += "|!patrolled"; } var hideMyself = ""; if (getQueryStringItems("hidemyself") == "1") { hideMyself="&rcexcludeuser=" + wgUserName; } var requestUrl = "http://www.mariowiki.com/api.php?action=query&list=recentchanges&rclimit=500&rctype=log&rcprop=loginfo|user|title|timestamp&rcstart=" + timestamp + "&rcshow=" + hideTheseElements.substring(1) + hideMyself + "&format=json"; var iterator = this; var rclogs = new XMLHttpRequest; rclogs.open("GET", requestUrl, true); rclogs.setRequestHeader('Api-User-Agent', 'Test/1.0'); rclogs.onreadystatechange = function {

if (!(this.readyState == 4 && this.status == 200)) { return; }

iterator.parsedRCLogs = JSON.parse(this.responseText); callback.processRcList; } rclogs.send; }

function processBlockLog(item, itemData) { if (itemData.logaction == "unblock"//||     /*typeof itemData.actionhidden != 'undefined'*/ ) { 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; }

function getQueryStringItems(itemName) { if (typeof this.items == 'undefined') { this.items = {}; var splitQueryString = window.location.search.substring(1).split("&"); for (var i = 0; i < splitQueryString.length; i++) { var splitSplitQueryString = splitQueryString[i].split("="); this.items[splitSplitQueryString[0]] = splitSplitQueryString[1]; } }  return this.items[itemName]; }

var listProcessor = new ListProcessor;