From: Trevor Parscal Date: Thu, 21 Oct 2010 01:03:46 +0000 (+0000) Subject: Changed the way that ResourceLoaderFileModule and mediaWiki.loader work in debug... X-Git-Tag: 1.31.0-rc.0~34392 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22upgrade%22%2C%22reinstall=non%22%29%20.%20%22?a=commitdiff_plain;h=1f0e5781304687f5db0cd69f96711738a60c0ea5;p=lhc%2Fweb%2Fwiklou.git Changed the way that ResourceLoaderFileModule and mediaWiki.loader work in debug mode. As of this commit, in debug mode, ResourceLoaderFileModule will emit code which appends a a script tag for each raw JavaScript file in the module, instead of the concatenated code of the module's scripts. This eliminates the need to disable batch loading on the client in debug mode, since it effectively supersedes the effect of turning batch loading off. --- diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 71083694fe..4439124323 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -79,6 +79,8 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * @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], ... ) @@ -147,7 +149,11 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { break; // Single strings case 'group': - $this->group = (string) $option; + $this->{$member} = (string) $option; + break; + // Single booleans + case 'debugRaw': + $this->{$member} = (bool) $option; break; } } @@ -160,13 +166,24 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * @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 .= ""; + } + return "\n\tdocument.write( " . FormatJson::encode( $tags ) . ' );'; + } } - return $script; + return self::readScriptFiles( $files ); } /** diff --git a/resources/Resources.php b/resources/Resources.php index 1ca2c40def..947815f2dc 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -25,7 +25,7 @@ return array( /* jQuery */ - 'jquery' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery/jquery.js' ) ), + 'jquery' => new ResourceLoaderFileModule( array( 'scripts' => 'resources/jquery/jquery.js', 'debugRaw' => false ) ), /* jQuery Plugins */ @@ -314,6 +314,7 @@ return array( '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', diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 97191220c8..69e00ce849 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -495,34 +495,26 @@ window.mediaWiki = new ( function( $ ) { }; // 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,