X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderClientHtml.php;h=e324d044233de05b8231d0cdcc57bb818655dbe4;hb=1b031cbf3f49d7b830bc7b55d65a142d0956b9da;hp=ec408c742bbfd9c65bb806689a51eec905deb06e;hpb=a38af7ba26579bb3004f673e44d39710887763aa;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php b/includes/resourceloader/ResourceLoaderClientHtml.php index ec408c742b..e324d04423 100644 --- a/includes/resourceloader/ResourceLoaderClientHtml.php +++ b/includes/resourceloader/ResourceLoaderClientHtml.php @@ -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 = <<config ) { - $chunks[] = ResourceLoader::makeInlineScript( - ResourceLoader::makeConfigSetScript( $this->config ), - $nonce - ); + $confJson = ResourceLoader::encodeJsonForScript( $this->config ); + $script .= <<exemptStates, $data['states'] ); if ( $states ) { - $chunks[] = ResourceLoader::makeInlineScript( - ResourceLoader::makeLoaderStateScript( $states ), + $stateJson = ResourceLoader::encodeJsonForScript( $states ); + $script .= <<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]; @@ -343,7 +348,7 @@ class ResourceLoaderClientHtml { private static function makeContext( ResourceLoaderContext $mainContext, $group, $type, array $extraQuery = [] ) { - // Create new ResourceLoaderContext so that $extraQuery may trigger isRaw(). + // Create new ResourceLoaderContext so that $extraQuery is supported (eg. for 'sync=1'). $req = new FauxRequest( array_merge( $mainContext->getRequest()->getValues(), $extraQuery ) ); // Set 'only' if not combined $req->setVal( 'only', $type === ResourceLoaderModule::TYPE_COMBINED ? null : $type ); @@ -429,12 +434,6 @@ class ResourceLoaderClientHtml { ); } } else { - // See if we have one or more raw modules - $isRaw = false; - foreach ( $moduleSet as $key => $module ) { - $isRaw |= $module->isRaw(); - } - // Special handling for the user group; because users might change their stuff // on-wiki like user pages, or user preferences; we need to find the highest // timestamp of these user-changeable modules so we can ensure cache misses on change @@ -450,9 +449,15 @@ class ResourceLoaderClientHtml { // Decide whether to use 'style' or 'script' element if ( $only === ResourceLoaderModule::TYPE_STYLES ) { $chunk = Html::linkedStyle( $url ); - } elseif ( $context->getRaw() || $isRaw ) { + } elseif ( $context->getRaw() ) { + // This request is asking for the module to be delivered standalone, + // (aka "raw") without communicating to any mw.loader client. + // Use cases: + // - startup (naturally because this is what will define mw.loader) + // - html5shiv (loads synchronously in old IE before the async startup module arrives) + // - QUnit (needed in SpecialJavaScriptTest before async startup) $chunk = Html::element( 'script', [ - // In SpecialJavaScriptTest, QUnit must load synchronous + // The 'sync' option is only supported in combination with 'raw'. 'async' => !isset( $extraQuery['sync'] ), 'src' => $url ] );