resourceloader: Remove addModuleScripts, and deprecate getModuleScripts.
authorTimo Tijhof <krinklemail@gmail.com>
Sun, 3 Mar 2019 19:19:51 +0000 (19:19 +0000)
committerKrinkle <krinklemail@gmail.com>
Tue, 5 Mar 2019 16:54:08 +0000 (16:54 +0000)
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
includes/api/ApiExpandTemplates.php
includes/api/ApiFormatBase.php
includes/api/ApiParse.php
includes/parser/ParserOutput.php
includes/resourceloader/ResourceLoaderClientHtml.php
resources/src/mediawiki.action/mediawiki.action.edit.preview.js
tests/phpunit/includes/OutputPageTest.php
tests/phpunit/includes/api/ApiParseTest.php
tests/phpunit/includes/parser/ParserOutputTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php

index 461df94..c663855 100644 (file)
@@ -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 <https://phabricator.wikimedia.org/T188689>.
-        *
-        * @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;
                }
index 562bcdf..22f5235 100644 (file)
@@ -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'] ) ) {
index 9d69145..e033525 100644 (file)
@@ -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' ),
index 855b73d..fc730e3 100644 (file)
@@ -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() ) );
                        }
                }
index 6260de6..e0e5d75 100644 (file)
@@ -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 );
index 5c072bf..2b3db22 100644 (file)
@@ -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 <script src></script>
-                               $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(
index a370881..af4b897 100644 (file)
                                }
                                if ( response.parse.modules ) {
                                        mw.loader.load( response.parse.modules.concat(
-                                               response.parse.modulescripts,
                                                response.parse.modulestyles
                                        ) );
                                }
index 7bb5c38..abc7c43 100644 (file)
@@ -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()
index b20d43e..f8399a3 100644 (file)
@@ -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'] );
index cb8257c..af2b9b7 100644 (file)
@@ -397,7 +397,6 @@ EOF
                $a->addHeadItem( '<foo1>' );
                $a->addHeadItem( '<bar1>', '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( '<foo2>' );
                $b->addHeadItem( '<bar2>', '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',
index 70056ba..8fdf5dd 100644 (file)
@@ -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 = '<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' . "\n"
                        . '<script>(window.RLQ=window.RLQ||[]).push(function(){'
                        . 'mw.config.set({"key":"value"});'
-                       . 'mw.loader.state({"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.styles.deprecated":"ready","test.scripts":"loading"});'
+                       . 'mw.loader.state({"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.styles.deprecated":"ready"});'
                        . 'mw.loader.implement("test.private@{blankVer}",null,{"css":[]});'
                        . 'RLPAGEMODULES=["test"];mw.loader.load(RLPAGEMODULES);'
-                       . 'mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts\u0026only=scripts\u0026skin=fallback");'
                        . '});</script>' . "\n"
                        . '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.deprecated%2Cpure&amp;only=styles&amp;skin=fallback"/>' . "\n"
                        . '<style>.private{}</style>' . "\n"
@@ -312,9 +291,6 @@ Deprecation message.' ]
                $client->setModuleStyles( [
                        'test.styles.deprecated',
                ] );
-               $client->setModuleScripts( [
-                       'test.scripts',
-               ] );
                // phpcs:disable Generic.Files.LineLength
                $expected = '<script>(window.RLQ=window.RLQ||[]).push(function(){'
                        . 'mw.log.warn("This page is using the deprecated ResourceLoader module \"test.styles.deprecated\".\nDeprecation message.");'