(bug 26283) Previewing user JS/CSS pages doesn't load other user JS/CSS pages
authorRoan Kattouw <catrope@users.mediawiki.org>
Sat, 13 Aug 2011 17:27:35 +0000 (17:27 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sat, 13 Aug 2011 17:27:35 +0000 (17:27 +0000)
RELEASE-NOTES-1.19
includes/OutputPage.php
includes/resourceloader/ResourceLoaderUserModule.php

index 1723976..3c994bf 100644 (file)
@@ -44,6 +44,7 @@ production.
 * (bug 30264) Changed installer-generated LocalSettings.php to use require_once()
   instead require() for included extensions.
 * Do not convert text in the user interface language to another script.
+* (bug 26283) Previewing user JS/CSS pages doesn't load other user JS/CSS pages
 
 === API changes in 1.19 ===
 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
index 2f705e5..75272a2 100644 (file)
@@ -2347,19 +2347,20 @@ $templates
 
        /**
         * TODO: Document
-        * @param $modules Array/string with the module name
+        * @param $modules Array/string with the module name(s)
         * @param $only String ResourceLoaderModule TYPE_ class constant
         * @param $useESI boolean
+        * @param $extraQuery Array with extra query parameters to add to each request. array( param => value )
         * @return string html <script> and <style> tags
         */
-       protected function makeResourceLoaderLink( $modules, $only, $useESI = false ) {
+       protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array() ) {
                global $wgLoadScript, $wgResourceLoaderUseESI,
                        $wgResourceLoaderInlinePrivateModules;
                $baseQuery = array(
                        'lang' => $this->getContext()->getLang()->getCode(),
                        'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
                        'skin' => $this->getSkin()->getSkinName(),
-               );
+               ) + $extraQuery;
                if ( $only !== ResourceLoaderModule::TYPE_COMBINED ) {
                        $baseQuery['only'] = $only;
                }
@@ -2577,11 +2578,15 @@ $templates
                if ( $wgAllowUserJs && $this->getUser()->isLoggedIn() ) {
                        if( $this->getTitle() && $this->getTitle()->isJsSubpage() && $this->userCanPreview() ) {
                                # XXX: additional security check/prompt?
+                               // We're on a preview of a JS subpage
+                               // Exclude this page from the user module in case it's in there (bug 26283)
+                               $scripts .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_SCRIPTS, false,
+                                       array( 'excludepage' => $this->getTitle()->getPrefixedText() )
+                               );
+                               // Load the previewed JS
                                $scripts .= Html::inlineScript( "\n" . $this->getRequest()->getText( 'wpTextbox1' ) . "\n" ) . "\n";
                        } else {
-                               # @todo FIXME: This means that User:Me/Common.js doesn't load when previewing
-                               # User:Me/Vector.js, and vice versa (bug 26283)
-                               
+                               // Include the user module normally
                                // We can't do $userScripts[] = 'user'; because the user module would end up
                                // being wrapped in a closure, so load it raw like 'site'
                                $scripts .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_SCRIPTS );
@@ -2961,6 +2966,7 @@ $templates
                // Add ResourceLoader styles
                // Split the styles into four groups
                $styles = array( 'other' => array(), 'user' => array(), 'site' => array(), 'private' => array(), 'noscript' => array() );
+               $otherTags = ''; // Tags to append after the normal <link> tags
                $resourceLoader = $this->getResourceLoader();
 
                $moduleStyles = $this->getModuleStyles();
@@ -2977,9 +2983,15 @@ $templates
                // Per-user custom styles
                if ( $wgAllowUserCss ) {
                        if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview() ) {
-                               // @todo FIXME: Properly escape the cdata!
-                               $this->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
+                               // We're on a preview of a CSS subpage
+                               // Exclude this page from the user module in case it's in there (bug 26283)
+                               $otherTags .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_STYLES, false,
+                                       array( 'excludepage' => $this->getTitle()->getPrefixedText() )
+                               );
+                               // Load the previewed CSS
+                               $otherTags .= Html::inlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );;
                        } else {
+                               // Load the user styles normally
                                $moduleStyles[] = 'user';
                        }
                }
@@ -3015,6 +3027,9 @@ $templates
                                        ResourceLoaderModule::TYPE_STYLES
                        );
                }
+               
+               // Add stuff in $otherTags (previewed user CSS if applicable)
+               $ret .= $otherTags;
                return $ret;
        }
 
index 892e846..e70aa51 100644 (file)
@@ -35,7 +35,7 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
        protected function getPages( ResourceLoaderContext $context ) {
                if ( $context->getUser() ) {
                        $username = $context->getUser();
-                       return array(
+                       $pages = array(
                                "User:$username/common.js" => array( 'type' => 'script' ),
                                "User:$username/" . $context->getSkin() . '.js' => 
                                        array( 'type' => 'script' ),
@@ -43,6 +43,15 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
                                "User:$username/" . $context->getSkin() . '.css' => 
                                        array( 'type' => 'style' ),
                        );
+                       
+                       // Hack for bug 26283: if we're on a preview page for a CSS/JS page,
+                       // we need to exclude that page from this module. In that case, the excludepage
+                       // parameter will be set to the name of the page we need to exclude.
+                       $excludepage = $context->getRequest()->getVal( 'excludepage' );
+                       if ( isset( $pages[$excludepage] ) ) {
+                               unset( $pages[$excludepage] );
+                       }
+                       return $pages;
                }
                return array();
        }