MediaWiki:Common.js

// // Variables // var action            = mw.config.get("wgAction"), pageName          = mw.config.get("wgPageName"), server            = mw.config.get("wgServer"), groups            = mw.config.get("wgUserGroups"), canonicalNamespace = mw.config.get("wgCanonicalNamespace"); // Any JavaScript here will be loaded for all users on every page load. mw.loader.load( '/index.php?title=MediaWiki:Tabs.js&action=raw&ctype=text/javascript' ); mw.loader.load( '/index.php?title=MediaWiki:Toggle.js&action=raw&ctype=text/javascript' ); mw.loader.load( '/index.php?title=MediaWiki:Scrollbar.js&action=raw&ctype=text/javascript' ); mw.loader.load( '/index.php?title=MediaWiki:Fonts.js&action=raw&ctype=text/javascript' );

// // Rights // Sets a variable "rights" which will return "false" if the // currently logged in user is a bureaucrat, administrator, or autoconfirmed user. It will return true otherwise. // it also defines variables which may be used elsewhere in scripts. //

if (groups){ groupsString = groups.toString; var rights_isAuto   = (groupsString.indexOf('autoconfirmed') != -1); var rights_isAdmin  = (groupsString.indexOf('sysop')         != -1); var rights_isCrat   = (groupsString.indexOf('bureaucrat')    != -1); var rights_isRetired = (groupsString.indexOf('retired')      != -1); var rights = true; } else { var rights = false; }

// // Special:MovePage // Uncheck "Leave a redirect behind" if moving a file // $(function {	var isMovingFile = pageName.startsWith("Special:MovePage/File");	if(isMovingFile) {		var leaveRedirectCheckbox = $("input[name=wpLeaveRedirect]")[0];		leaveRedirectCheckbox.checked = false;	} });

// // Special:ExpandTemplates // Check "Suppress tags in result" when using ExpandTemplates // $(function {	if (pageName == "Special:ExpandTemplates") {		document.getElementById( 'removenowiki' ).checked = true;	} });

// // ForcePreviewLite // A modified version of http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Force_edit_summary_alternative // NOTE: This is not a completed script, only a test of possible options for future addition. Implementation of this script would be done by combining the code of "function forceSummary" into "function forcePreview" at http://www.mediawiki.org/wiki/Manual:Force_preview //

function addForceSummary { if(!/&action=edit/.test(window.location.href) && !/&action=submit/.test(window.location.href)) return; if(/&section=new/.test(window.location.href)) return; if(!document.forms.editform) return; document.forms.editform.wpSave.onclick = forceSummary; } function forceSummary { flashcolour(7); document.forms.editform.wpSave.onclick = ""; return false; } var flashcolour_timer; function flashcolour(count) { if (count%2 == 1) document.getElementById("wpPreview").style.backgroundColor = "silver"; else document.getElementById("wpPreview").style.backgroundColor = "yellow"; if (flashcolour_timer !== null) { clearTimeout(flashcolour_timer); flashcolour_timer = null; }	if (count > 0) flashcolour_timer = window.setTimeout("flashcolour(" + (count-1) + ")",350); } if (action != "submit" && rights === false) { $(document).ready(addForceSummary); }

// -- // Preview button for Special:Upload // -- if (pageName == 'Special:Upload') { mw.loader.load( '/index.php?title=MediaWiki:UploadPreview.js&action=raw&ctype=text/javascript' ); }

// -- // Force lowercase file extensions // -- function force_lowercase { $('#mw-upload-form').on('submit', function{		var dest = $('#wpDestFile').val,		   ext = dest.split("").reverse.join("").split('.');		ext = ext[0].split("").reverse.join("").toLowerCase;		$('#wpDestFile').val(dest.slice(0, -3) + ext);	}); } $( force_lowercase );

// -- // CrazyEgg Tracking // -- setTimeout(function{	var a=document.createElement("script"),	   b=document.getElementsByTagName("script")[0];	a.src=document.location.protocol+"//script.crazyegg.com/pages/scripts/0011/8371.js?"+Math.floor(new Date.getTime/3600000);	a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);

// -- // Temporary upload-related things // --

//Add the html5 'required' attribute to the Source field on Special:Upload if (pageName === "Special:Upload") { $(function {		$("#mw-input-source").prop('required',true);		$("label[for=mw-input-source]").html('Source ('+''+'help'+''+')');	}); }

// -- // Restyle the Purge tab from the current "Refresh" // --

$(document).ready(function{	$("#ca-purge a").attr("title","Purge the server cache of this page [alt-shift-0]").attr("accesskey","0").text("Purge");	});