X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoader.php;h=f6f6d1b72a0a0068e993687d8b4601f73ab3d72e;hb=aa00a3e8384a87430f82739507e09bb74c6b40ec;hp=93cc24548e81c4fdf24a3263491113d879e6f59c;hpb=04f27a07a181e903497024a4fdbc2c6d24f974c4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 93cc24548e..f6f6d1b72a 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -646,19 +646,32 @@ class ResourceLoader { // Generate a response $response = $this->makeModuleResponse( $context, $modules, $missing ); - // Prepend comments indicating exceptions - $response = $errors . $response; - // Capture any PHP warnings from the output buffer and append them to the - // response in a comment if we're in debug mode. + // error list if we're in debug mode. if ( $context->getDebug() && strlen( $warnings = ob_get_contents() ) ) { - $response = self::makeComment( $warnings ) . $response; + $errors .= self::makeComment( $warnings ); + $this->hasErrors = true; + } + + if ( $context->getImageObj() && !$response ) { + $errors .= self::makeComment( "Image generation failed." ); $this->hasErrors = true; } + if ( $this->hasErrors ) { + if ( $context->getImageObj() ) { + // Bail, we can't show both the error messages and the response when it's not CSS or JS. + // sendResponseHeaders() will handle this sensibly. + $response = $errors; + } else { + // Prepend comments indicating exceptions + $response = $errors . $response; + } + } + // Save response to file cache unless there are errors - if ( isset( $fileCache ) && !$errors && !count( $missing ) ) { - // Cache single modules...and other requests if there are enough hits + if ( isset( $fileCache ) && !$this->hasErrors && !count( $missing ) ) { + // Cache single modules and images...and other requests if there are enough hits if ( ResourceFileCache::useFileCache( $context ) ) { if ( $fileCache->isCacheWorthy() ) { $fileCache->saveText( $response ); @@ -699,7 +712,13 @@ class ResourceLoader { $maxage = $rlMaxage['versioned']['client']; $smaxage = $rlMaxage['versioned']['server']; } - if ( $context->getOnly() === 'styles' ) { + if ( $context->getImageObj() ) { + if ( $errors ) { + header( 'Content-Type: text/plain; charset=utf-8' ); + } else { + $context->getImageObj()->sendResponseHeaders( $context ); + } + } elseif ( $context->getOnly() === 'styles' ) { header( 'Content-Type: text/css; charset=utf-8' ); header( 'Access-Control-Allow-Origin: *' ); } else { @@ -858,6 +877,13 @@ class ResourceLoader { wfProfileIn( __METHOD__ ); + $image = $context->getImageObj(); + if ( $image ) { + $data = $image->getImageData( $context ); + wfProfileOut( __METHOD__ ); + return $data; + } + // Pre-fetch blobs if ( $context->shouldIncludeMessages() ) { try { @@ -1188,6 +1214,27 @@ class ResourceLoader { ); } + /** + * Remove empty values from the end of an array. + * + * Values considered empty: + * + * - null + * - empty array + * + * @param Array $array + */ + private static function trimArray( Array &$array ) { + $i = count( $array ); + while ( $i-- ) { + if ( $array[$i] === null || $array[$i] === array() ) { + unset( $array[$i] ); + } else { + break; + } + } + } + /** * Returns JS code which calls mw.loader.register with the given * parameters. Has three calling conventions: @@ -1219,16 +1266,37 @@ class ResourceLoader { $dependencies = null, $group = null, $source = null, $skip = null ) { if ( is_array( $name ) ) { + // Build module name index + $index = array(); + foreach ( $name as $i => &$module ) { + $index[$module[0]] = $i; + } + + // Transform dependency names into indexes when possible, they will be resolved by + // mw.loader.register on the other end + foreach ( $name as &$module ) { + if ( isset( $module[2] ) ) { + foreach ( $module[2] as &$dependency ) { + if ( isset( $index[$dependency] ) ) { + $dependency = $index[$dependency]; + } + } + } + } + + array_walk( $name, array( 'self', 'trimArray' ) ); + return Xml::encodeJsCall( 'mw.loader.register', array( $name ), ResourceLoader::inDebugMode() ); } else { - $version = (int) $version; + $registration = array( $name, $version, $dependencies, $group, $source, $skip ); + self::trimArray( $registration ); return Xml::encodeJsCall( 'mw.loader.register', - array( $name, $version, $dependencies, $group, $source, $skip ), + $registration, ResourceLoader::inDebugMode() ); }