Jump to content

User:Monchoman45/toolbar.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
/* toolbar.js, with lots of tools and stuff on it. */
/* originally designed for use on Wikia (wikifarm), hence the sysop and bureaucrat tools */

function ToolbarInit() {
	CSS('#semanticToolbar {display:inline-block; float:right; line-height:15px; font-size:12px; margin-top:1px;} #semanticToolbar ul {list-style:none; display:inline;} #semanticToolbar ul li {display:inline;} .stb-button a {font-size:12px; padding:2px 6px 2px 6px; color:#0645AD; background-color:#a7d7f9; background-image:-moz-linear-gradient(top, #fff 15%, #a7d7f9 95%); background-image:-webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(15%, #fff), color-stop(85%, #a7d7f9)); border:1px solid #a7d7f9; border-left:0;} .stb-button a:hover, .stb-button-selected a:hover {text-decoration:none; color:#000 !important; border:1px solid #f2e85e !important; border-left:0 !important; background-color:#f2e85e !important; background-image:-moz-linear-gradient(top, #fff 95%, #f2e85e 15%) !important; background-image:-webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(15%, #fff), color-stop(95%, #f2e85e)) !important;} .stb-button:first-child a {border-left:1px solid #a7d7f9; border-top-left-radius:1ex; border-bottom-left-radius:1ex; -moz-border-radius-bottomleft:1ex; -moz-border-radius-topleft:1ex;} .stb-button:first-child a:hover, .stb-button-selected:first-child a:hover {border-left:1px solid #f2e85e !important;} .stb-button:last-child a, .stb-button-selected:last-child a, .stb-button-unusable:last-child span {border-top-right-radius:1ex; border-bottom-right-radius:1ex; -moz-border-radius-bottomright:1ex; -moz-border-radius-topright:1ex;} .stb-button-selected a { font-size:12px; text-decoration:none; color:#000; padding:2px 6px 2px 6px; border:1px solid #f2e85e; border-left:0; background-color:#f2e85e; background-image:-moz-linear-gradient(top, #fff 95%, #f2e85e 15%); background-image:-webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(15%, #fff), color-stop(95%, #f2e85e));} .stb-button-selected:first-child a {border-left:1px solid #f2e85e; border-top-left-radius:1ex; border-bottom-left-radius:1ex; -moz-border-radius-bottomleft:1ex; -moz-border-radius-topleft:1ex;} .stb-button-unusable span {font-size:12px; cursor:default; color:#ccc; padding:2px 6px 2px 6px; background-color:#eee; background-image:-moz-linear-gradient(top, #fff 15%, #eee 85%); background-image:-webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(15%, #fff), color-stop(95%, #eee)); border:1px solid #d3d3d3; border-left:0;} .stb-button-unusable span:hover {text-decoration:none;} .stb-button-unusable:first-child span {border-left:1px solid #d3d3d3; border-top-left-radius:1ex; border-bottom-left-radius:1ex; -moz-border-radius-bottomleft:1ex; -moz-border-radius-topleft:1ex;}');

	var oldid = (urlQuery('oldid') != false) ? '&oldid=' + urlQuery('oldid') : '';
	try {wgRestrictionEdit} catch(err) {wgRestrictionEdit = false;}
	try {wgRestrictionCreate} catch(err) {wgRestrictionCreate = false;}
	try {wgRestrictionMove} catch(err) {wgRestrictionMove = false;}

	//Get user rights
	var autoconfirmed = false;
	var admin = false;
	var bureaucrat = false;
	for(i in wgUserGroups) {
		if(wgUserGroups[i] == 'autoconfirmed') {
			autoconfirmed = true;
		}
		if(wgUserGroups[i] == 'sysop') {
			admin = true;
		}
		if(wgUserGroups[i] == 'bureaucrat') {
			bureaucrat = true;
		}
	}

	switch(wgPageName) {
		case 'Special:Contributions':
		case 'Special:DeletedContributions':
			window.wgSemanticPageName = 'User:' + $('input[name="target"]').attr('value');
			window.wgSemanticNamespace = 'User';
			window.wgSemanticTitle = $('input[name="target"]').attr('value');
			window.wgSemanticUser = window.wgSemanticTitle;
			break;
		case 'Special:Block':
			window.wgSemanticPageName = 'User:' + $('input[name="wpBlockAddress"]').attr('value');
			window.wgSemanticNamespace = 'User';
			window.wgSemanticTitle = $('input[name="wpBlockAddress"]').attr('value');
			window.wgSemanticUser = window.wgSemanticTitle;
			break;
		case 'Special:UserRights':
			window.wgSemanticPageName = 'User:' + document.getElementById('username').value;
			window.wgSemanticNamespace = 'User';
			window.wgSemanticTitle = document.getElementById('username').value;
			window.wgSemanticUser = window.wgSemanticTitle;
			break;
		case 'Special:MovePage':
			window.wgSemanticPageName = document.getElementById('wpNewTitle').value;
			if(wgCanonicalNamespace != '') {window.wgSemanticNamespace = window.wgSemanticPageName.split(':')[0]; window.wgSemanticTitle = window.wgSemanticPageName.split(':')[1];}
			else {window.wgSemanticNamespace = ''; window.wgSemanticTitle = window.wgSemanticPageName;}
			window.wgSemanticUser = window.wgTitle;
			break;
		case 'Special:Undelete':
			window.wgSemanticPageName = $('.mw-undelete-pagetitle b a').html();
			if(wgCanonicalNamespace != '') {window.wgSemanticNamespace = window.wgSemanticPageName.split(':')[0]; window.wgSemanticTitle = window.wgSemanticPageName.split(':')[1];}
			else {window.wgSemanticNamespace = ''; window.wgSemanticTitle = window.wgSemanticPageName;}
			window.wgSemanticUser = window.wgTitle;
			break;
		case 'Special:WhatLinksHere':
			window.wgSemanticPageName = document.getElementById('mw-whatlinkshere-target').value;
			if(wgCanonicalNamespace != '') {window.wgSemanticNamespace = window.wgSemanticPageName.split(':')[0]; window.wgSemanticTitle = window.wgSemanticPageName.split(':')[1];}
			else {window.wgSemanticNamespace = ''; window.wgSemanticTitle = window.wgSemanticPageName;}
			window.wgSemanticUser = window.wgTitle;
			break;
		case 'Special:PrefixIndex':
			window.wgSemanticNamespace = document.getElementById('namespace')[document.getElementById('namespace').selectedIndex].innerHTML;
			window.wgSemanticPageName = window.wgSemanticNamespace + ':' + document.getElementById('nsfrom').value;
			window.wgSemanticTitle = document.getElementById('nsfrom').value;
			window.wgSemanticUser = window.wgTitle;
			break;
		case 'Special:Log':
		case 'Special:ListUsers':
			if($('input[name="username"]').length > 0 || $('input[name="user"]').length > 0) {
				window.wgSemanticPageName = 'User:' + $('input[name="user' + ((wgPageName == 'Special:ListUsers') ? 'name' : '') + '"]').attr('value');
				window.wgSemanticNamespace = 'User';
				window.wgSemanticTitle = $('input[name="user' + ((wgPageName == 'Special:ListUsers') ? 'name' : '') + '"]').attr('value');
				window.wgSemanticUser = window.wgSemanticTitle;
				break;
			}
		default:
			window.wgSemanticUser = window.wgTitle;
			if(wgCanonicalNamespace != '') {
				window.wgSemanticPageName = wgFormattedNamespaces[wgNamespaceNumber] + ':' + wgTitle;
				window.wgSemanticNamespace = wgFormattedNamespaces[wgNamespaceNumber];
				window.wgSemanticTitle = wgTitle;
			}
			else {
				window.wgSemanticPageName = wgTitle;
				window.wgSemanticNamespace = '';
				window.wgSemanticTitle = wgTitle;
			}
			break;
	}
	if(wgCanonicalNamespace == 'User' || wgCanonicalNamespace == 'User_talk') {wgSemanticUser = wgSemanticUser.split('/')[0];}

	$('#bodyContent').prepend('<div id="semanticToolbar"><ul id="stb-databuttons"><li class="stb-button" id="wlhbutton"><a href="/wiki/Special:WhatLinksHere/' + wgSemanticPageName + '" title="Special:WhatLinksHere/' + wgSemanticPageName + '">WLH</a></li><li class="stb-button" id="prefixbutton"><a href="/wiki/Special:PrefixIndex/' + wgSemanticPageName + '" title="Special:PrefixIndex/' + wgSemanticPageName + '">Index</a></li><li class="stb-button" id="logbutton"><a href="/w/index.php?title=Special:Log&page=' + wgSemanticPageName + '" title="Special:Log/' + wgSemanticPageName + '">Log</a></li></ul><ul id="stb-actionbuttons"><li class="stb-button" id="viewbutton"><a href="/w/index.php?title=' + wgSemanticPageName + '" title="' + wgSemanticPageName + '">View</a></li><li class="stb-button" id="editbutton"><a href="/w/index.php?title=' + wgSemanticPageName + '&action=edit' + oldid + '" title="' + wgSemanticPageName + '&action=edit">Edit</a></li><li class="stb-button" id="histbutton"><a href="/w/index.php?title=' + wgSemanticPageName + '&action=history" title="' + wgSemanticPageName + '&action=history">History</a></li><li class="stb-button" id="movebutton" title="Special:MovePage/' + wgSemanticPageName + '"><a href="/wiki/Special:MovePage/' + wgSemanticPageName + '">Move</a></li><li class="stb-button" id="protbutton"><a href="/w/index.php?title=' + wgSemanticPageName + '&action=protect" title="' + wgSemanticPageName + '&action=protect">Protect</a></li><li class="stb-button" id="delbutton"><a href="/w/index.php?title=' + wgSemanticPageName + '&action=delete" title="' + wgSemanticPageName + '&action=delete">Delete</a></li></ul></div>');
	if(wgPageName == 'Special:Contributions' || (wgPageName == 'Special:ListUsers' && $('input[name="username"]').length > 0) || (wgPageName == 'Special:Log' && $('input[name="user"]').length > 0) || wgPageName == 'Special:DeletedContributions' || wgPageName == 'Special:Block' || wgPageName == 'Special:UserRights' || wgPageName == 'Special:CreateBlogPage' || wgCanonicalNamespace == 'User' || wgCanonicalNamespace == 'User_talk') {
		$('#semanticToolbar').prepend('<ul id="stb-userbuttons"><li class="stb-button" id="contribsbutton"><a href="/wiki/Special:Contributions/' + wgSemanticUser + '" title="Special:Contributions/' + wgSemanticUser + '">Contribs</a></li><li class="stb-button" id="listbutton"><a href="/w/index.php?title=Special:ListUsers&limit=1&username=' + wgSemanticUser + '" title="Special:ListUsers/' + wgSemanticUser + '">List</a></li><li class="stb-button" id="delcontribsbutton"><a href="/wiki/Special:DeletedContributions/' + wgSemanticUser + '" title="Special:DeletedContributions/' + wgSemanticUser + '">Del Contribs</a></li><li class="stb-button" id="blockbutton"><a href="/wiki/Special:Block/' + wgSemanticUser + '" title="Special:Block/' + wgSemanticUser + '">Block</a></li><li class="stb-button" id="rightsbutton"><a href="/wiki/Special:UserRights/' + wgSemanticUser + '" title="Special:UserRights/' + wgSemanticUser + '">Rights</a></li></ul>');
	}

	//Stuff for wgAction
	switch(wgAction) {
		case 'purge': //If you purged the page, you're viewing it
		case 'view':
			document.getElementById('viewbutton').className = 'stb-button-selected';
			break;
		case 'edit':
		case 'submit': //They're pretty much the same thing
			document.getElementById('editbutton').className = 'stb-button-selected';
			break;
		case 'history':
			document.getElementById('histbutton').className = 'stb-button-selected';
			break;
		case 'protect':
			document.getElementById('protbutton').className = 'stb-button-selected';
			break;
		case 'delete':
			document.getElementById('delbutton').className = 'stb-button-selected';
			break;
	}
	//Stuff for wgPageName
	switch(wgPageName) {
		case 'Special:Contributions':
			document.getElementById('contribsbutton').className = 'stb-button-selected';
			break;
		case 'Special:ListUsers':
			document.getElementById('listbutton').className = 'stb-button-selected';
			break;
		case 'Special:DeletedContributions':
			document.getElementById('delcontribsbutton').className = 'stb-button-selected';
			break;
		case 'Special:Block':
			document.getElementById('blockbutton').className = 'stb-button-selected';
			break;
		case 'Special:UserRights':
			document.getElementById('rightsbutton').className = 'stb-button-selected';
			break;
		case 'Special:MovePage':
			document.getElementById('movebutton').className = 'stb-button-selected';
			document.getElementById('viewbutton').className = 'stb-button';
			break;
		case 'Special:Undelete':
			document.getElementById('delbutton').className = 'stb-button-selected';
			document.getElementById('viewbutton').className = 'stb-button';
			break;
		case 'Special:WhatLinksHere':
			document.getElementById('wlhbutton').className = 'stb-button-selected';
			break;
		case 'Special:PrefixIndex':
			document.getElementById('prefixbutton').className = 'stb-button-selected';
			break;
		case 'Special:Log':
			document.getElementById('logbutton').className = 'stb-button-selected';
			break;
	}

	//Turn off page actions on non-semantic special pages
	if(wgCanonicalNamespace == 'Special' && wgPageName != 'Special:MovePage' && wgPageName != 'Special:WhatLinksHere' && wgPageName != 'Special:PrefixIndex' && wgPageName != 'Special:Undelete') {
		document.getElementById('viewbutton').className = 'stb-button-selected';
		document.getElementById('editbutton').className = 'stb-button-unusable';
		document.getElementById('editbutton').innerHTML = '<span>Edit</span>';
		document.getElementById('editbutton').childNodes[0].title = 'Special pages can\'t be edited';
		document.getElementById('histbutton').className = 'stb-button-unusable';
		document.getElementById('histbutton').innerHTML = '<span>History</span>';
		document.getElementById('histbutton').childNodes[0].title = 'Special pages don\'t have history';
		document.getElementById('movebutton').className = 'stb-button-unusable';
		document.getElementById('movebutton').innerHTML = '<span>Move</span>';
		document.getElementById('movebutton').childNodes[0].title = 'Special pages can\'t be moved';
		document.getElementById('protbutton').className = 'stb-button-unusable';
		document.getElementById('protbutton').innerHTML = '<span>Protect</span>';
		document.getElementById('protbutton').childNodes[0].title = 'Special pages can\'t be protected';
		document.getElementById('delbutton').className = 'stb-button-unusable';
		document.getElementById('delbutton').innerHTML = '<span>Delete</span>';
		document.getElementById('delbutton').childNodes[0].title = 'Special pages can\'t be deleted';
		document.getElementById('wlhbutton').className = 'stb-button-unusable';
		document.getElementById('wlhbutton').innerHTML = '<span>WLH</span>';
		document.getElementById('wlhbutton').childNodes[0].title = 'Can\'t view what links to special pages';
		document.getElementById('prefixbutton').className = 'stb-button-unusable';
		document.getElementById('prefixbutton').innerHTML = '<span>Index</span>';
		document.getElementById('prefixbutton').childNodes[0].title = 'Can\'t view index for special pages';
		document.getElementById('logbutton').className = 'stb-button-unusable';
		document.getElementById('logbutton').innerHTML = '<span>Log</span>';
		document.getElementById('logbutton').childNodes[0].title = 'Can\'t view log for special pages';
	}
	//Turn off protect for MediaWiki pages, and move for categories
	if(wgCanonicalNamespace == 'MediaWiki' || wgSemanticNamespace == 'MediaWiki') {
		document.getElementById('protbutton').className = 'stb-button-unusable';
		document.getElementById('protbutton').innerHTML = '<span>Protect</span>';
		document.getElementById('protbutton').childNodes[0].title = 'MediaWiki pages can\'t be protected';
	}
	if(wgCanonicalNamespace == 'Category' || wgSemanticNamespace == 'Category') {
		document.getElementById('movebutton').className = 'stb-button-unusable';
		document.getElementById('movebutton').innerHTML = '<span>Move</span>';
		document.getElementById('movebutton').childNodes[0].title = 'Categories can\'t be moved';
	}
	//Remove functions that don't work on pages that don't exist
	if($('.noarticletext').length > 0) {
		document.getElementById('histbutton').className = 'stb-button-unusable';
		document.getElementById('histbutton').innerHTML = '<span>History</span>';
		document.getElementById('histbutton').childNodes[0].title = 'Non-existent pages have no history';
		document.getElementById('movebutton').className = 'stb-button-unusable';
		document.getElementById('movebutton').innerHTML = '<span>Move</span>';
		document.getElementById('movebutton').childNodes[0].title = 'Non-existent pages can\'t be moved';
		document.getElementById('delbutton').childNodes[0].innerHTML = 'Undelete';
		document.getElementById('delbutton').childNodes[0].href = '/wiki/Special:Undelete/' + wgSemanticPageName;
		document.getElementById('delbutton').childNodes[0].title = 'Special:Undelete/' + wgSemanticPageName;
	}

	//Turn off edit and move on semiprotected pages for non-autoconfirmed users
	if(autoconfirmed == false) {
		if(wgRestrictionEdit && wgRestrictionEdit[0] == 'autoconfirmed') {
			document.getElementById('editbutton').childNodes[0].innerHTML = 'Source';
			document.getElementById('editbutton').childNodes[0].title = 'Page is edit protected (autoconfirmed)';
		}
		else if(wgRestrictionCreate || wgRestrictionCreate[0] == 'autoconfirmed') {
			document.getElementById('editbutton').childNodes[0].innerHTML = 'Source';
			document.getElementById('editbutton').childNodes[0].title = 'Page is edit protected (autoconfirmed)';
		}
		if(wgRestrictionMove && wgRestrictionMove[0] == 'autoconfirmed') {
			document.getElementById('movebutton').className = 'stb-button-unusable';
			document.getElementById('movebutton').innerHTML = '<span>Move</span>';
			document.getElementById('movebutton').childNodes[0].title = 'Page is move protected (autoconfirmed)';
		}
	}
	//Turn off sysop tools and edit on sysop protected pages for users with no admin privilages
	if(admin == false && bureaucrat == false) {
		document.getElementById('protbutton').className = 'stb-button-unusable';
		document.getElementById('protbutton').innerHTML = '<span>Protect</span>';
		document.getElementById('protbutton').childNodes[0].title = 'Need admin rights to protect pages';
		document.getElementById('delbutton').className = 'stb-button-unusable';
		document.getElementById('delbutton').innerHTML = '<span>Delete</span>';
		document.getElementById('delbutton').childNodes[0].title = 'Need admin rights to delete pages';
		if(document.getElementById('stb-userbuttons')) {
			document.getElementById('blockbutton').className = 'stb-button-unusable';
			document.getElementById('blockbutton').innerHTML = '<span>Block</span>';
			document.getElementById('blockbutton').childNodes[0].title = 'Need admin rights to block users';
			document.getElementById('delcontribsbutton').className = 'stb-button-unusable';
			document.getElementById('delcontribsbutton').innerHTML = '<span>Del&nbsp;Contribs</span>';
			document.getElementById('delcontribsbutton').childNodes[0].title = 'Need admin rights to view deleted contributions';
		}
		
		if(wgRestrictionEdit && (wgRestrictionEdit[0] == 'sysop' || wgCanonicalNamespace == 'MediaWiki' || wgSemanticNamespace == 'MediaWiki')) {
			document.getElementById('editbutton').childNodes[0].innerHTML = 'Source';
			document.getElementById('editbutton').childNodes[0].title = 'Page is edit protected (sysop)';
		}
		else if(wgRestrictionCreate && wgRestrictionCreate[0] == 'sysop') {
			document.getElementById('editbutton').childNodes[0].innerHTML = 'Source';
			document.getElementById('editbutton').childNodes[0].title = 'Page is edit protected (sysop)';
		}
		if(wgRestrictionMove && (wgRestrictionMove[0] == 'sysop' || wgCanonicalNamespace == 'MediaWiki' || wgSemanticNamespace == 'MediaWiki')) {
			document.getElementById('movebutton').className = 'stb-button-unusable';
			document.getElementById('movebutton').innerHTML = '<span>Move</span>';
			document.getElementById('movebutton').childNodes[0].title = 'Page is move protected (sysop)';
		}
	}
	if(bureaucrat == false && document.getElementById('stb-userbuttons')) {
		document.getElementById('rightsbutton').parentNode.removeChild(document.getElementById('rightsbutton'));
	}
}
$(ToolbarInit);