X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderImage.php;h=9d5fe38d2222ec4698d01d0b90e185b5509ac604;hb=a218a56b774ffa5163c0a01f092a12990132c48d;hp=12d1e8279e5fcf7d5c6e66f4b0a5a71fa80b59cf;hpb=6733f81d33a71755428a55f2723f4066a141cbb8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php index 12d1e8279e..9d5fe38d22 100644 --- a/includes/resourceloader/ResourceLoaderImage.php +++ b/includes/resourceloader/ResourceLoaderImage.php @@ -54,15 +54,16 @@ class ResourceLoaderImage { $this->variants = $variants; // Expand shorthands: - // array( "en,de,fr" => "foo.svg" ) → array( "en" => "foo.svg", "de" => "foo.svg", "fr" => "foo.svg" ) + // array( "en,de,fr" => "foo.svg" ) + // → array( "en" => "foo.svg", "de" => "foo.svg", "fr" => "foo.svg" ) if ( is_array( $this->descriptor ) && isset( $this->descriptor['lang'] ) ) { foreach ( array_keys( $this->descriptor['lang'] ) as $langList ) { if ( strpos( $langList, ',' ) !== false ) { $this->descriptor['lang'] += array_fill_keys( explode( ',', $langList ), - $this->descriptor['lang'][ $langList ] + $this->descriptor['lang'][$langList] ); - unset( $this->descriptor['lang'][ $langList ] ); + unset( $this->descriptor['lang'][$langList] ); } } } @@ -75,11 +76,15 @@ class ResourceLoaderImage { } ); $extensions = array_unique( $extensions ); if ( count( $extensions ) !== 1 ) { - throw new InvalidArgumentException( "File type for different image files of '$name' not the same" ); + throw new InvalidArgumentException( + "File type for different image files of '$name' not the same" + ); } $ext = $extensions[0]; if ( !isset( self::$fileTypes[$ext] ) ) { - throw new InvalidArgumentException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)" ); + throw new InvalidArgumentException( + "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)" + ); } $this->extension = $ext; } @@ -117,14 +122,14 @@ class ResourceLoaderImage { * @param ResourceLoaderContext $context Any context * @return string */ - protected function getPath( ResourceLoaderContext $context ) { + public function getPath( ResourceLoaderContext $context ) { $desc = $this->descriptor; if ( is_string( $desc ) ) { return $this->basePath . '/' . $desc; - } elseif ( isset( $desc['lang'][ $context->getLanguage() ] ) ) { - return $this->basePath . '/' . $desc['lang'][ $context->getLanguage() ]; - } elseif ( isset( $desc[ $context->getDirection() ] ) ) { - return $this->basePath . '/' . $desc[ $context->getDirection() ]; + } elseif ( isset( $desc['lang'][$context->getLanguage()] ) ) { + return $this->basePath . '/' . $desc['lang'][$context->getLanguage()]; + } elseif ( isset( $desc[$context->getDirection()] ) ) { + return $this->basePath . '/' . $desc[$context->getDirection()]; } else { return $this->basePath . '/' . $desc['default']; } @@ -310,21 +315,23 @@ class ResourceLoaderImage { * @return string|bool PNG image data, or false on failure */ protected function rasterize( $svg ) { - // This code should be factored out to a separate method on SvgHandler, or perhaps a separate - // class, with a separate set of configuration settings. - // - // This is a distinct use case from regular SVG rasterization: - // * We can skip many sanity and security checks (as the images come from a trusted source, - // rather than from the user). - // * We need to provide extra options to some converters to achieve acceptable quality for very - // small images, which might cause performance issues in the general case. - // * We want to directly pass image data to the converter, rather than a file path. - // - // See https://phabricator.wikimedia.org/T76473#801446 for examples of what happens with the - // default settings. - // - // For now, we special-case rsvg (used in WMF production) and do a messy workaround for other - // converters. + /** + * This code should be factored out to a separate method on SvgHandler, or perhaps a separate + * class, with a separate set of configuration settings. + * + * This is a distinct use case from regular SVG rasterization: + * * We can skip many sanity and security checks (as the images come from a trusted source, + * rather than from the user). + * * We need to provide extra options to some converters to achieve acceptable quality for very + * small images, which might cause performance issues in the general case. + * * We want to directly pass image data to the converter, rather than a file path. + * + * See https://phabricator.wikimedia.org/T76473#801446 for examples of what happens with the + * default settings. + * + * For now, we special-case rsvg (used in WMF production) and do a messy workaround for other + * converters. + */ global $wgSVGConverter, $wgSVGConverterPath;