MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(Created page with "→Any JavaScript here will be loaded for all users on every page load.: mw.util.addPortletLink ('p-tb', '/wiki/Q5296', 'Mepdata item');") |
No edit summary |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
mw.util. | |||
/** | |||
* Load jquery.ui button if used in content | |||
* for backward-compatibilty | |||
* Should be removed/replaced with mediawiki.ui, when that is loaded on each page | |||
*/ | |||
mw.hook( 'wikipage.content' ).add( function ( $content ) { | |||
if ( $content.find( '.ui-button' ).length ) { | |||
mw.loader.load( 'jquery.ui' ); | |||
} | |||
} ); | |||
/** | |||
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL | |||
* @revision 2020-04-04 | |||
*/ | |||
mw.loader.using( ['mediawiki.util'], function () { | |||
var extraCSS = mw.util.getParamValue( 'withCSS' ), | |||
extraJS = mw.util.getParamValue( 'withJS' ); | |||
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' } ); | |||
} | |||
} | |||
}); | |||
// ScoredRevision configs, see #wikimedia-ai at 28.04.2016 | |||
// XXX: Shouldn't this be set in configuration? | |||
// [[File:User:He7d3r/Tools/ScoredRevisions.js]] (workaround for [[phab:T35355]]) | |||
mw.config.set( 'ScoredRevisionsThresholds', { low: 0.8, medium: 0.9, high: 0.95 } ); | |||
$( '.mw-notification-tag-wikibase-anonymouseditwarning a').each( function() { $( this ).attr('target', '_blank') } ); |
Latest revision as of 02:03, 26 August 2024
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* Load jquery.ui button if used in content
* for backward-compatibilty
* Should be removed/replaced with mediawiki.ui, when that is loaded on each page
*/
mw.hook( 'wikipage.content' ).add( function ( $content ) {
if ( $content.find( '.ui-button' ).length ) {
mw.loader.load( 'jquery.ui' );
}
} );
/**
* @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @revision 2020-04-04
*/
mw.loader.using( ['mediawiki.util'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
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' } );
}
}
});
// ScoredRevision configs, see #wikimedia-ai at 28.04.2016
// XXX: Shouldn't this be set in configuration?
// [[File:User:He7d3r/Tools/ScoredRevisions.js]] (workaround for [[phab:T35355]])
mw.config.set( 'ScoredRevisionsThresholds', { low: 0.8, medium: 0.9, high: 0.95 } );
$( '.mw-notification-tag-wikibase-anonymouseditwarning a').each( function() { $( this ).attr('target', '_blank') } );