Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Mobile.js: Difference between revisions

MediaWiki interface page
Content deleted Content added
ChaoticShadow (talk | contribs)
mNo edit summary
ChaoticShadow (talk | contribs)
mNo edit summary
Line 1: Line 1:
/* All JavaScript here will be loaded for users of the mobile site */
/* All JavaScript here will be loaded for users of the mobile site */
mw.loader.using('mobile.site.styles', function () {
mw.loader.using('mobile.site.styles',
function () {
console.log('Styles loaded');
console.log('Styles loaded');
});
},
function () {
console.log('Error');
}
);
mw.loader.load( '/w/index.php?title=MediaWiki:Countdown.js&action=raw&ctype=text/javascript' );
mw.loader.load( '/w/index.php?title=MediaWiki:Countdown.js&action=raw&ctype=text/javascript' );



Revision as of 17:00, 2 November 2021

/* All JavaScript here will be loaded for users of the mobile site */
mw.loader.using('mobile.site.styles',
	function () {
		console.log('Styles loaded');
	},
	function () {
		console.log('Error');
	}
);
mw.loader.load( '/w/index.php?title=MediaWiki:Countdown.js&action=raw&ctype=text/javascript' );

/**
 * @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' } );
		}
	}
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.