MediaWiki:Common.js
Jump to navigation
Jump to search
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.
/* Any JavaScript here will be loaded for all users on every page load. */
//<tabber> extension req
//v2.0, 2017, user:fngplg.
//set active tab: https://jojowiki.com/page#activeTab
(function ($){
var nstarget = window.location.hash.replace('#', '');
if (nstarget === '') return;
//convert wiki-utf 2 ansi
nstarget = nstarget.replace(/\./g, '%');
nstarget = decodeURIComponent(nstarget).replace(/_/g, ' ');
//console.log('trgt:'+nstarget);
$(function(){
setTimeout(function() {
var $nt2a = $('.tabberlive>.tabbernav>li>a[title="' + nstarget + '"]');
$nt2a.click();
$nt2a.get(0).scrollIntoView({inline: "nearest"});
}, 100);//settimeout
});//doc.rdy
})(jQuery);
window.hotcat_use_category_links = false;
/**
* @source https://www.mediawiki.org/wiki/Snippets/Open_specific_links_in_new_window
* @version 2018-09-15
*/
$( function () {
$( '#mw-content-text' ).on( 'click', '.newwin > a', function () {
var otherWindow = window.open();
otherWindow.opener = null;
otherWindow.location = this;
return false;
} );
} );
mw.loader.using( ['mediawiki.util'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' ),
extraModule = mw.util.getParamValue( 'withModule' );
if ( extraCSS ) {
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( 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 ) {
// WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
if ( extraModule ) {
if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
mw.loader.load( extraModule );
} else {
mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
}
}
});
// Creates action=raw links for JS or CSS gadgets
// Useful for mw.loader.load, which doesn't accept page titles
function rawPageLink( pageName ) {
return mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?title=' + mw.util.wikiUrlencode(pageName) + '&action=raw&ctype=text/javascript';
}
// Overwriting deprecated functions that don't have an exact followup but can be easily mapped:
window.importScript = function ( page ) {
if ( typeof page === 'string' && page.length ) {
mw.loader.load( rawPageLink( page ) );
}
};