From 6815e355753c633578636d6b3102f70f4038a602 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 14 Aug 2018 00:55:48 +0100 Subject: [PATCH] resourceloader: Remove support for `state(name, state)` signature This has no usage in non-test code anywhere in Wikimedia Git, and was only used in the test suite for mw.loader in core, and in the test suite for the NavigationTiming extension. The core usage is as part of this commit. The usage in NavTiming is updated by I240ced4e65988f9. Bug: T127328 Depends-On: I240ced4e65988f96c7ece3772378c2c9a335fb9a Change-Id: Ic17c797e528feaf07a4777709d705615fea353e5 --- includes/resourceloader/ResourceLoader.php | 27 +++++++--------- resources/src/startup/mediawiki.js | 31 ++++++++----------- tests/qunit/data/load.mock.php | 2 +- .../mediawiki/mediawiki.loader.test.js | 4 +-- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 637bae640a..2843ba8c51 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -1298,8 +1298,8 @@ MESSAGE; } /** - * Returns a JS call to mw.loader.state, which sets the state of a - * module or modules to a given value. Has two calling conventions: + * Returns a JS call to mw.loader.state, which sets the state of one + * ore more modules to a given value. Has two calling conventions: * * - ResourceLoader::makeLoaderStateScript( $name, $state ): * Set the state of a single module called $name to $state @@ -1307,24 +1307,19 @@ MESSAGE; * - ResourceLoader::makeLoaderStateScript( [ $name => $state, ... ] ): * Set the state of modules with the given names to the given states * - * @param string $name + * @param array|string $states * @param string|null $state * @return string JavaScript code */ - public static function makeLoaderStateScript( $name, $state = null ) { - if ( is_array( $name ) ) { - return Xml::encodeJsCall( - 'mw.loader.state', - [ $name ], - self::inDebugMode() - ); - } else { - return Xml::encodeJsCall( - 'mw.loader.state', - [ $name, $state ], - self::inDebugMode() - ); + public static function makeLoaderStateScript( $states, $state = null ) { + if ( !is_array( $states ) ) { + $states = [ $states => $state ]; } + return Xml::encodeJsCall( + 'mw.loader.state', + [ $states ], + self::inDebugMode() + ); } /** diff --git a/resources/src/startup/mediawiki.js b/resources/src/startup/mediawiki.js index 63d23d8d3a..d586fc9f9f 100644 --- a/resources/src/startup/mediawiki.js +++ b/resources/src/startup/mediawiki.js @@ -1922,26 +1922,21 @@ /** * Change the state of one or more modules. * - * @param {string|Object} module Module name or object of module name/state pairs - * @param {string} state State name + * @param {Object|string} modules Object of module name/state pairs */ - state: function ( module, state ) { - var m; - - if ( typeof module === 'object' ) { - for ( m in module ) { - mw.loader.state( m, module[ m ] ); + state: function ( modules ) { + var module, state; + for ( module in modules ) { + state = modules[ module ]; + if ( !hasOwn.call( registry, module ) ) { + mw.loader.register( module ); + } + registry[ module ].state = state; + if ( state === 'ready' || state === 'error' || state === 'missing' ) { + // Make sure pending modules depending on this one get executed if their + // dependencies are now fulfilled! + handlePending( module ); } - return; - } - if ( !hasOwn.call( registry, module ) ) { - mw.loader.register( module ); - } - registry[ module ].state = state; - if ( state === 'ready' || state === 'error' || state === 'missing' ) { - // Make sure pending modules depending on this one get executed if their - // dependencies are now fulfilled! - handlePending( module ); } }, diff --git a/tests/qunit/data/load.mock.php b/tests/qunit/data/load.mock.php index 3b710c4a50..2238fcebf5 100644 --- a/tests/qunit/data/load.mock.php +++ b/tests/qunit/data/load.mock.php @@ -103,7 +103,7 @@ if ( isset( $_GET['modules'] ) ) { . '} );'; } else { // Default - $response .= 'mw.loader.state(' . json_encode( $module ) . ', "missing" );' . "\n"; + $response .= 'mw.loader.state(' . json_encode( [ $module => 'missing' ] ) . ');' . "\n"; } } } diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js index 05b85be3a4..1a1affa5f5 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js @@ -665,7 +665,7 @@ assert.strictEqual( mw.loader.getState( 'test.module7' ), 'registered', 'Expected "registered" state for test.module7' ); assert.strictEqual( mw.loader.getState( 'test.module8' ), 'loaded', 'Expected "loaded" state for test.module8' ); assert.strictEqual( mw.loader.getState( 'test.module9' ), 'registered', 'Expected "registered" state for test.module9' ); - mw.loader.state( 'test.module7', 'missing' ); + mw.loader.state( { 'test.module7': 'missing' } ); assert.strictEqual( mw.loader.getState( 'test.module7' ), 'missing', 'Expected "missing" state for test.module7' ); assert.strictEqual( mw.loader.getState( 'test.module8' ), 'error', 'Expected "error" state for test.module8' ); assert.strictEqual( mw.loader.getState( 'test.module9' ), 'error', 'Expected "error" state for test.module9' ); @@ -732,7 +732,7 @@ }, function ( e, badmodules ) { assert.ok( true, 'Error handler should be invoked.' ); - // As soon as server spits out state('testMissing', 'missing'); + // As soon as server sets state of 'testMissing' to 'missing' // it will bubble up and trigger the error callback. // Therefor the badmodules array is not testUsesMissing or testUsesNestedMissing. assert.deepEqual( badmodules, [ 'testMissing' ], 'Bad modules as expected.' ); -- 2.20.1