testPngNativetZtxt requires zlib extension
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 6705863..5abe226 100644 (file)
@@ -176,6 +176,7 @@ class ResourceLoader {
                } catch ( Exception $exception ) {
                        // Return exception as a comment
                        $result = $this->makeComment( $exception->__toString() );
+                       $this->hasErrors = true;
                }
 
                wfProfileOut( __METHOD__ );
@@ -347,7 +348,7 @@ class ResourceLoader {
                return array_keys( $this->moduleInfos );
        }
 
-       /**
+       /**
         * Get a list of test module names for one (or all) frameworks.
         * If the given framework id is unknkown, or if the in-object variable is not an array,
         * then it will return an empty array.
@@ -435,6 +436,7 @@ class ResourceLoader {
 
                wfProfileIn( __METHOD__ );
                $errors = '';
+               $this->hasErrors = false;
 
                // Split requested modules into two groups, modules and missing
                $modules = array();
@@ -446,6 +448,7 @@ class ResourceLoader {
                                // This is a security issue, see bug 34907.
                                if ( $module->getGroup() === 'private' ) {
                                        $errors .= $this->makeComment( "Cannot show private module \"$name\"" );
+                                       $this->hasErrors = true;
                                        continue;
                                }
                                $modules[$name] = $this->getModule( $name );
@@ -460,6 +463,7 @@ class ResourceLoader {
                } catch( Exception $e ) {
                        // Add exception to the output as a comment
                        $errors .= $this->makeComment( $e->__toString() );
+                       $this->hasErrors = true;
                }
 
                wfProfileIn( __METHOD__.'-getModifiedTime' );
@@ -477,14 +481,12 @@ class ResourceLoader {
                        } catch ( Exception $e ) {
                                // Add exception to the output as a comment
                                $errors .= $this->makeComment( $e->__toString() );
+                               $this->hasErrors = true;
                        }
                }
 
                wfProfileOut( __METHOD__.'-getModifiedTime' );
 
-               // Send content type and cache related headers
-               $this->sendResponseHeaders( $context, $mtime );
-
                // If there's an If-Modified-Since header, respond with a 304 appropriately
                if ( $this->tryRespondLastModified( $context, $mtime ) ) {
                        wfProfileOut( __METHOD__ );
@@ -501,6 +503,7 @@ class ResourceLoader {
                // response in a comment if we're in debug mode.
                if ( $context->getDebug() && strlen( $warnings = ob_get_contents() ) ) {
                        $response = $this->makeComment( $warnings ) . $response;
+                       $this->hasErrors = true;
                }
 
                // Save response to file cache unless there are errors
@@ -515,6 +518,9 @@ class ResourceLoader {
                        }
                }
 
+               // Send content type and cache related headers
+               $this->sendResponseHeaders( $context, $mtime, $this->hasErrors );
+
                // Remove the output buffer and output the response
                ob_end_clean();
                echo $response;
@@ -526,13 +532,15 @@ class ResourceLoader {
         * Send content type and last modified headers to the client.
         * @param $context ResourceLoaderContext
         * @param $mtime string TS_MW timestamp to use for last-modified
+        * @param $error bool Whether there are commented-out errors in the response
         * @return void
         */
-       protected function sendResponseHeaders( ResourceLoaderContext $context, $mtime ) {
+       protected function sendResponseHeaders( ResourceLoaderContext $context, $mtime, $errors ) {
                global $wgResourceLoaderMaxage;
                // If a version wasn't specified we need a shorter expiry time for updates
                // to propagate to clients quickly
-               if ( is_null( $context->getVersion() ) ) {
+               // If there were errors, we also need a shorter expiry time so we can recover quickly
+               if ( is_null( $context->getVersion() ) || $errors ) {
                        $maxage  = $wgResourceLoaderMaxage['unversioned']['client'];
                        $smaxage = $wgResourceLoaderMaxage['unversioned']['server'];
                // If a version was specified we can use a longer expiry time since changing
@@ -680,6 +688,7 @@ class ResourceLoader {
                        } catch ( Exception $e ) {
                                // Add exception to the output as a comment
                                $exceptions .= $this->makeComment( $e->__toString() );
+                               $this->hasErrors = true;
                        }
                } else {
                        $blobs = array();
@@ -785,6 +794,7 @@ class ResourceLoader {
                        } catch ( Exception $e ) {
                                // Add exception to the output as a comment
                                $exceptions .= $this->makeComment( $e->__toString() );
+                               $this->hasErrors = true;
 
                                // Register module as missing
                                $missing[] = $name;