Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -68,8 +68,6 @@ |
69 | 69 | |
70 | 70 | // @var array list of module name/ResourceLoaderModule object pairs |
71 | 71 | protected static $modules = array(); |
72 | | - // @var array list of modules which should not be registered, as they are already registered in mediawiki.js |
73 | | - protected static $preRegisteredModules = array( 'jquery', 'mediawiki' ); |
74 | 72 | |
75 | 73 | /* Protected Static Methods */ |
76 | 74 | |
— | — | @@ -185,24 +183,20 @@ |
186 | 184 | $scripts = ''; |
187 | 185 | $registrations = array(); |
188 | 186 | foreach ( self::$modules as $name => $module ) { |
189 | | - if ( in_array( $name, self::$preRegisteredModules ) ) { |
190 | | - $registrations[] = array( $name, $module->getModifiedTime( $lang, $skin, $debug ), array(), 'ready' ); |
191 | | - } else { |
192 | | - // Support module loader scripts |
193 | | - if ( ( $loader = $module->getLoaderScript() ) !== false ) { |
194 | | - $scripts .= $loader; |
| 187 | + // Support module loader scripts |
| 188 | + if ( ( $loader = $module->getLoaderScript() ) !== false ) { |
| 189 | + $scripts .= $loader; |
| 190 | + } |
| 191 | + // Automatically register module |
| 192 | + else { |
| 193 | + // Modules without dependencies pass one argument (name) to mediaWiki.loader.register() |
| 194 | + if ( !count( $module->getDependencies() ) ) { |
| 195 | + $registrations[] = array( $name, $module->getModifiedTime( $lang, $skin, $debug ) ); |
195 | 196 | } |
196 | | - // Automatically register module |
| 197 | + // Modules with dependencies pass two arguments (name, dependencies) to mediaWiki.loader.register() |
197 | 198 | else { |
198 | | - // Modules without dependencies pass one argument (name) to mediaWiki.loader.register() |
199 | | - if ( !count( $module->getDependencies() ) ) { |
200 | | - $registrations[] = array( $name, $module->getModifiedTime( $lang, $skin, $debug ) ); |
201 | | - } |
202 | | - // Modules with dependencies pass two arguments (name, dependencies) to mediaWiki.loader.register() |
203 | | - else { |
204 | | - $registrations[] = array( $name, $module->getModifiedTime( $lang, $skin, $debug ), |
205 | | - $module->getDependencies() ); |
206 | | - } |
| 199 | + $registrations[] = array( $name, $module->getModifiedTime( $lang, $skin, $debug ), |
| 200 | + $module->getDependencies() ); |
207 | 201 | } |
208 | 202 | } |
209 | 203 | } |
— | — | @@ -383,13 +377,21 @@ |
384 | 378 | echo "mediaWiki.loader.implement( '{$name}', function() {{$scripts}},\n'{$styles}',\n{$messages} );\n"; |
385 | 379 | } |
386 | 380 | } |
387 | | - |
| 381 | + // Update the status of script-only modules |
| 382 | + if ( $parameters['only'] === 'scripts' && !in_array( 'startup', $modules ) ) { |
| 383 | + $statuses = array(); |
| 384 | + foreach ( $modules as $name ) { |
| 385 | + $statuses[$name] = 'ready'; |
| 386 | + } |
| 387 | + $statuses = FormatJson::encode( $statuses ); |
| 388 | + echo "mediaWiki.loader.state( {$statuses} );"; |
| 389 | + } |
388 | 390 | // Register missing modules |
389 | 391 | foreach ( $missing as $name ) { |
390 | 392 | echo "mediaWiki.loader.register( '{$name}', null, 'missing' );\n"; |
391 | 393 | } |
392 | 394 | |
393 | | - if ( $parameters['only'] == 'styles' ) { |
| 395 | + if ( $parameters['only'] === 'styles' ) { |
394 | 396 | header( 'Content-Type: text/css' ); |
395 | 397 | } else { |
396 | 398 | header( 'Content-Type: text/javascript' ); |
Index: branches/resourceloader/phase3/resources/Resources.php |
— | — | @@ -358,7 +358,6 @@ |
359 | 359 | ) ), |
360 | 360 | 'mediawiki.legacy.wikibits' => new ResourceLoaderFileModule( array( |
361 | 361 | 'scripts' => 'skins/common/wikibits.js', |
362 | | - 'dependencies' => 'mediawiki', |
363 | 362 | 'messages' => array( 'showtoc', 'hidetoc' ), |
364 | 363 | ) ), |
365 | 364 | ) ); |
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -483,11 +483,11 @@ |
484 | 484 | this.register = function( module, version, dependencies, status ) { |
485 | 485 | // Allow multiple registration |
486 | 486 | if ( typeof module === 'object' ) { |
487 | | - for ( var n = 0; n < module.length; n++ ) { |
488 | | - if ( typeof module[n] === 'string' ) { |
489 | | - that.register( module[n] ); |
490 | | - } else if ( typeof module[n] === 'object' ) { |
491 | | - that.register.apply( that, module[n] ); |
| 487 | + for ( var m = 0; m < module.length; m++ ) { |
| 488 | + if ( typeof module[m] === 'string' ) { |
| 489 | + that.register( module[m] ); |
| 490 | + } else if ( typeof module[m] === 'object' ) { |
| 491 | + that.register.apply( that, module[m] ); |
492 | 492 | } |
493 | 493 | } |
494 | 494 | return; |
— | — | @@ -617,12 +617,29 @@ |
618 | 618 | } |
619 | 619 | }; |
620 | 620 | /** |
621 | | - * Flush the request queue and begin executing load requests on demand |
| 621 | + * Flushes the request queue and begin executing load requests on demand |
622 | 622 | */ |
623 | 623 | this.go = function() { |
624 | 624 | suspended = false; |
625 | 625 | that.work(); |
626 | | - } |
| 626 | + }; |
| 627 | + /** |
| 628 | + * Changes the state of a module |
| 629 | + * |
| 630 | + * @param mixed module string module name or object of module name/state pairs |
| 631 | + * @param string state string state name |
| 632 | + */ |
| 633 | + this.state = function( module, state ) { |
| 634 | + if ( typeof module === 'object' ) { |
| 635 | + for ( var m in module ) { |
| 636 | + that.state( m, module[m] ); |
| 637 | + } |
| 638 | + return; |
| 639 | + } |
| 640 | + if ( module in registry ) { |
| 641 | + registry[module].state = state; |
| 642 | + } |
| 643 | + }; |
627 | 644 | |
628 | 645 | /* Cache document ready status */ |
629 | 646 | |