From bc374082fa1a0e459ef816908e4d3cb7956ef1aa Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 7 Nov 2016 23:47:15 +0000 Subject: [PATCH] resourceloader: Remove top/bottom queue distinction * The styles queue has always been top-only (except for a few months in 2015). * The top queue loads asynchronous since mid-2015. (T107399) And LocalStorage eval, previously the last remaining non-async part of module loading, is also async as of October 2016. (T142129) * This change merges the bottom 'mw.loader.load()' queue with the top queue. It also moves any other snippets potentially in the bottom queue still: - embed: I couldn't find any private modules with position=bottom (doesn't make sense due to their blocking nature). If any do exist, (third-party extensions?), they'll now be embedded in the . - scripts: Any legacy 'only=scripts' requests will now initiate from the . Bug: T109837 Change-Id: I6c21e3e47c23df33a04c42ce94bd4c1964599c7f --- .../ResourceLoaderClientHtml.php | 65 ++++--------------- .../resourceloader/ResourceLoaderModule.php | 7 +- .../ResourceLoaderClientHtmlTest.php | 20 ++---- 3 files changed, 23 insertions(+), 69 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php b/includes/resourceloader/ResourceLoaderClientHtml.php index 572921817e..91e0b02087 100644 --- a/includes/resourceloader/ResourceLoaderClientHtml.php +++ b/includes/resourceloader/ResourceLoaderClientHtml.php @@ -130,26 +130,15 @@ class ResourceLoaderClientHtml { 'states' => [ // moduleName => state ], - 'general' => [ - // position => [ moduleName ] - 'top' => [], - 'bottom' => [], - ], + 'general' => [], 'styles' => [ // moduleName ], - 'scripts' => [ - // position => [ moduleName ] - 'top' => [], - 'bottom' => [], - ], + 'scripts' => [], // Embedding for private modules 'embed' => [ 'styles' => [], - 'general' => [ - 'top' => [], - 'bottom' => [], - ], + 'general' => [], ], ]; @@ -161,16 +150,15 @@ class ResourceLoaderClientHtml { } $group = $module->getGroup(); - $position = $module->getPosition(); if ( $group === 'private' ) { // Embed via mw.loader.implement per T36907. - $data['embed']['general'][$position][] = $name; + $data['embed']['general'][] = $name; // Avoid duplicate request from mw.loader $data['states'][$name] = 'loading'; } else { // Load via mw.loader.load() - $data['general'][$position][] = $name; + $data['general'][] = $name; } } @@ -216,14 +204,13 @@ class ResourceLoaderClientHtml { } $group = $module->getGroup(); - $position = $module->getPosition(); $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'][$position][] = $name; + $data['scripts'][] = $name; // Avoid duplicate request from mw.loader $data['states'][$name] = 'loading'; @@ -282,24 +269,24 @@ class ResourceLoaderClientHtml { } // Inline RLQ: Embedded modules - if ( $data['embed']['general']['top'] ) { + if ( $data['embed']['general'] ) { $chunks[] = $this->getLoad( - $data['embed']['general']['top'], + $data['embed']['general'], ResourceLoaderModule::TYPE_COMBINED ); } // Inline RLQ: Load general modules - if ( $data['general']['top'] ) { + if ( $data['general'] ) { $chunks[] = ResourceLoader::makeInlineScript( - Xml::encodeJsCall( 'mw.loader.load', [ $data['general']['top'] ] ) + Xml::encodeJsCall( 'mw.loader.load', [ $data['general'] ] ) ); } // Inline RLQ: Load only=scripts - if ( $data['scripts']['top'] ) { + if ( $data['scripts'] ) { $chunks[] = $this->getLoad( - $data['scripts']['top'], + $data['scripts'], ResourceLoaderModule::TYPE_SCRIPTS ); } @@ -336,33 +323,7 @@ class ResourceLoaderClientHtml { * @return string|WrappedStringList HTML */ public function getBodyHtml() { - $data = $this->getData(); - $chunks = []; - - // Inline RLQ: Embedded modules - if ( $data['embed']['general']['bottom'] ) { - $chunks[] = $this->getLoad( - $data['embed']['general']['bottom'], - ResourceLoaderModule::TYPE_COMBINED - ); - } - - // Inline RLQ: Load only=scripts - if ( $data['scripts']['bottom'] ) { - $chunks[] = $this->getLoad( - $data['scripts']['bottom'], - ResourceLoaderModule::TYPE_SCRIPTS - ); - } - - // Inline RLQ: Load general modules - if ( $data['general']['bottom'] ) { - $chunks[] = ResourceLoader::makeInlineScript( - Xml::encodeJsCall( 'mw.loader.load', [ $data['general']['bottom'] ] ) - ); - } - - return WrappedStringList::join( "\n", $chunks ); + return ''; } private function getContext( $group, $type ) { diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 796c575885..4456517f01 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -330,14 +330,13 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { } /** - * Where on the HTML page should this module's JS be loaded? - * - 'top': in the "" - * - 'bottom': at the bottom of the "" + * From where in the page HTML should this module be loaded? * + * @deprecated since 1.29 Obsolete. All modules load async from ``. * @return string */ public function getPosition() { - return 'bottom'; + return 'top'; } /** diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php index d2a0724ccf..528c3220e8 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php @@ -114,22 +114,22 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase { 'test.scripts.mixed.user.empty' => 'ready', ], 'general' => [ - 'top' => [ 'test.top' ], - 'bottom' => [ 'test' ], + 'test', + 'test.top', ], 'styles' => [ 'test.styles.mixed', 'test.styles.pure', ], 'scripts' => [ - 'top' => [ 'test.scripts.top' ], - 'bottom' => [ 'test.scripts' ], + 'test.scripts', + 'test.scripts.top', ], 'embed' => [ 'styles' => [ 'test.styles.private' ], 'general' => [ - 'top' => [ 'test.private.top' ], - 'bottom' => [ 'test.private.bottom' ], + 'test.private.bottom', + 'test.private.top', ], ], ]; @@ -202,13 +202,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase { 'test.scripts', ] ); - // @codingStandardsIgnoreStart Generic.Files.LineLength - $expected = ''; - // @codingStandardsIgnoreEnd + $expected = ''; $expected = self::expandVariables( $expected ); $this->assertEquals( $expected, $client->getBodyHtml() ); -- 2.20.1