MediaWiki:Common.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// --------------------------------------------------------
// Variables
// --------------------------------------------------------
var action = mw.config.get("wgAction");
var pageName = mw.config.get("wgPageName");
var canonicalNamespace = mw.config.get("wgCanonicalNamespace");
var server = mw.config.get("wgServer");
var groups = mw.config.get("wgUserGroups");
// 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){
var rights_isAuto = (groups.toString().indexOf('autoconfirmed') != -1);
var rights_isAdmin = (groups.toString().indexOf('sysop') != -1);
var rights_isCrat = (groups.toString().indexOf('bureaucrat') != -1);
var rights_isRetired= (groups.toString().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 <nowiki> 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(/§ion=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);
}
// --------------------------------------------------------
// Contains citation templates to be added to the toolbar.
// Source: [http://mediawiki.org/wiki/Manual:Custom_edit_buttons MediaWiki.org]
// Credit to [[User:RAP|RAP]] for the images.
// --------------------------------------------------------
// We begin by getting the date for use in certain citations.
var time = new Date();
var curday = time.getDate();
var month=new Array();
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
var curmonth = month[time.getMonth()];
var nowyear = time.getYear()+1900;
var nowday = curday.toString();
var nowmonth = curmonth.toString();
// Now we make the function itself
var addExtraButtons = function(){
// Start with web cite
mw.toolbar.addButton( {
imageFile: 'https://zeldawiki.org/images/9/91/Button_cite_web.png',
speedTip: 'Web Citation',
tagOpen: "<ref>{{Cite web|quote= |author= |published= |retrieved=" + nowmonth + " " + nowday + ", " + nowyear + "|url= |title= |site= |type=",
tagClose: '}}</ref>',
sampleText: '',
imageId: ''
} );
// Cite book
mw.toolbar.addButton( {
imageFile: 'https://zeldawiki.org/images/e/ef/Button_cite_book.png',
speedTip: 'Cite book',
tagOpen: '<ref>{{Cite book|quote= |book= |publisher= |page= ',
tagClose: '}}</ref>',
sampleText: '',
imageId: ''
} );
// Cite person
mw.toolbar.addButton( {
imageFile: 'https://zeldawiki.org/images/5/53/Button_cite_person.png',
speedTip: 'Cite person',
tagOpen: '<ref>{{Cite person|quote= |name= |url= |title= ',
tagClose: '}}</ref>',
sampleText: '',
imageId: ''
} );
// Cite episode
mw.toolbar.addButton( {
imageFile: 'https://zeldawiki.org/images/1/1c/Button_cite_episode.png',
speedTip: 'Cite episode',
tagOpen: '<ref>{{Cite episode|quote= |name= |show= |episode= |time= ',
tagClose: '}}</ref>',
sampleText: '',
imageId: ''
} );
// Cite manual
mw.toolbar.addButton( {
imageFile: 'https://zeldawiki.org/images/5/5d/Button_cite_manual.png',
speedTip: 'Cite manual',
tagOpen: '<ref>{{Cite manual|quote= |game= |page= ',
tagClose: '}}</ref>',
sampleText: '',
imageId: ''
} );
// Regular cite template
mw.toolbar.addButton( {
imageFile: 'https://zeldawiki.org/images/2/20/Button_cite_template.png',
speedTip: 'Regular citation',
tagOpen: '<ref>{{Cite|(Quote)|(Person)|(Game)',
tagClose: '}}</ref>',
sampleText: '',
imageId: ''
} );
};
if( $.inArray( action, [ 'edit', 'submit' ] ) !== -1 ) {
mw.loader.using( 'user.options', function () {
if ( ! mw.user.options.get( 'usebetatoolbar' ) ) {
mw.loader.using( 'mediawiki.action.edit', function(){
$( addExtraButtons );
} );
}
} );
}
// --------------------------------------------------
// 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();
var 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");
var 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);