r72259 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72258‎ | r72259 | r72260 >
Date:03:56, 3 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Removed the notion of "pre-loaded" modules, in favor of once again updating the client's module registry for script loaded as only=scripts. Special casing is used for the startup module.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/resources/Resources.php (modified) (history)
  • /branches/resourceloader/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -68,8 +68,6 @@
6969
7070 // @var array list of module name/ResourceLoaderModule object pairs
7171 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' );
7472
7573 /* Protected Static Methods */
7674
@@ -185,24 +183,20 @@
186184 $scripts = '';
187185 $registrations = array();
188186 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 ) );
195196 }
196 - // Automatically register module
 197+ // Modules with dependencies pass two arguments (name, dependencies) to mediaWiki.loader.register()
197198 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() );
207201 }
208202 }
209203 }
@@ -383,13 +377,21 @@
384378 echo "mediaWiki.loader.implement( '{$name}', function() {{$scripts}},\n'{$styles}',\n{$messages} );\n";
385379 }
386380 }
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+ }
388390 // Register missing modules
389391 foreach ( $missing as $name ) {
390392 echo "mediaWiki.loader.register( '{$name}', null, 'missing' );\n";
391393 }
392394
393 - if ( $parameters['only'] == 'styles' ) {
 395+ if ( $parameters['only'] === 'styles' ) {
394396 header( 'Content-Type: text/css' );
395397 } else {
396398 header( 'Content-Type: text/javascript' );
Index: branches/resourceloader/phase3/resources/Resources.php
@@ -358,7 +358,6 @@
359359 ) ),
360360 'mediawiki.legacy.wikibits' => new ResourceLoaderFileModule( array(
361361 'scripts' => 'skins/common/wikibits.js',
362 - 'dependencies' => 'mediawiki',
363362 'messages' => array( 'showtoc', 'hidetoc' ),
364363 ) ),
365364 ) );
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js
@@ -483,11 +483,11 @@
484484 this.register = function( module, version, dependencies, status ) {
485485 // Allow multiple registration
486486 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] );
492492 }
493493 }
494494 return;
@@ -617,12 +617,29 @@
618618 }
619619 };
620620 /**
621 - * Flush the request queue and begin executing load requests on demand
 621+ * Flushes the request queue and begin executing load requests on demand
622622 */
623623 this.go = function() {
624624 suspended = false;
625625 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+ };
627644
628645 /* Cache document ready status */
629646

Status & tagging log