Changed the way that ResourceLoaderFileModule and mediaWiki.loader work in debug...
authorTrevor Parscal <tparscal@users.mediawiki.org>
Thu, 21 Oct 2010 01:03:46 +0000 (01:03 +0000)
committerTrevor Parscal <tparscal@users.mediawiki.org>
Thu, 21 Oct 2010 01:03:46 +0000 (01:03 +0000)
includes/resourceloader/ResourceLoaderFileModule.php
resources/Resources.php
resources/mediawiki/mediawiki.js

index 7108369..4439124 100644 (file)
@@ -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 .= "<script type=\"text/javascript\" src=\"$wgScriptPath/$file\"></script>";
+                               }
+                               return "\n\tdocument.write( " . FormatJson::encode( $tags ) . ' );';
+                       }
                }
-               return $script;
+               return self::readScriptFiles( $files );
        }
 
        /**
index 1ca2c40..947815f 100644 (file)
@@ -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',
index 9719122..69e00ce 100644 (file)
@@ -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,