MediaWiki:Common.js

From Mepdata
Revision as of 02:03, 26 August 2024 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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. */

/**
 * 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') } );