MediaWiki:Common.js
From Bahaipedia
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
* loaded for all users on every wiki page. If possible create a gadget that is
* enabled by default instead of adding it here (since gadgets are fully
* optimized ResourceLoader modules with possibility to add dependencies etc.)
*
* Since Common.js isn't a gadget, there is no place to declare its
* dependencies, so we have to lazy load them with mw.loader.using on demand and
* then execute the rest in the callback. In most cases these dependencies will
* be loaded (or loading) already and the callback will not be delayed. In case a
* dependency hasn't arrived yet it'll make sure those are loaded before this.
*/
/* global mw, $ */
/* jshint strict:false, browser:true */
mw.loader.using( [ 'mediawiki.util' ] ).done( function () {
/* Begin of mw.loader.using callback */
/**
* Map addPortletLink to mw.util
* @deprecated: Use mw.util.addPortletLink instead.
*/
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink, 'Use mw.util.addPortletLink instead' );
/**
* Test if an element has a certain class
* @deprecated: Use $(element).hasClass() instead.
*/
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
return $( element ).hasClass( className );
}, 'Use jQuery.hasClass() instead' );
/**
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @rev 6
*/
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
mw.loader.load( '/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
/**
* Helper script for .hlist class in Common.css
* Add pseudo-selector class to last-child list items in IE8
* @source mediawiki.org/wiki/Snippets/Horizontal_lists
* @revision 6 (2014-08-23)
* @author [[User:Edokter]]
*/
( function ( mw, $ ) {
var profile = $.client.profile();
if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
$content.find( '.hlist' ).find( 'dd:last-child, dt:last-child, li:last-child' )
.addClass( 'hlist-last-child' );
} );
}
}( mediaWiki, jQuery ) );
/**
* Hide category container when no categoies can exist (special pages) ***************************
*
*/
var catlinksElement = document.querySelector('.catlinks-allhidden');
var navElement = document.querySelector('nav.p-navbar.not-collapsible.small.mb-2');
var sidebartransElement = document.querySelector('.sidebar-item.sidebar-menu-translations.col');
var langElement = document.querySelector('.interlanguage-link');
if (catlinksElement && navElement) {
navElement.parentNode.removeChild(navElement);
}
if (langElement) {
sidebartransElement.style.display = 'block';
}
/* All JavaScript here will be loaded for users of the Vector skin */
/**
* ImageAnnotator
* Globally enabled per
* http://commons.wikimedia.org/?title=Commons:Village_pump&oldid=26818359#New_interface_feature
* Maintainer: [[User:Lupo]]
*/
mw.loader.load( '/index.php?title=MediaWiki:Gadget-ImageAnnotator.js&action=raw&ctype=text/javascript' );
/* ADD A URL IN THE FOOTER TO TRAFFIC STATISTICS PAGES */
$(function () {
var allowedNamespaces = [0, 14];
var ns = mw.config.get('wgNamespaceNumber');
if (!allowedNamespaces.includes(ns) || mw.config.get('wgAction') !== 'view') return;
var pageTitle = mw.config.get('wgPageName');
var decodedTitle = pageTitle.replace(/_/g, ' ');
var encodedTitle = encodeURIComponent(decodedTitle).replace(/%20/g, '+');
var statsURL = 'https://digitalbahairesources.org/pageview-analysis?website_id=1&titles=%5B%22' +
encodedTitle + '%22%5D&from_year=2024&from_month=7&to_year=2025&to_month=7';
var $link = $('<a>')
.attr('href', statsURL)
.attr('target', '_blank')
.text('📊 View Traffic Statistics')
.css({ marginLeft: '1em' });
var $container = $('#footer-info > div').first();
if ($container.length) {
$container.append($link);
}
});
/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */