http://www.mediawiki.org/wiki/Special:Code/MediaWiki/68438

Revision: 68438
Author:   tparscal
Date:     2010-06-23 01:02:13 +0000 (Wed, 23 Jun 2010)

Log Message:
-----------
Fixed some bugs, things actually load now... Hooray for tests!

Modified Paths:
--------------
    branches/resourceloader/phase3/includes/ResourceLoader.php
    branches/resourceloader/phase3/resources/core/mw.js
    branches/resourceloader/phase3/resources/test/loader.js
    branches/resourceloader/phase3/resources/test/test.js

Added Paths:
-----------
    branches/resourceloader/phase3/resources/test/bar.js
    branches/resourceloader/phase3/resources/test/baz.js
    branches/resourceloader/phase3/resources/test/buz.js
    branches/resourceloader/phase3/resources/test/foo.js

Modified: branches/resourceloader/phase3/includes/ResourceLoader.php
===================================================================
--- branches/resourceloader/phase3/includes/ResourceLoader.php  2010-06-23 
00:46:44 UTC (rev 68437)
+++ branches/resourceloader/phase3/includes/ResourceLoader.php  2010-06-23 
01:02:13 UTC (rev 68438)
@@ -47,6 +47,22 @@
                        'script' => 'resources/test/test.js',
                        'loader' => 'resources/test/loader.js',
                ),
+               'foo' => array(
+                       'script' => 'resources/test/foo.js',
+                       'loader' => 'resources/test/loader.js',
+               ),
+               'bar' => array(
+                       'script' => 'resources/test/bar.js',
+                       'loader' => 'resources/test/loader.js',
+               ),
+               'buz' => array(
+                       'script' => 'resources/test/baz.js',
+                       'loader' => 'resources/test/loader.js',
+               ),
+               'baz' => array(
+                       'script' => 'resources/test/buz.js',
+                       'loader' => 'resources/test/loader.js',
+               ),
                'wikibits' => array(
                        'script' => 'skins/common/wikibits.js',
                        'loader' => 'skins/common/loader.js',
@@ -58,7 +74,7 @@
        private $loadedModules = array();
        private $includeCore = false;
        
-       private $useJSMin = true;
+       private $useJSMin = false;
        private $useCSSMin = true;
        private $useCSSJanus = true;
        
@@ -75,7 +91,7 @@
         */
        public function addModule( $module ) {
                if ( $module == 'core' ) {
-                       $includeCore = true;
+                       $this->includeCore = true;
                } else if ( isset( self::$modules[$module] ) ) {
                        $this->loadedModules[] = $module;
                        $this->scripts[$module] = 
self::$modules[$module]['script'];
@@ -144,10 +160,15 @@
                $this->loadedModules = array_unique( $this->loadedModules );
                $retval = '';
                
-               // TODO: file_get_contents() errors?
-               // TODO: CACHING!
-               foreach ( self::$coreScripts as $script ) {
-                       $retval .= file_get_contents( $script );
+               if ( $this->includeCore ) {
+                       // TODO: file_get_contents() errors?
+                       // TODO: CACHING!
+                       foreach ( self::$coreScripts as $script ) {
+                               if ( file_exists( $script ) ) {
+                                       $retval .= file_get_contents( $script );
+                               }
+                       }
+                       $retval .= $this->getLoaderJS();
                }
                
                /*
@@ -163,7 +184,9 @@
                // TODO: file_get_contents() errors?
                // TODO: CACHING!
                foreach ( $this->scripts as $module => $script ) {
-                       $retval .= "mw.loader.implement( '{$module}', 
function() { " . file_get_contents( $script ) . " } );\n";
+                       if ( file_exists( $script ) ) {
+                               $retval .= "mw.loader.implement( '{$module}', 
function() { " . file_get_contents( $script ) . " } );\n";
+                       }
                }
                $retval .= $this->getStyleJS( $this->styles );
                $retval .= $this->getMessagesJS( $this->loadedModules );
@@ -176,10 +199,15 @@
        
        public function getLoaderJS() {
                $retval = '';
+               // Only add each file once (just in case there are multiple 
modules in a single loader, which is common)
+               $loaders = array();
                foreach ( self::$modules as $name => $module ) {
                        // TODO: file_get_contents() errors?
                        // TODO: CACHING!
-                       $retval .= file_get_contents( $module['loader'] );
+                       if ( !in_array( $module['loader'], $loaders ) && 
file_exists( $module['loader'] ) ) {
+                               $retval .= file_get_contents( $module['loader'] 
);
+                               $loaders[] = $module['loader'];
+                       }
                }
                // FIXME: Duplicated; centralize in doJSTransforms() or 
something?
                if ( $this->useJSMin ) {

Modified: branches/resourceloader/phase3/resources/core/mw.js
===================================================================
--- branches/resourceloader/phase3/resources/core/mw.js 2010-06-23 00:46:44 UTC 
(rev 68437)
+++ branches/resourceloader/phase3/resources/core/mw.js 2010-06-23 01:02:13 UTC 
(rev 68438)
@@ -38,9 +38,9 @@
                                url += components['path'];
                        }
                        if ( typeof components['query'] === 'string' ) {
-                               url += '?' + components['path'];
+                               url += '?' + components['query'];
                        } else if ( typeof components['query'] === 'object' ) {
-                               url += '?' + that.buildQueryString( 
components['path'] );
+                               url += '?' + that.buildQueryString( 
components['query'] );
                        }
                        if ( typeof components['fragment'] === 'string' ) {
                                url += '#' + components['fragment'];
@@ -60,11 +60,14 @@
                                        .replace(/\)/g, '%29')
                                        .replace(/\*/g, '%2A');  
                        }
-                       var parts = [];
-                       for ( p in parameters ) {
-                               parts[parts.length] = encode( key ) + '=' + 
encode( parameters[p] );
+                       if ( typeof parameters === 'object' ) {
+                               var parts = [];
+                               for ( p in parameters ) {
+                                       parts[parts.length] = encode( p ) + '=' 
+ encode( parameters[p] );
+                               }
+                               return parts.join( '&' );
                        }
-                       return parts.join( '&' );
+                       return '';
                };
        } )(),
        /**
@@ -98,8 +101,10 @@
                this.get = function( keys, fallback ) {
                        if ( typeof keys === 'object' ) {
                                var result = {};
-                               for ( key in keys ) {
-                                       result[key] = typeof values[keys] === 
'undefined' ? null : values[keys];
+                               for ( k in keys ) {
+                                       if ( typeof values[keys[k]] !== 
'undefined' ) {
+                                               result[keys[k]] = 
values[keys[k]];
+                                       }
                                }
                                return result;
                        } else if ( typeof values[keys] === 'undefined' ) {
@@ -249,17 +254,17 @@
                                                                break;
                                                        case 'ready':
                                                                // This doesn't 
belong in the queue item's pending list
-                                                               delete 
queue[q].requirements[r];
+                                                               
queue[q].pending.splice( p );
                                                                break;
                                                }
-                                               // If all pending requirements 
have been satisfied, we're ready to execute the callback
-                                               if ( 
queue[q].requirements.length == 0 ) {
-                                                       queue[q].callback();
-                                                       // Clean up the queue
-                                                       delete queue[q];
-                                               }
                                        }
                                }
+                               // If all pending requirements have been 
satisfied, we're ready to execute the callback
+                               if ( typeof queue[q].pending.length == 0 ) {
+                                       queue[q].callback();
+                                       // Clean up the queue
+                                       queue.splice( q, 1 );
+                               }
                        }
                        // Handle the batch only when ready
                        if ( batch.length && ready ) {
@@ -273,12 +278,12 @@
                                        $(this).append(
                                                $( '<script 
type="text/javascript"></script>' )
                                                        .attr( 'src', 
mw.util.buildUrlString( {
-                                                               'path': 
'load.php',
+                                                               'path': 
mw.config.get( 'wgScriptPath' ) + '/load.php',
                                                                'query': 
$.extend(
+                                                                               
// Modules are in the format foo|bar|baz|buz
+                                                                               
{ 'modules': batch.join( '|' ) },
                                                                                
// Pass configuration values through the URL
-                                                                               
mw.config.get( [ 'user', 'skin', 'space', 'view', 'language' ] ),
-                                                                               
// Modules are in the format foo|bar|baz|buz
-                                                                               
{ 'modules': batch.join( '|' ) }
+                                                                               
mw.config.get( [ 'user', 'skin', 'space', 'view', 'language' ] )
                                                                        )
                                                        } ) )
                                                        .load( function() {

Added: branches/resourceloader/phase3/resources/test/bar.js
===================================================================
--- branches/resourceloader/phase3/resources/test/bar.js                        
        (rev 0)
+++ branches/resourceloader/phase3/resources/test/bar.js        2010-06-23 
01:02:13 UTC (rev 68438)
@@ -0,0 +1,2 @@
+// Test output
+console.log( 'Bar' );


Property changes on: branches/resourceloader/phase3/resources/test/bar.js
___________________________________________________________________
Added: svn:eol-style
   + native

Added: branches/resourceloader/phase3/resources/test/baz.js
===================================================================
--- branches/resourceloader/phase3/resources/test/baz.js                        
        (rev 0)
+++ branches/resourceloader/phase3/resources/test/baz.js        2010-06-23 
01:02:13 UTC (rev 68438)
@@ -0,0 +1,2 @@
+// Test output
+console.log( 'Baz' );


Property changes on: branches/resourceloader/phase3/resources/test/baz.js
___________________________________________________________________
Added: svn:eol-style
   + native

Added: branches/resourceloader/phase3/resources/test/buz.js
===================================================================
--- branches/resourceloader/phase3/resources/test/buz.js                        
        (rev 0)
+++ branches/resourceloader/phase3/resources/test/buz.js        2010-06-23 
01:02:13 UTC (rev 68438)
@@ -0,0 +1,2 @@
+// Test output
+console.log( 'Buz' );


Property changes on: branches/resourceloader/phase3/resources/test/buz.js
___________________________________________________________________
Added: svn:eol-style
   + native

Added: branches/resourceloader/phase3/resources/test/foo.js
===================================================================
--- branches/resourceloader/phase3/resources/test/foo.js                        
        (rev 0)
+++ branches/resourceloader/phase3/resources/test/foo.js        2010-06-23 
01:02:13 UTC (rev 68438)
@@ -0,0 +1,2 @@
+// Test output
+console.log( 'Foo' );


Property changes on: branches/resourceloader/phase3/resources/test/foo.js
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: branches/resourceloader/phase3/resources/test/loader.js
===================================================================
--- branches/resourceloader/phase3/resources/test/loader.js     2010-06-23 
00:46:44 UTC (rev 68437)
+++ branches/resourceloader/phase3/resources/test/loader.js     2010-06-23 
01:02:13 UTC (rev 68438)
@@ -1,2 +1,6 @@
-// Registers the module with the loading system
-mw.loader.register( 'test' );
\ No newline at end of file
+// Registers the modules with the loading system
+mw.loader.register( 'test', ['foo'] );
+mw.loader.register( 'foo', ['bar'] );
+mw.loader.register( 'bar', ['buz', 'baz'] );
+mw.loader.register( 'buz' );
+mw.loader.register( 'baz' );
\ No newline at end of file

Modified: branches/resourceloader/phase3/resources/test/test.js
===================================================================
--- branches/resourceloader/phase3/resources/test/test.js       2010-06-23 
00:46:44 UTC (rev 68437)
+++ branches/resourceloader/phase3/resources/test/test.js       2010-06-23 
01:02:13 UTC (rev 68438)
@@ -1,2 +1,2 @@
 // Test output
-console.log( 'Test succeeded!' );
+console.log( 'Test' );



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to