resourceloader: Remove ESI support (previously disabled)
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 31 Jul 2015 19:34:10 +0000 (12:34 -0700)
committerOri.livneh <ori@wikimedia.org>
Sat, 1 Aug 2015 18:05:23 +0000 (18:05 +0000)
These were never enabled or used in production and are not
compatible with the upcoming async changes (T107399). To avoid
having to maintain compatibility with this, remove it for now.

The current on-going request to operations for ESI support is unrelated
to this code.

Considered making makeResourceLoaderLink() protected as it's not
used anywhere in @wikimedia Git outside mediawiki-core. And the unit
test actually treated it as protected already. However it's called
in SpecialJavaScriptTest so leaving that as-is for now.

In Icba6d7a87b239 the signature will change again with the removal
of the $loadCall parameter, which is obsolete in an async world
due to document.write being forbidden.

Change-Id: I9f557cc794638ffd15329934865e21e1027f7cfa

RELEASE-NOTES-1.26
includes/DefaultSettings.php
includes/OutputPage.php
includes/specials/SpecialJavaScriptTest.php
tests/phpunit/includes/OutputPageTest.php

index fc0e752..11da802 100644 (file)
@@ -16,6 +16,8 @@ production.
   use the 'rawcontinue' parameter to receive raw query-continue data, but the
   new style is encouraged as it's harder to implement incorrectly.
 * Deprecated API formats dump and wddx have been completely removed.
+* $wgResourceLoaderUseESI was deprecated and removed. This was an experimental
+  feature that was never enabled by default.
 
 === New features in 1.26 ===
 * (T51506) Now action=info gives estimates of actual watchers for a page.
