Merge "Fix double quote to apostrophe in a message"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 5ad33fa..8f9f9c6 100644 (file)
@@ -2674,12 +2674,10 @@ 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();
+               $ret .= $this->getHeadScripts() . "\n";
 
                foreach ( $this->mHeadItems as $item ) {
                        $ret .= $item . "\n";
@@ -2959,36 +2957,6 @@ class OutputPage extends ContextSource {
                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'
@@ -3000,6 +2968,17 @@ class OutputPage extends ContextSource {
                $links = array();
                $links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
 
+               // Load config before anything else
+               $links[] = ResourceLoader::makeInlineScript(
+                       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(
@@ -3011,6 +2990,15 @@ 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[] = ResourceLoader::makeInlineScript(
+                               Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
+                       );
+               }
+
                if ( $this->getConfig()->get( 'ResourceLoaderExperimentalAsyncLoading' ) ) {
                        $links[] = $this->getScriptsForBottomQueue( true );
                }
@@ -3104,7 +3092,7 @@ class OutputPage extends ContextSource {
                // This also enforces $.isReady to be true at </body> which fixes the
                // mw.loader bug in Firefox with using document.write between </body>
                // and the DOMContentReady event (bug 47457).
-               $html = Html::inlineScript( 'window.jQuery && jQuery.ready();' );
+               $html = Html::inlineScript( 'if(window.jQuery)jQuery.ready();' );
 
                if ( !$this->getConfig()->get( 'ResourceLoaderExperimentalAsyncLoading' ) ) {
                        $html .= $this->getScriptsForBottomQueue( false );
@@ -3286,6 +3274,10 @@ class OutputPage extends ContextSource {
                if ( !$this->getTitle()->isJsSubpage() && !$this->getTitle()->isCssSubpage() ) {
                        return false;
                }
+               if ( !$this->getTitle()->isSubpageOf( $this->getUser()->getUserPage() ) ) {
+                       // Don't execute another user's CSS or JS on preview (T85855)
+                       return false;
+               }
 
                return !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) );
        }
@@ -3917,6 +3909,11 @@ class OutputPage extends ContextSource {
        public function enableOOUI() {
                OOUI\Theme::setSingleton( new OOUI\MediaWikiTheme() );
                OOUI\Element::setDefaultDir( $this->getLanguage()->getDir() );
-               $this->addModuleStyles( 'oojs-ui.styles' );
+               $this->addModuleStyles( array(
+                       'oojs-ui.styles',
+                       'oojs-ui.styles.icons',
+                       'oojs-ui.styles.indicators',
+                       'oojs-ui.styles.textures',
+               ) );
        }
 }