Move embedded ResourceLoader modules to the <head>
authorKrinkle <krinkle@users.mediawiki.org>
Wed, 28 Dec 2011 22:20:29 +0000 (22:20 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Wed, 28 Dec 2011 22:20:29 +0000 (22:20 +0000)
* Embed "private" ResourceLoader modules in the <head> before the first loader link, instead of in the <body> after the last loader link
* Wow, was in the opposite place where it should've been :D
* Fixes bug 30914

RELEASE-NOTES-1.19
includes/OutputPage.php
includes/resourceloader/ResourceLoader.php

index 6ea996f..c75295d 100644 (file)
@@ -197,6 +197,8 @@ production.
 * (bug 30711) When adding a new section to a page with section=new, the text is
   now always added to the current version of the page
 * (bug 31719) Recognize &ns_svg; as the svg namespace when extracting width
+* (bug 30914) Embeddable ResourceLoader modules (user.options, user.tokens)
+  should be loaded in <head> for proper dependency resolution
 
 === API changes in 1.19 ===
 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
index 1273a7f..ee11868 100644 (file)
@@ -2575,7 +2575,9 @@ $templates
                                continue;
                        }
 
-                       // Support inlining of private modules if configured as such
+                       // Support inlining of private modules if configured as such. Note that these
+                       // modules should be loaded from getHeadScripts() before the first loader call.
+                       // Otherwise other modules can't properly use them as dependencies (bug 30914)
                        if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) {
                                if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
                                        $links .= Html::inlineStyle(
@@ -2661,6 +2663,10 @@ $templates
                        )
                );
 
+               // Load embeddable private modules before any loader links
+               $embedScripts = array( 'user.options', 'user.tokens' );
+               $scripts .= $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED );
+
                // Script and Messages "only" requests marked for top inclusion
                // Messages should go first
                $scripts .= $this->makeResourceLoaderLink( $this->getModuleMessages( true, 'top' ), ResourceLoaderModule::TYPE_MESSAGES );
@@ -2708,7 +2714,7 @@ $templates
                // Legacy Scripts
                $scripts .= "\n" . $this->mScripts;
 
-               $userScripts = array( 'user.options', 'user.tokens' );
+               $userScripts = array();
 
                // Add site JS if enabled
                if ( $wgUseSiteJs ) {
index 1024ce5..cfc6494 100644 (file)
@@ -913,8 +913,7 @@ class ResourceLoader {
         * @return string
         */
        public static function makeLoaderConditionalScript( $script ) {
-               $script = str_replace( "\n", "\n\t", trim( $script ) );
-               return "if(window.mw){\n\t$script\n}\n";
+               return "if(window.mw){\n".trim( $script )."\n}";
        }
 
        /**