index 2517bc5..4d1b329 100644 (file)
@@ -3510,13 +3510,6 @@ $wgResourceLoaderMaxage = array(
  */
 $wgResourceLoaderDebug = false;
 
-/**
- * Enable embedding of certain resources using Edge Side Includes. This will
- * improve performance but only works if there is something in front of the
- * web server (e..g a Squid or Varnish server) configured to process the ESI.
- */
-$wgResourceLoaderUseESI = false;
-
 /**
  * Put each statement on its own line when minifying JavaScript. This makes
  * debugging in non-debug mode a bit easier.
index c972045..530a1d5 100644 (file)
@@ -2766,15 +2766,14 @@ class OutputPage extends ContextSource {
         * @todo Document
         * @param array|string $modules One or more module names
         * @param string $only ResourceLoaderModule TYPE_ class constant
-        * @param bool $useESI
         * @param array $extraQuery Array with extra query parameters to add to each
         *   request. array( param => value ).
         * @param bool $loadCall If true, output an (asynchronous) mw.loader.load()
         *   call rather than a "<script src='...'>" tag.
         * @return string The html "<script>", "<link>" and "<style>" tags
         */
-       public function makeResourceLoaderLink( $modules, $only, $useESI = false,
-               array $extraQuery = array(), $loadCall = false
+       public function makeResourceLoaderLink( $modules, $only, array $extraQuery = array(),
+               $loadCall = false
        ) {
                $modules = (array)$modules;
 
@@ -2798,7 +2797,7 @@ class OutputPage extends ContextSource {
                        if ( ResourceLoader::inDebugMode() ) {
                                // Recursively call us for every item
                                foreach ( $modules as $name ) {
-                                       $link = $this->makeResourceLoaderLink( $name, $only, $useESI );
+                                       $link = $this->makeResourceLoaderLink( $name, $only );
                                        $links['html'] = array_merge( $links['html'], $link['html'] );
                                        $links['states'] += $link['states'];
                                }
@@ -2813,7 +2812,6 @@ class OutputPage extends ContextSource {
                // Create keyed-by-source and then keyed-by-group list of module objects from modules list
                $sortedModules = array();
                $resourceLoader = $this->getResourceLoader();
-               $resourceLoaderUseESI = $this->getConfig()->get( 'ResourceLoaderUseESI' );
                foreach ( $modules as $name ) {
                        $module = $resourceLoader->getModule( $name );
                        # Check that we're allowed to include this module on this page
@@ -2908,40 +2906,31 @@ class OutputPage extends ContextSource {
                                $moduleContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                                $url = $resourceLoader->createLoaderURL( $source, $moduleContext, $extraQuery );
 
-                               if ( $useESI && $resourceLoaderUseESI ) {
-                                       $esi = Xml::element( 'esi:include', array( 'src' => $url ) );
-                                       if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
-                                               $link = Html::inlineStyle( $esi );
-                                       } else {
-                                               $link = Html::inlineScript( $esi );
-                                       }
+                               // Automatically select style/script elements
+                               if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
+                                       $link = Html::linkedStyle( $url );
+                               } elseif ( $loadCall ) {
+                                       $link = ResourceLoader::makeInlineScript(
+                                               Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
+                                       );
                                } else {
-                                       // Automatically select style/script elements
-                                       if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
-                                               $link = Html::linkedStyle( $url );
-                                       } elseif ( $loadCall ) {
+                                       $link = Html::linkedScript( $url );
+                                       if ( !$context->getRaw() && !$isRaw ) {
+                                               // Wrap only=script / only=combined requests in a conditional as
+                                               // browsers not supported by the startup module would unconditionally
+                                               // execute this module. Otherwise users will get "ReferenceError: mw is
+                                               // undefined" or "jQuery is undefined" from e.g. a "site" module.
                                                $link = ResourceLoader::makeInlineScript(
-                                                       Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
+                                                       Xml::encodeJsCall( 'document.write', array( $link ) )
                                                );
-                                       } else {
-                                               $link = Html::linkedScript( $url );
-                                               if ( !$context->getRaw() && !$isRaw ) {
-                                                       // Wrap only=script / only=combined requests in a conditional as
-                                                       // browsers not supported by the startup module would unconditionally
-                                                       // execute this module. Otherwise users will get "ReferenceError: mw is
-                                                       // undefined" or "jQuery is undefined" from e.g. a "site" module.
-                                                       $link = ResourceLoader::makeInlineScript(
-                                                               Xml::encodeJsCall( 'document.write', array( $link ) )
-                                                       );
-                                               }
+                                       }
 
-                                               // For modules requested directly in the html via <link> or <script>,
-                                               // tell mw.loader they are being loading to prevent duplicate requests.
-                                               foreach ( $grpModules as $key => $module ) {
-                                                       // Don't output state=loading for the startup module..
-                                                       if ( $key !== 'startup' ) {
-                                                               $links['states'][$key] = 'loading';
-                                                       }
+                                       // For modules requested directly in the html via <link> or <script>,
+                                       // tell mw.loader they are being loading to prevent duplicate requests.
+                                       foreach ( $grpModules as $key => $module ) {
+                                               // Don't output state=loading for the startup module..
+                                               if ( $key !== 'startup' ) {
+                                                       $links['states'][$key] = 'loading';
                                                }
                                        }
                                }
@@ -2994,7 +2983,7 @@ class OutputPage extends ContextSource {
        function getHeadScripts() {
                // Startup - this will immediately load jquery and mediawiki modules
                $links = array();
-               $links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
+               $links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS );
 
                // Load config before anything else
                $links[] = ResourceLoader::makeInlineScript(
@@ -3048,12 +3037,12 @@ class OutputPage extends ContextSource {
                $links = array();
 
                $links[] = $this->makeResourceLoaderLink( $this->getModuleScripts( true, 'bottom' ),
-                       ResourceLoaderModule::TYPE_SCRIPTS, /* $useESI = */ false, /* $extraQuery = */ array(),
+                       ResourceLoaderModule::TYPE_SCRIPTS, /* $extraQuery = */ array(),
                        /* $loadCall = */ $inHead
                );
 
                $links[] = $this->makeResourceLoaderLink( $this->getModuleStyles( true, 'bottom' ),
-                       ResourceLoaderModule::TYPE_STYLES, /* $useESI = */ false, /* $extraQuery = */ array(),
+                       ResourceLoaderModule::TYPE_STYLES, /* $extraQuery = */ array(),
                        /* $loadCall = */ $inHead
                );
 
@@ -3080,7 +3069,7 @@ class OutputPage extends ContextSource {
                ) {
                        // We're on a preview of a JS subpage. Exclude this page from the user module (T28283)
                        // and include the draft contents as a raw script instead.
-                       $links[] = $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_COMBINED, false,
+                       $links[] = $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_COMBINED,
                                array( 'excludepage' => $this->getTitle()->getPrefixedDBkey() ), $inHead
                        );
                        // Load the previewed JS
@@ -3106,13 +3095,13 @@ class OutputPage extends ContextSource {
                } else {
                        // Include the user module normally, i.e., raw to avoid it being wrapped in a closure.
                        $links[] = $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_COMBINED,
-                               /* $useESI = */ false, /* $extraQuery = */ array(), /* $loadCall = */ $inHead
+                               /* $extraQuery = */ array(), /* $loadCall = */ $inHead
                        );
                }
 
                // Group JS is only enabled if site JS is enabled.
                $links[] = $this->makeResourceLoaderLink( 'user.groups', ResourceLoaderModule::TYPE_COMBINED,
-                       /* $useESI = */ false, /* $extraQuery = */ array(), /* $loadCall = */ $inHead
+                       /* $extraQuery = */ array(), /* $loadCall = */ $inHead
                );
 
                return self::getHtmlFromLoaderLinks( $links );
@@ -3671,7 +3660,7 @@ class OutputPage extends ContextSource {
                ) {
                        // We're on a preview of a CSS subpage
                        // Exclude this page from the user module in case it's in there (bug 26283)
-                       $link = $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_STYLES, false,
+                       $link = $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_STYLES,
                                array( 'excludepage' => $this->getTitle()->getPrefixedDBkey() )
                        );
                        $otherTags = array_merge( $otherTags, $link['html'] );
index 4c73f16..442b764 100644 (file)
@@ -247,15 +247,16 @@ HTML;
                        'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
                ) );
 
-               $styles = $out->makeResourceLoaderLink(
-                       'jquery.qunit', ResourceLoaderModule::TYPE_STYLES, false
+               $styles = $out->makeResourceLoaderLink( 'jquery.qunit',
+                       ResourceLoaderModule::TYPE_STYLES
                );
                // Use 'raw' since this is a plain HTML page without ResourceLoader
-               $scripts = $out->makeResourceLoaderLink(
-                       'jquery.qunit', ResourceLoaderModule::TYPE_SCRIPTS, false, array( 'raw' => 'true' )
+               $scripts = $out->makeResourceLoaderLink( 'jquery.qunit',
+                       ResourceLoaderModule::TYPE_SCRIPTS,
+                       array( 'raw' => 'true' )
                );
 
-               $head = trim( $styles['html'] . $scripts['html'] );
+               $head = implode( "\n", array_merge( $styles['html'], $scripts['html'] ) );
                $summary = $this->getSummaryHtml();
                $html = <<<HTML
 <!DOCTYPE html>
index 0b38168..69f55c3 100644 (file)
@@ -174,16 +174,6 @@ class OutputPageTest extends MediaWikiTestCase {
                                        . "mw.test.baz({token:123});},{\"css\":[\".mw-icon{transition:none}\\n"
                                        . "\"]});\n\n} );</script>"
                        ),
-                       // Load module script with ESI
-                       array(
-                               array( 'test.foo', ResourceLoaderModule::TYPE_SCRIPTS, true ),
-                               '<script><esi:include src="http://127.0.0.1:8080/w/load.php?debug=false&amp;lang=en&amp;modules=test.foo&amp;only=scripts&amp;skin=fallback&amp;*" /></script>'
-                       ),
-                       // Load module styles with ESI
-                       array(
-                               array( 'test.foo', ResourceLoaderModule::TYPE_STYLES, true ),
-                               '<style><esi:include src="http://127.0.0.1:8080/w/load.php?debug=false&amp;lang=en&amp;modules=test.foo&amp;only=styles&amp;skin=fallback&amp;*" /></style>',
-                       ),
                        // Load no modules
                        array(
                                array( array(), ResourceLoaderModule::TYPE_COMBINED ),
@@ -219,7 +209,6 @@ class OutputPageTest extends MediaWikiTestCase {
        public function testMakeResourceLoaderLink( $args, $expectedHtml ) {
                $this->setMwGlobals( array(
                        'wgResourceLoaderDebug' => false,
-                       'wgResourceLoaderUseESI' => true,
                        'wgLoadScript' => 'http://127.0.0.1:8080/w/load.php',
                        // Affects whether CDATA is inserted
                        'wgWellFormedXml' => false,