From c6f344083271fb2b289c5690bbe2a16ce4a714c5 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 3 Mar 2019 19:19:51 +0000 Subject: [PATCH] resourceloader: Remove addModuleScripts, and deprecate getModuleScripts. The addModuleScripts() methods were deprecated in 1.31 and 1.32, these are now removed. The getModuleScripts() are now deprecated as well, always returning an empty array. To be removed in 1.34. Depends on commits for bundled/wmf-deployed extensions that remove the last few remaining callers to the deprecated functions in: 3D, Collection, Flow, GlobalUserPage, and Wikibase. Bug: T188689 Depends-On: If9f0bc6aef85117587fa1929f34f8861c8d80314 Depends-On: Ia8d41b97fbf6822f5f8f7ac889408acce1ac9a3a Depends-On: I503b919739ea474ff33726815b0da55e2f7e2724 Depends-On: I236ef637fd03b810a46eb361e25067a037e9d183 Depends-On: I62e17779753b977a452cc0c9694947941e999cc3 Change-Id: I5a19b8f164ccf666485d2971202194b747f882df --- includes/OutputPage.php | 34 +++------------ includes/api/ApiExpandTemplates.php | 3 +- includes/api/ApiFormatBase.php | 1 - includes/api/ApiParse.php | 6 ++- includes/parser/ParserOutput.php | 18 +------- .../ResourceLoaderClientHtml.php | 43 ------------------- .../mediawiki.action.edit.preview.js | 1 - tests/phpunit/includes/OutputPageTest.php | 1 - tests/phpunit/includes/api/ApiParseTest.php | 3 +- .../includes/parser/ParserOutputTest.php | 6 --- .../ResourceLoaderClientHtmlTest.php | 26 +---------- 11 files changed, 15 insertions(+), 127 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 461df946e7..c663855c96 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -152,9 +152,6 @@ class OutputPage extends ContextSource { /** @var array */ protected $mModules = []; - /** @var array */ - protected $mModuleScripts = []; - /** @var array */ protected $mModuleStyles = []; @@ -552,30 +549,12 @@ class OutputPage extends ContextSource { } /** - * Get the list of script-only modules to load on this page. - * - * @param bool $filter - * @param string|null $position Unused - * @return array Array of module names - */ - public function getModuleScripts( $filter = false, $position = null ) { - return $this->getModules( $filter, null, 'mModuleScripts', - ResourceLoaderModule::TYPE_SCRIPTS - ); - } - - /** - * Load the scripts of one or more ResourceLoader modules, on this page. - * - * This method exists purely to provide the legacy behaviour of loading - * a module's scripts in the global scope, and without dependency resolution. - * See . - * - * @deprecated since 1.31 Use addModules() instead. - * @param string|array $modules Module name (string) or array of module names + * @deprecated since 1.33 Use getModules() instead. + * @return array */ - public function addModuleScripts( $modules ) { - $this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules ); + public function getModuleScripts() { + wfDeprecated( __METHOD__, '1.33' ); + return []; } /** @@ -1970,7 +1949,6 @@ class OutputPage extends ContextSource { $this->mNoGallery = $parserOutput->getNoGallery(); $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() ); $this->addModules( $parserOutput->getModules() ); - $this->addModuleScripts( $parserOutput->getModuleScripts() ); $this->addModuleStyles( $parserOutput->getModuleStyles() ); $this->addJsConfigVars( $parserOutput->getJsConfigVars() ); $this->mPreventClickjacking = $this->mPreventClickjacking @@ -2037,7 +2015,6 @@ class OutputPage extends ContextSource { $this->addParserOutputText( $parserOutput, $poOptions ); $this->addModules( $parserOutput->getModules() ); - $this->addModuleScripts( $parserOutput->getModuleScripts() ); $this->addModuleStyles( $parserOutput->getModuleStyles() ); $this->addJsConfigVars( $parserOutput->getJsConfigVars() ); @@ -3183,7 +3160,6 @@ class OutputPage extends ContextSource { $rlClient->setConfig( $this->getJSVars() ); $rlClient->setModules( $this->getModules( /*filter*/ true ) ); $rlClient->setModuleStyles( $moduleStyles ); - $rlClient->setModuleScripts( $this->getModuleScripts( /*filter*/ true ) ); $rlClient->setExemptStates( $exemptStates ); $this->rlClient = $rlClient; } diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 562bcdf9da..22f52356f2 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -162,7 +162,8 @@ class ApiExpandTemplates extends ApiBase { } if ( isset( $prop['modules'] ) ) { $retval['modules'] = array_values( array_unique( $p_output->getModules() ) ); - $retval['modulescripts'] = array_values( array_unique( $p_output->getModuleScripts() ) ); + // Deprecated since 1.32 (T188689) + $retval['modulescripts'] = []; $retval['modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) ); } if ( isset( $prop['jsconfigvars'] ) ) { diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 9d6914579f..e03352554b 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -307,7 +307,6 @@ abstract class ApiFormatBase extends ApiBase { 'html' => $out->getHTML(), 'modules' => array_values( array_unique( array_merge( $out->getModules(), - $out->getModuleScripts(), $out->getModuleStyles() ) ) ), 'continue' => $this->getResult()->getResultData( 'continue' ), diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 855b73d2e1..fc730e3ceb 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -417,11 +417,13 @@ class ApiParse extends ApiBase { if ( isset( $prop['modules'] ) ) { if ( $skin ) { $result_array['modules'] = $outputPage->getModules(); - $result_array['modulescripts'] = $outputPage->getModuleScripts(); + // Deprecated since 1.32 (T188689) + $result_array['modulescripts'] = []; $result_array['modulestyles'] = $outputPage->getModuleStyles(); } else { $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) ); - $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) ); + // Deprecated since 1.32 (T188689) + $result_array['modulescripts'] = []; $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) ); } } diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 6260de6bc0..e0e5d75e92 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -120,11 +120,6 @@ class ParserOutput extends CacheTime { */ public $mModules = []; - /** - * @var array $mModuleScripts Modules of which only the JS will be loaded by ResourceLoader. - */ - public $mModuleScripts = []; - /** * @var array $mModuleStyles Modules of which only the CSSS will be loaded by ResourceLoader. */ @@ -524,7 +519,8 @@ class ParserOutput extends CacheTime { } public function getModuleScripts() { - return $this->mModuleScripts; + wfDeprecated( __METHOD__, '1.33' ); + return []; } public function getModuleStyles() { @@ -817,14 +813,6 @@ class ParserOutput extends CacheTime { $this->mModules = array_merge( $this->mModules, (array)$modules ); } - /** - * @deprecated since 1.31 Use addModules() instead. - * @see OutputPage::addModuleScripts - */ - public function addModuleScripts( $modules ) { - $this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules ); - } - /** * @see OutputPage::addModuleStyles */ @@ -857,7 +845,6 @@ class ParserOutput extends CacheTime { */ public function addOutputPageMetadata( OutputPage $out ) { $this->addModules( $out->getModules() ); - $this->addModuleScripts( $out->getModuleScripts() ); $this->addModuleStyles( $out->getModuleStyles() ); $this->addJsConfigVars( $out->getJsConfigVars() ); @@ -1338,7 +1325,6 @@ class ParserOutput extends CacheTime { // HTML and HTTP $this->mHeadItems = self::mergeMixedList( $this->mHeadItems, $source->getHeadItems() ); $this->mModules = self::mergeList( $this->mModules, $source->getModules() ); - $this->mModuleScripts = self::mergeList( $this->mModuleScripts, $source->getModuleScripts() ); $this->mModuleStyles = self::mergeList( $this->mModuleStyles, $source->getModuleStyles() ); $this->mJsConfigVars = self::mergeMap( $this->mJsConfigVars, $source->getJsConfigVars() ); $this->mMaxAdaptiveExpiry = min( $this->mMaxAdaptiveExpiry, $source->mMaxAdaptiveExpiry ); diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php b/includes/resourceloader/ResourceLoaderClientHtml.php index 5c072bfdec..2b3db22a48 100644 --- a/includes/resourceloader/ResourceLoaderClientHtml.php +++ b/includes/resourceloader/ResourceLoaderClientHtml.php @@ -46,9 +46,6 @@ class ResourceLoaderClientHtml { /** @var array */ private $moduleStyles = []; - /** @var array */ - private $moduleScripts = []; - /** @var array */ private $exemptStates = []; @@ -101,16 +98,6 @@ class ResourceLoaderClientHtml { $this->moduleStyles = $modules; } - /** - * Ensure the scripts of one or more modules are loaded. - * - * @deprecated since 1.28 - * @param array $modules Array of module names - */ - public function setModuleScripts( array $modules ) { - $this->moduleScripts = $modules; - } - /** * Set state of special modules that are handled by the caller manually. * @@ -139,7 +126,6 @@ class ResourceLoaderClientHtml { ], 'general' => [], 'styles' => [], - 'scripts' => [], // Embedding for private modules 'embed' => [ 'styles' => [], @@ -217,26 +203,6 @@ class ResourceLoaderClientHtml { } } - foreach ( $this->moduleScripts as $name ) { - $module = $rl->getModule( $name ); - if ( !$module ) { - continue; - } - - $group = $module->getGroup(); - $context = $this->getContext( $group, ResourceLoaderModule::TYPE_SCRIPTS ); - if ( $module->isKnownEmpty( $context ) ) { - // Avoid needless request for empty module - $data['states'][$name] = 'ready'; - } else { - // Load from load.php?only=scripts via - $data['scripts'][] = $name; - - // Avoid duplicate request from mw.loader - $data['states'][$name] = 'loading'; - } - } - return $data; } @@ -312,15 +278,6 @@ class ResourceLoaderClientHtml { ); } - // Inline RLQ: Load only=scripts - if ( $data['scripts'] ) { - $chunks[] = $this->getLoad( - $data['scripts'], - ResourceLoaderModule::TYPE_SCRIPTS, - $nonce - ); - } - // External stylesheets (only=styles) if ( $data['styles'] ) { $chunks[] = $this->getLoad( diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js index a3708817ba..af4b8976f4 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js @@ -145,7 +145,6 @@ } if ( response.parse.modules ) { mw.loader.load( response.parse.modules.concat( - response.parse.modulescripts, response.parse.modulestyles ) ); } diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 7bb5c38fa9..abc7c43542 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -1744,7 +1744,6 @@ class OutputPageTest extends MediaWikiTestCase { // @todo Make sure to test the following in addParserOutputMetadata() as well when we add tests // for them: // * addModules() - // * addModuleScripts() // * addModuleStyles() // * addJsConfigVars() // * enableOOUI() diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php index b20d43e28c..f8399a3f33 100644 --- a/tests/phpunit/includes/api/ApiParseTest.php +++ b/tests/phpunit/includes/api/ApiParseTest.php @@ -650,7 +650,6 @@ class ApiParseTest extends ApiTestCase { function ( $parser ) { $output = $parser->getOutput(); $output->addModules( [ 'foo', 'bar' ] ); - $output->addModuleScripts( [ 'baz', 'quuz' ] ); $output->addModuleStyles( [ 'aaa', 'zzz' ] ); $output->addJsConfigVars( [ 'x' => 'y', 'z' => -3 ] ); } @@ -663,7 +662,7 @@ class ApiParseTest extends ApiTestCase { ] ); $this->assertSame( [ 'foo', 'bar' ], $res[0]['parse']['modules'] ); - $this->assertSame( [ 'baz', 'quuz' ], $res[0]['parse']['modulescripts'] ); + $this->assertSame( [], $res[0]['parse']['modulescripts'] ); $this->assertSame( [ 'aaa', 'zzz' ], $res[0]['parse']['modulestyles'] ); $this->assertSame( [ 'x' => 'y', 'z' => -3 ], $res[0]['parse']['jsconfigvars'] ); $this->assertSame( '{"x":"y","z":-3}', $res[0]['parse']['encodedjsconfigvars'] ); diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php index cb8257c050..af2b9b7a1f 100644 --- a/tests/phpunit/includes/parser/ParserOutputTest.php +++ b/tests/phpunit/includes/parser/ParserOutputTest.php @@ -397,7 +397,6 @@ EOF $a->addHeadItem( '' ); $a->addHeadItem( '', 'bar' ); $a->addModules( 'test-module-a' ); - $a->addModuleScripts( 'test-module-script-a' ); $a->addModuleStyles( 'test-module-styles-a' ); $b->addJsConfigVars( 'test-config-var-a', 'a' ); @@ -406,7 +405,6 @@ EOF $b->addHeadItem( '' ); $b->addHeadItem( '', 'bar' ); $b->addModules( 'test-module-b' ); - $b->addModuleScripts( 'test-module-script-b' ); $b->addModuleStyles( 'test-module-styles-b' ); $b->addJsConfigVars( 'test-config-var-b', 'b' ); $b->addJsConfigVars( 'test-config-var-a', 'X' ); @@ -421,10 +419,6 @@ EOF 'test-module-a', 'test-module-b', ], - 'getModuleScripts' => [ - 'test-module-script-a', - 'test-module-script-b', - ], 'getModuleStyles' => [ 'test-module-styles-a', 'test-module-styles-b', diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php index 70056baf62..8fdf5dd075 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php @@ -106,7 +106,6 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase { * @covers ResourceLoaderClientHtml::__construct * @covers ResourceLoaderClientHtml::setModules * @covers ResourceLoaderClientHtml::setModuleStyles - * @covers ResourceLoaderClientHtml::setModuleScripts * @covers ResourceLoaderClientHtml::getData * @covers ResourceLoaderClientHtml::getContext */ @@ -132,13 +131,6 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase { 'test.styles.deprecated', 'test.unregistered.styles', ] ); - $client->setModuleScripts( [ - 'test.scripts', - 'test.scripts.user', - 'test.scripts.user.empty', - 'test.scripts.shouldembed', - 'test.unregistered.scripts', - ] ); $expected = [ 'states' => [ @@ -151,10 +143,6 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase { 'test.styles.private' => 'ready', 'test.styles.shouldembed' => 'ready', 'test.styles.deprecated' => 'ready', - 'test.scripts' => 'loading', - 'test.scripts.user' => 'loading', - 'test.scripts.user.empty' => 'ready', - 'test.scripts.shouldembed' => 'loading', ], 'general' => [ 'test', @@ -163,11 +151,6 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase { 'test.styles.pure', 'test.styles.deprecated', ], - 'scripts' => [ - 'test.scripts', - 'test.scripts.user', - 'test.scripts.shouldembed', - ], 'embed' => [ 'styles' => [ 'test.styles.private', 'test.styles.shouldembed' ], 'general' => [ @@ -213,9 +196,6 @@ Deprecation message.' ] 'test.styles.private', 'test.styles.deprecated', ] ); - $client->setModuleScripts( [ - 'test.scripts', - ] ); $client->setExemptStates( [ 'test.exempt' => 'ready', ] ); @@ -224,10 +204,9 @@ Deprecation message.' ] $expected = '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" @@ -312,9 +291,6 @@ Deprecation message.' ] $client->setModuleStyles( [ 'test.styles.deprecated', ] ); - $client->setModuleScripts( [ - 'test.scripts', - ] ); // phpcs:disable Generic.Files.LineLength $expected = '