* @format array( [message-key], [message-key], ... )
*/
protected $group;
+ /** @var {boolean} Link to raw files in debug mode */
+ protected $debugRaw = true;
/**
* @var {array} Cache for mtime
* @format array( [hash] => [mtime], [hash] => [mtime], ... )
break;
// Single strings
case 'group':
- $this->group = (string) $option;
+ $this->{$member} = (string) $option;
+ break;
+ // Single booleans
+ case 'debugRaw':
+ $this->{$member} = (bool) $option;
break;
}
}
* @return {string} JavaScript code for $context
*/
public function getScript( ResourceLoaderContext $context ) {
- $script = self::readScriptFiles( $this->scripts ) . "\n" .
- self::readScriptFiles( self::tryForKey( $this->languageScripts, $context->getLanguage() ) ) . "\n" .
- self::readScriptFiles( self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' ) ) . "\n";
+ global $wgScriptPath;
+
+ $files = array_merge(
+ $this->scripts,
+ self::tryForKey( $this->languageScripts, $context->getLanguage() ),
+ self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
+ );
if ( $context->getDebug() ) {
- $script .= "\n" . self::readScriptFiles( $this->debugScripts );
+ $files = array_merge( $files, $this->debugScripts );
+ if ( $this->debugRaw ) {
+ $tags = '';
+ foreach ( $files as $file ) {
+ $tags .= "<script type=\"text/javascript\" src=\"$wgScriptPath/$file\"></script>";
+ }
+ return "\n\tdocument.write( " . FormatJson::encode( $tags ) . ' );';
+ }
}
- return $script;
+ return self::readScriptFiles( $files );
}
/**
/* jQuery */
- 'jquery' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery/jquery.js' ) ),
+ 'jquery' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery/jquery.js', 'debugRaw' => false ) ),
/* jQuery Plugins */
'mediawiki' => new ResourceLoaderFileModule( array(
'scripts' => 'resources/mediawiki/mediawiki.js',
'debugScripts' => 'resources/mediawiki/mediawiki.log.js',
+ 'debugRaw' => false
) ),
'mediawiki.specials.preferences' => new ResourceLoaderFileModule( array(
'scripts' => 'resources/mediawiki/mediawiki.specials.preferences.js',
};
// Extend request parameters with a list of modules in the batch
var requests = [];
- if ( base.debug == '1' ) {
- for ( var b = 0; b < batch.length; b++ ) {
- requests[requests.length] = $.extend(
- { 'modules': batch[b], 'version': registry[batch[b]].version }, base
- );
- }
- } else {
- // Split into groups
- var groups = {};
- for ( var b = 0; b < batch.length; b++ ) {
- var group = registry[batch[b]].group;
- if ( !( group in groups ) ) {
- groups[group] = [];
- }
- groups[group][groups[group].length] = batch[b];
+ // Split into groups
+ var groups = {};
+ for ( var b = 0; b < batch.length; b++ ) {
+ var group = registry[batch[b]].group;
+ if ( !( group in groups ) ) {
+ groups[group] = [];
}
- for ( var group in groups ) {
- // Calculate the highest timestamp
- var version = 0;
- for ( var g = 0; g < groups[group].length; g++ ) {
- if ( registry[groups[group][g]].version > version ) {
- version = registry[groups[group][g]].version;
- }
+ groups[group][groups[group].length] = batch[b];
+ }
+ for ( var group in groups ) {
+ // Calculate the highest timestamp
+ var version = 0;
+ for ( var g = 0; g < groups[group].length; g++ ) {
+ if ( registry[groups[group][g]].version > version ) {
+ version = registry[groups[group][g]].version;
}
- requests[requests.length] = $.extend(
- { 'modules': groups[group].join( '|' ), 'version': formatVersionNumber( version ) }, base
- );
}
+ requests[requests.length] = $.extend(
+ { 'modules': groups[group].join( '|' ), 'version': formatVersionNumber( version ) }, base
+ );
}
// Clear the batch - this MUST happen before we append the script element to the body or it's
// possible that the script will be locally cached, instantly load, and work the batch again,