Bruger:Rodejong/tools.js

Fra Wikipedia, den frie encyklopædi
function get_query_value(query, name){
	if (typeof query != "string" || typeof name != "string")
		return "";
	var value = query.match('[&?]' + name + '=([^&]*)');
	if (value)
		return decodeURIComponent(value[1]);
	else
		return "";
}
function lastdiff() {
	mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&diff=cur&oldid=prev", "last", "ca-last", "Show most recent diff");
}
function userlogs() {
	mw.util.addPortletLink("p-cactions", mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=Special:Log/block&page=User:" + encodeURIComponent(wgTitle), "blocklog", "ca-blocklog", "block log");
}
function addtoolboxlinks() {
	mw.util.addPortletLink("p-tb", '/wiki/Special:NewPages', 'NewPages', 'pt-newpages', 'New pages', null, 'pt-logs');
	mw.util.addPortletLink("p-tb", '/wiki/Special:Log/newusers', 'NewUsers', 'pt-newusers', 'New users', null, 'pt-newpages');
	if (wgIsArticle==true && wgNamespaceNumber != 6 && wgNamespaceNumber != 7) mw.util.addPortletLink("p-tb", '/wiki/Special:PrefixIndex/'+wgPageName, 'PrefixIndex', 'pt-prefixindex', 'PrefixIndex', null, 'pt-newusers');
	if (wgIsArticle == true) mw.util.addPortletLink("p-tb", mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=Special:Log&page=' + encodeURIComponent(mw.config.get('wgPageName')), "PageLogs", "pt-logs", "Logs for this page", null);
}
function contribstools() {
	var user = encodeURIComponent(document.getElementsByName('target')[0].value);
	mw.util.addPortletLink("p-tb", "http://toolserver.org/~luxo/contributions/contributions.php?user=" + user + "&blocks=true&lang=", "Luxo's", 't-luxos', "Luxo's global contribs", null);
	mw.util.addPortletLink("p-tb", "http://toolserver.org/~pathoschild/crossblock/?target=" + user + "&hide_unblocked=on", "Crossblock", "t-crossblock", "Pathoschild's cross-wiki block tool", null, "t-luxos");
	if (!/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/.test(user)){
		mw.util.addPortletLink("p-tb", "http://toolserver.org/~vvv/sulutil.php?user=" + user, "VVV's", "t-vvv", "VVV's SUL tool", null, "t-crossblock");
		mw.util.addPortletLink("p-tb", "https://secure.wikimedia.org/wikipedia/meta/wiki/Special:CentralAuth/" + user, "CentralAuth", "t-centralauth", "Special:CentralAuth", null, "t-vvv");
	}
	if (/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/.test(user)){
		mw.util.addPortletLink("p-tb", "http://www.robtex.com/rbls/" + user + ".html", "RBL check", "t-rblcheck", "Multi-RBL check", null, "t-crossblock");
		mw.util.addPortletLink("p-tb", "http://toolserver.org/~chm/whois.php?ip=" + user, "WHOIS", "t-whois", "Toolserver WHOIS", null, "t-rblcheck");
		mw.util.addPortletLink("p-tb", "http://toolserver.org/~krimpet/torcheck.php?ip=" + user, "TOR?", "t-tor", "TOR check", null, "t-whois");
		mw.util.addPortletLink("p-tb", "http://meta.wikimedia.org/wiki/Special:GlobalBlock/" + user, "GlobalBlock", "t-globalblock", "Special:GlobalBlock", null, "t-tor");
	}
}
function purge() {
	var hist; var url;
	if (!(hist = document.getElementById('ca-history') )) return;
	if (!(url = hist.getElementsByTagName('a')[0] )) return;
	if (!(url = url.href )) return;
	mw.util.addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'), 'purge', 'ca-purge', 'Purge server cache for this page', '0');
}
function edittop() {
	// This will add an [edit] link at the top of all pages except preview pages and the main page
	if (wgNamespaceNumber < 0) return;
	if (wgAction == "edit") {
		var section = get_query_value(window.location.href, "section");
		if (section == "0") { document.getElementById("wpSummary").value = "/* Intro */ "; }
	}
	else {
		//un-hide siteSub if it's hidden
		appendCSS('#siteSub {display:inline !important; font-weight:normal !important; font-size:1.2em !important;}');
		// create span and set innerHTML to link
		var sectionZero = document.createElement('span');
		sectionZero.setAttribute('class','editsection');
		var a = document.createElement("a");
		a.href = wgScript+'?title='+ encodeURIComponent(mw.config.get('wgPageName'))+'&action=edit&section=0';
		a.title = 'Edit section: Intro';
		a.appendChild(document.createTextNode("edit"));
		sectionZero.appendChild(document.createTextNode("["));
		sectionZero.appendChild(a);
		sectionZero.appendChild(document.createTextNode("]"));
		// insert sectionZero into the DOM before the first level 1 heading
		document.getElementById('siteSub').insertBefore(sectionZero,document.getElementById('siteSub').firstChild);
	}
}
function blockhist() {
	var ul = document.getElementById('bodyContent').getElementsByTagName('ul')[0];
	if (!ul || !ul.getElementsByTagName('li')[0]){return;}//nothing to do
	var l = ul.getElementsByTagName('li');
	if (l[0].innerHTML.indexOf('">block</a>)') ==-1){//non-admin
		//somehow get the user and create links as for the admin section below
		return;
	}
	//use unblock links
	if (location.href.search(/&page=[^&]/) ==-1) {
//		alert("add stuff");
		for (var i=0; i<l.length; i++) {
			if (l[i].getElementsByTagName('a')[4]) {
			var name = l[i].getElementsByTagName('a')[4].innerHTML;
			l[i].innerHTML = '(<a href="/w/index.php?title=Special%3ALog&type=block&page=User:' + name + '">hist</a>) (<a href="/w/index.php?title=Special%3AIpblocklist&action=search&limit=&ip=' + name + '">status</a>) ' + l[i].innerHTML;
			}
		}
	}
	else {
		var name = l[0].getElementsByTagName('a')[4].innerHTML;
		l[0].innerHTML = '(<a href="/w/index.php?title=Special%3AIpblocklist&action=search&limit=&ip=' + name + '">status</a>) ' + l[0].innerHTML;
	}
}
 
if ( wgCanonicalNamespace != "Special" ) addOnloadHook(purge);
if ( wgCanonicalSpecialPageName == "Contributions" ) addOnloadHook(contribstools);
if ( wgCanonicalSpecialPageName == 'IPBlockList' || wgCanonicalSpecialPageName == 'Log' && ( location.href.search(/\/block|type=block/) != -1 ) ) addOnloadHook(blockhist);
if ( wgIsArticle == true && wgCanonicalNamespace != 'Special' ) addOnloadHook(lastdiff);
if ( wgIsArticle == true && ( wgNamespaceNumber == 2 || wgNamespaceNumber == 3 ) && wgPageName.indexOf("/") == -1 ) addOnloadHook(userlogs);
$(addtoolboxlinks);
if ( wgAction == "view" || wgAction == "purge" || wgAction == "edit" ) addOnloadHook(edittop);