// 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 ) {
*/
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.
*
'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 );
}
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;
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'] ) );
+ }
}