Merge "ApiQueryAllUsers: Set 'array' type on result arrays"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index ce1fd82..ce18c32 100644 (file)
@@ -72,6 +72,11 @@ class ResourceLoader {
         */
        protected $errors = array();
 
+       /**
+        * @var MessageBlobStore
+        */
+       protected $blobStore;
+
        /**
         * Load information stored in the database about modules.
         *
@@ -250,6 +255,7 @@ class ResourceLoader {
                        $this->registerTestModules();
                }
 
+               $this->setMessageBlobStore( new MessageBlobStore() );
        }
 
        /**
@@ -259,6 +265,14 @@ class ResourceLoader {
                return $this->config;
        }
 
+       /**
+        * @param MessageBlobStore $blobStore
+        * @since 1.25
+        */
+       public function setMessageBlobStore( MessageBlobStore $blobStore ) {
+               $this->blobStore = $blobStore;
+       }
+
        /**
         * Register a module with the ResourceLoader system.
         *
@@ -325,19 +339,16 @@ class ResourceLoader {
                                        } elseif ( isset( $skinStyles['+' . $name] ) ) {
                                                $paths = (array)$skinStyles['+' . $name];
                                                $styleFiles = isset( $this->moduleInfos[$name]['skinStyles']['default'] ) ?
-                                                       $this->moduleInfos[$name]['skinStyles']['default'] :
+                                                       (array)$this->moduleInfos[$name]['skinStyles']['default'] :
                                                        array();
                                        } else {
                                                continue;
                                        }
 
                                        // Add new file paths, remapping them to refer to our directories and not use settings
-                                       // from the module we're modifying. These can come from the base definition or be defined
-                                       // for each module.
+                                       // from the module we're modifying, which come from the base definition.
                                        list( $localBasePath, $remoteBasePath ) =
                                                ResourceLoaderFileModule::extractBasePaths( $skinStyles );
-                                       list( $localBasePath, $remoteBasePath ) =
-                                               ResourceLoaderFileModule::extractBasePaths( $paths, $localBasePath, $remoteBasePath );
 
                                        foreach ( $paths as $path ) {
                                                $styleFiles[] = new ResourceLoaderFilePath( $path, $localBasePath, $remoteBasePath );
@@ -753,6 +764,9 @@ class ResourceLoader {
 
                                header( 'HTTP/1.0 304 Not Modified' );
                                header( 'Status: 304 Not Modified' );
+
+                               // Send content type and cache headers
+                               $this->sendResponseHeaders( $context, $mtime, false );
                                return true;
                        }
                }
@@ -787,18 +801,18 @@ class ResourceLoader {
                }
                if ( $good ) {
                        $ts = $fileCache->cacheTimestamp();
-                       // Send content type and cache headers
-                       $this->sendResponseHeaders( $context, $ts, false );
                        // If there's an If-Modified-Since header, respond with a 304 appropriately
                        if ( $this->tryRespondLastModified( $context, $ts ) ) {
                                return false; // output handled (buffers cleared)
                        }
-                       $response = $fileCache->fetchText();
                        // Capture any PHP warnings from the output buffer and append them to the
                        // response in a comment if we're in debug mode.
                        if ( $context->getDebug() && strlen( $warnings = ob_get_contents() ) ) {
                                $response = "/*\n$warnings\n*/\n" . $response;
                        }
+                       // Send content type and cache headers
+                       $this->sendResponseHeaders( $context, $ts, false );
+                       $response = $fileCache->fetchText();
                        // Remove the output buffer and output the response
                        ob_end_clean();
                        echo $response . "\n/* Cached {$ts} */";
@@ -885,7 +899,7 @@ MESSAGE;
                // Pre-fetch blobs
                if ( $context->shouldIncludeMessages() ) {
                        try {
-                               $blobs = MessageBlobStore::getInstance()->get( $this, $modules, $context->getLanguage() );
+                               $blobs = $this->blobStore->get( $this, $modules, $context->getLanguage() );
                        } catch ( Exception $e ) {
                                MWExceptionHandler::logException( $e );
                                wfDebugLog(
@@ -1335,6 +1349,7 @@ MESSAGE;
         * Returns JS code which runs given JS code if the client-side framework is
         * present.
         *
+        * @deprecated since 1.25; use makeInlineScript instead
         * @param string $script JavaScript code
         * @return string
         */
@@ -1342,6 +1357,20 @@ MESSAGE;
                return "if(window.mw){\n" . trim( $script ) . "\n}";
        }
 
+       /**
+        * Construct an inline script tag with given JS code.
+        *
+        * The code will be wrapped in a closure, and it will be executed by ResourceLoader
+        * only if the client has adequate support for MediaWiki JavaScript code.
+        *
+        * @param string $script JavaScript code
+        * @return string HTML
+        */
+       public static function makeInlineScript( $script ) {
+               $js = self::makeLoaderConditionalScript( $script );
+               return Html::inlineScript( $js );
+       }
+
        /**
         * Returns JS code which will set the MediaWiki configuration array to
         * the given value.