X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderImage.php;h=6497543f564d9aa518983393584709cc6d0d59d6;hb=ab2e77bb5d228683c2458bcec16559ac10cd2c01;hp=c1b3dc34caf0a1dd9254fc9367f024c591b15d3f;hpb=2e0cf0891444367942677692cf8efde87f19c3ef;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php index c1b3dc34ca..6497543f56 100644 --- a/includes/resourceloader/ResourceLoaderImage.php +++ b/includes/resourceloader/ResourceLoaderImage.php @@ -95,9 +95,9 @@ class ResourceLoaderImage { // Ensure that all files have common extension. $extensions = []; - $descriptor = (array)$this->descriptor; + $descriptor = is_array( $this->descriptor ) ? $this->descriptor : [ $this->descriptor ]; array_walk_recursive( $descriptor, function ( $path ) use ( &$extensions ) { - $extensions[] = pathinfo( $path, PATHINFO_EXTENSION ); + $extensions[] = pathinfo( $this->getLocalPath( $path ), PATHINFO_EXTENSION ); } ); $extensions = array_unique( $extensions ); if ( count( $extensions ) !== 1 ) { @@ -150,31 +150,43 @@ class ResourceLoaderImage { */ public function getPath( ResourceLoaderContext $context ) { $desc = $this->descriptor; - if ( is_string( $desc ) ) { - return $this->basePath . '/' . $desc; + if ( !is_array( $desc ) ) { + return $this->getLocalPath( $desc ); } if ( isset( $desc['lang'] ) ) { $contextLang = $context->getLanguage(); if ( isset( $desc['lang'][$contextLang] ) ) { - return $this->basePath . '/' . $desc['lang'][$contextLang]; + return $this->getLocalPath( $desc['lang'][$contextLang] ); } $fallbacks = Language::getFallbacksFor( $contextLang, Language::STRICT_FALLBACKS ); foreach ( $fallbacks as $lang ) { if ( isset( $desc['lang'][$lang] ) ) { - return $this->basePath . '/' . $desc['lang'][$lang]; + return $this->getLocalPath( $desc['lang'][$lang] ); } } } if ( isset( $desc[$context->getDirection()] ) ) { - return $this->basePath . '/' . $desc[$context->getDirection()]; + return $this->getLocalPath( $desc[$context->getDirection()] ); } if ( isset( $desc['default'] ) ) { - return $this->basePath . '/' . $desc['default']; + return $this->getLocalPath( $desc['default'] ); } else { throw new MWException( 'No matching path found' ); } } + /** + * @param string|ResourceLoaderFilePath $path + * @return string + */ + protected function getLocalPath( $path ) { + if ( $path instanceof ResourceLoaderFilePath ) { + return $path->getLocalPath(); + } + + return "{$this->basePath}/$path"; + } + /** * Get the extension of the image. * @@ -214,10 +226,13 @@ class ResourceLoaderImage { 'image' => $this->getName(), 'variant' => $variant, 'format' => $format, - 'lang' => $context->getLanguage(), - 'skin' => $context->getSkin(), - 'version' => $context->getVersion(), ]; + if ( $this->varyOnLanguage() ) { + $query['lang'] = $context->getLanguage(); + } + // The following parameters are at the end to keep the original order of the parameters. + $query['skin'] = $context->getSkin(); + $query['version'] = $context->getVersion(); return wfAppendQuery( $script, $query ); } @@ -422,7 +437,8 @@ class ResourceLoaderImage { file_put_contents( $tempFilenameSvg, $svg ); - $metadata = SVGMetadataExtractor::getMetadata( $tempFilenameSvg ); + $svgReader = new SVGReader( $tempFilenameSvg ); + $metadata = $svgReader->getMetadata(); if ( !isset( $metadata['width'] ) || !isset( $metadata['height'] ) ) { unlink( $tempFilenameSvg ); return false; @@ -446,4 +462,16 @@ class ResourceLoaderImage { return $png ?: false; } } + + /** + * Check if the image depends on the language. + * + * @return bool + */ + private function varyOnLanguage() { + return is_array( $this->descriptor ) && ( + isset( $this->descriptor['ltr'] ) || + isset( $this->descriptor['rtl'] ) || + isset( $this->descriptor['lang'] ) ); + } }