MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
/* | /*global mw, JSconfig, importScript */ | ||
if (wgNamespaceNumber != -1) | /*jshint forin:false, strict:false, onecase:true, laxbreak:true, browser:true, jquery:true */ | ||
mw.loader.using(['mediawiki.util']).then(function () { | |||
/* Begin of mw.loader.using callback */ | |||
// Overwriting deprecated functions that have a follower that (also) accepts the same syntax: | |||
window.getParamValue = mw.util.getParamValue; | |||
/** | |||
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL | |||
* @revision 2017-05-16 | |||
*/ | |||
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' } ); | |||
} | |||
} | |||
}); | |||
/** | |||
* ImageAnnotator | |||
* Globally enabled per | |||
* http://commons.wikimedia.org/?title=Commons:Village_pump&oldid=26818359#New_interface_feature | |||
* Maintainer: [[User:Lupo]] | |||
*/ | |||
// Not on Special pages, and only if viewing the page | |||
if (mw.config.get( 'wgNamespaceNumber' ) !== -1 && ['view', 'submit'].indexOf(mw.config.get('wgAction') ) !== -1 ) { | |||
if (typeof ImageAnnotator_disable === 'undefined' || !ImageAnnotator_disable) { | |||
// Don't even import it if it's disabled. | |||
mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-ImageAnnotator.js&action=raw&ctype=text/javascript' ); // Backlink: [[MediaWiki:Gadget-ImageAnnotator.js]] | |||
} | |||
} | |||
/* End of mw.loader.using callback */ | |||
}); |
Revision as of 18:22, 6 January 2023
/*global mw, JSconfig, importScript */ /*jshint forin:false, strict:false, onecase:true, laxbreak:true, browser:true, jquery:true */ mw.loader.using(['mediawiki.util']).then(function () { /* Begin of mw.loader.using callback */ // Overwriting deprecated functions that have a follower that (also) accepts the same syntax: window.getParamValue = mw.util.getParamValue; /** * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL * @revision 2017-05-16 */ 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' } ); } } }); /** * ImageAnnotator * Globally enabled per * http://commons.wikimedia.org/?title=Commons:Village_pump&oldid=26818359#New_interface_feature * Maintainer: [[User:Lupo]] */ // Not on Special pages, and only if viewing the page if (mw.config.get( 'wgNamespaceNumber' ) !== -1 && ['view', 'submit'].indexOf(mw.config.get('wgAction') ) !== -1 ) { if (typeof ImageAnnotator_disable === 'undefined' || !ImageAnnotator_disable) { // Don't even import it if it's disabled. mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-ImageAnnotator.js&action=raw&ctype=text/javascript' ); // Backlink: [[MediaWiki:Gadget-ImageAnnotator.js]] } } /* End of mw.loader.using callback */ });