Merge "Add framework for file warnings"
[lhc/web/wiklou.git] / includes / OutputPage.php
index aa282a7..5ad33fa 100644 (file)
@@ -1412,7 +1412,8 @@ class OutputPage extends ContextSource {
                if ( $overrideBaseUrl ) {
                        $helpUrl = $to;
                } else {
-                       $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$to";
+                       $toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) );
+                       $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
                }
                $link = Html::rawElement(
                        'a',
@@ -2673,10 +2674,12 @@ class OutputPage extends ContextSource {
                        $ret .= $item . "\n";
                }
 
+               $ret .= $this->getInlineHeadScript();
+
                // No newline after buildCssLinks since makeResourceLoaderLink did that already
                $ret .= $this->buildCssLinks();
 
-               $ret .= $this->getHeadScripts() . "\n";
+               $ret .= $this->getHeadScripts();
 
                foreach ( $this->mHeadItems as $item ) {
                        $ret .= $item . "\n";
@@ -2853,10 +2856,8 @@ class OutputPage extends ContextSource {
                                                        $resourceLoader->makeModuleResponse( $context, $grpModules )
                                                );
                                        } else {
-                                               $links['html'] .= Html::inlineScript(
-                                                       ResourceLoader::makeLoaderConditionalScript(
-                                                               $resourceLoader->makeModuleResponse( $context, $grpModules )
-                                                       )
+                                               $links['html'] .= ResourceLoader::makeInlineScript(
+                                                       $resourceLoader->makeModuleResponse( $context, $grpModules )
                                                );
                                        }
                                        $links['html'] .= "\n";
@@ -2895,22 +2896,18 @@ class OutputPage extends ContextSource {
                                        if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
                                                $link = Html::linkedStyle( $url );
                                        } elseif ( $loadCall ) {
-                                               $link = Html::inlineScript(
-                                                       ResourceLoader::makeLoaderConditionalScript(
-                                                               Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
-                                                       )
+                                               $link = ResourceLoader::makeInlineScript(
+                                                       Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
                                                );
                                        } else {
                                                $link = Html::linkedScript( $url );
-                                               if ( $context->getOnly() === 'scripts' && !$context->getRaw() && !$isRaw ) {
-                                                       // Wrap only=script 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 = Html::inlineScript(
-                                                               ResourceLoader::makeLoaderConditionalScript(
-                                                                       Xml::encodeJsCall( 'document.write', array( $link ) )
-                                                               )
+                                               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 ) )
                                                        );
                                                }
 
@@ -2954,16 +2951,44 @@ class OutputPage extends ContextSource {
                }
 
                if ( count( $states ) ) {
-                       $html = Html::inlineScript(
-                               ResourceLoader::makeLoaderConditionalScript(
-                                       ResourceLoader::makeLoaderStateScript( $states )
-                               )
+                       $html = ResourceLoader::makeInlineScript(
+                               ResourceLoader::makeLoaderStateScript( $states )
                        ) . "\n" . $html;
                }
 
                return $html;
        }
 
+       /**
+        * Get <script> tags for <head> whose source is inline.
+        *
+        * @since 1.25
+        * @return string HTML fragment
+        */
+       public function getInlineHeadScript() {
+               // Load config before anything else.
+               $html = ResourceLoader::makeInlineScript(
+                       ResourceLoader::makeConfigSetScript( $this->getJSVars() )
+               );
+
+               // Load embeddable private modules before any loader links.
+               $inlineModulesLink = $this->makeResourceLoaderLink(
+                       array( 'user.options', 'user.tokens' ), ResourceLoaderModule::TYPE_COMBINED
+               );
+               $html .= "\n" . self::getHtmlFromLoaderLinks( array( $inlineModulesLink ) );
+
+               // Construct mw.loader.load() call for top-loaded modules.
+               // Client-side code will request these modules and their dependencies.
+               $topModules = $this->getModules( true, 'top' );
+               if ( $topModules ) {
+                       $html .= ResourceLoader::makeInlineScript(
+                               Xml::encodeJsCall( 'mw.loader.load', array( $topModules ) )
+                       ) . "\n";
+               }
+
+               return $html;
+       }
+
        /**
         * JS stuff to put in the "<head>". This is the startup module, config
         * vars and modules marked with position 'top'
@@ -2975,19 +3000,6 @@ class OutputPage extends ContextSource {
                $links = array();
                $links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
 
-               // Load config before anything else
-               $links[] = Html::inlineScript(
-                       ResourceLoader::makeLoaderConditionalScript(
-                               ResourceLoader::makeConfigSetScript( $this->getJSVars() )
-                       )
-               );
-
-               // Load embeddable private modules before any loader links
-               // This needs to be TYPE_COMBINED so these modules are properly wrapped
-               // in mw.loader.implement() calls and deferred until mw.user is available
-               $embedScripts = array( 'user.options', 'user.tokens' );
-               $links[] = $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED );
-
                // Scripts and messages "only" requests marked for top inclusion
                // Messages should go first
                $links[] = $this->makeResourceLoaderLink(
@@ -2999,17 +3011,6 @@ class OutputPage extends ContextSource {
                        ResourceLoaderModule::TYPE_SCRIPTS
                );
 
-               // Modules requests - let the client calculate dependencies and batch requests as it likes
-               // Only load modules that have marked themselves for loading at the top
-               $modules = $this->getModules( true, 'top' );
-               if ( $modules ) {
-                       $links[] = Html::inlineScript(
-                               ResourceLoader::makeLoaderConditionalScript(
-                                       Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
-                               )
-                       );
-               }
-
                if ( $this->getConfig()->get( 'ResourceLoaderExperimentalAsyncLoading' ) ) {
                        $links[] = $this->getScriptsForBottomQueue( true );
                }
@@ -3046,10 +3047,8 @@ class OutputPage extends ContextSource {
                // Only load modules that have marked themselves for loading at the bottom
                $modules = $this->getModules( true, 'bottom' );
                if ( $modules ) {
-                       $links[] = Html::inlineScript(
-                               ResourceLoader::makeLoaderConditionalScript(
-                                       Xml::encodeJsCall( 'mw.loader.load', array( $modules, null, true ) )
-                               )
+                       $links[] = ResourceLoader::makeInlineScript(
+                               Xml::encodeJsCall( 'mw.loader.load', array( $modules, null, true ) )
                        );
                }