You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

Performance/Runbook/Module source: Difference between revisions

From Wikitech-static
Jump to navigation Jump to search
imported>Krinkle
mNo edit summary
imported>Quiddity
m (fixes)
 
Line 1: Line 1:
This snippet shows how to '''get the source code of a module''' from a web browser, for a module registered on that page.
This snippet shows how to '''get the source code of a module''' from a web browser, for a module registered on that page.


<source lang="javascript">
<syntaxhighlight lang="javascript">
mw.loader._getSource = function ( module ) {
mw.loader._getSource = function ( module ) {
if ( !mw.loader.getState( module ) ) {
if ( !mw.loader.getState( module ) ) {
Line 20: Line 20:
} );
} );
};
};
</source>
</syntaxhighlight>


== External links ==
== External links ==

Latest revision as of 18:59, 4 September 2021

This snippet shows how to get the source code of a module from a web browser, for a module registered on that page.

mw.loader._getSource = function ( module ) {
	if ( !mw.loader.getState( module ) ) {
		console.warn( 'Unknown module: ' + module );
		return false;
	}
	var path = mw.util.wikiScript('load') + '?' + $.param({
		debug: true,
		only: 'scripts',
		modules: module,
		lang: mw.config.get('wgUserLanguage'),
		skin: mw.config.get('skin'),
		raw: 1
	});
	console.log( new URL( path, location ).href );
	$.ajax( { url: path, dataType: 'text' } ).then( function ( data ) {
		console.log( data );
	} );
};

External links