Merge "Update monolog/monolog from 1.22.1 -> 1.24.0"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderClientHtml.php
index ec408c7..7f2f85f 100644 (file)
@@ -233,27 +233,43 @@ class ResourceLoaderClientHtml {
                $chunks = [];
 
                // Change "client-nojs" class to client-js. This allows easy toggling of UI components.
-               // This happens synchronously on every page view to avoid flashes of wrong content.
+               // This must happen synchronously on every page view to avoid flashes of wrong content.
                // See also #getDocumentAttributes() and /resources/src/startup.js.
-               $chunks[] = Html::inlineScript(
-                       'document.documentElement.className = document.documentElement.className'
-                       . '.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );',
-                       $nonce
-               );
+               $script = <<<JAVASCRIPT
+document.documentElement.className = document.documentElement.className
+       .replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );
+JAVASCRIPT;
 
-               // Inline RLQ: Set page variables
+               // Inline script: Declare mw.config variables for this page.
                if ( $this->config ) {
-                       $chunks[] = ResourceLoader::makeInlineScript(
-                               ResourceLoader::makeConfigSetScript( $this->config ),
-                               $nonce
-                       );
+                       $confJson = ResourceLoader::encodeJsonForScript( $this->config );
+                       $script .= <<<JAVASCRIPT
+RLCONF = {$confJson};
+JAVASCRIPT;
                }
 
-               // Inline RLQ: Initial module states
+               // Inline script: Declare initial module states for this page.
                $states = array_merge( $this->exemptStates, $data['states'] );
                if ( $states ) {
-                       $chunks[] = ResourceLoader::makeInlineScript(
-                               ResourceLoader::makeLoaderStateScript( $states ),
+                       $stateJson = ResourceLoader::encodeJsonForScript( $states );
+                       $script .= <<<JAVASCRIPT
+RLSTATE = {$stateJson};
+JAVASCRIPT;
+               }
+
+               // Inline script: Declare general modules to load on this page.
+               if ( $data['general'] ) {
+                       $pageModulesJson = ResourceLoader::encodeJsonForScript( $data['general'] );
+                       $script .= <<<JAVASCRIPT
+RLPAGEMODULES = {$pageModulesJson};
+JAVASCRIPT;
+               }
+
+               if ( $this->context->getDebug() ) {
+                       $chunks[] = Html::inlineScript( $script, $nonce );
+               } else {
+                       $chunks[] = Html::inlineScript(
+                               ResourceLoader::filter( 'minify-js', $script, [ 'cache' => false ] ),
                                $nonce
                        );
                }
@@ -267,17 +283,6 @@ class ResourceLoaderClientHtml {
                        );
                }
 
-               // Inline RLQ: Load general modules
-               if ( $data['general'] ) {
-                       $chunks[] = ResourceLoader::makeInlineScript(
-                               'RLPAGEMODULES='
-                                       . ResourceLoader::encodeJsonForScript( $data['general'] )
-                                       . ';'
-                                       . 'mw.loader.load(RLPAGEMODULES);',
-                               $nonce
-                       );
-               }
-
                // External stylesheets (only=styles)
                if ( $data['styles'] ) {
                        $chunks[] = $this->getLoad(
@@ -298,7 +303,7 @@ class ResourceLoaderClientHtml {
 
                // Async scripts. Once the startup is loaded, inline RLQ scripts will run.
                // Pass-through a custom 'target' from OutputPage (T143066).
-               $startupQuery = [];
+               $startupQuery = [ 'raw' => '1' ];
                foreach ( [ 'target', 'safemode' ] as $param ) {
                        if ( $this->options[$param] !== null ) {
                                $startupQuery[$param] = (string)$this->options[$param];