* @file
*/
+use MediaWiki\Shell\Shell;
+
/**
* Class encapsulating an image used in a ResourceLoaderImageModule.
*
'jpg' => 'image/jpg',
];
+ /** @var string */
+ private $name;
+ /** @var string */
+ private $module;
+ /** @var string|array */
+ private $descriptor;
+ /** @var string */
+ private $basePath;
+ /** @var array */
+ private $variants;
+ /** @var string|null */
+ private $defaultColor;
+ /** @var string */
+ private $extension;
+
/**
* @param string $name Image name
* @param string $module Module name
}
// Remove 'deprecated' key
if ( is_array( $this->descriptor ) ) {
- unset( $this->descriptor[ 'deprecated' ] );
+ unset( $this->descriptor['deprecated'] );
}
// Ensure that all files have common extension.
$dom = new DOMDocument;
$dom->loadXML( file_get_contents( $this->getPath( $context ) ) );
$root = $dom->documentElement;
- $wrapper = $dom->createElement( 'g' );
+ $titleNode = null;
+ $wrapper = $dom->createElementNS( 'http://www.w3.org/2000/svg', 'g' );
+ // Reattach all direct children of the `<svg>` root node to the `<g>` wrapper
while ( $root->firstChild ) {
- $wrapper->appendChild( $root->firstChild );
+ $node = $root->firstChild;
+ if ( !$titleNode && $node->nodeType === XML_ELEMENT_NODE && $node->tagName === 'title' ) {
+ // Remember the first encountered `<title>` node
+ $titleNode = $node;
+ }
+ $wrapper->appendChild( $node );
+ }
+ if ( $titleNode ) {
+ // Reattach the `<title>` node to the `<svg>` root node rather than the `<g>` wrapper
+ $root->appendChild( $titleNode );
}
$root->appendChild( $wrapper );
$wrapper->setAttribute( 'fill', $variantConf['color'] );
if ( strpos( $wgSVGConverter, 'rsvg' ) === 0 ) {
$command = 'rsvg-convert';
if ( $wgSVGConverterPath ) {
- $command = wfEscapeShellArg( "$wgSVGConverterPath/" ) . $command;
+ $command = Shell::escape( "$wgSVGConverterPath/" ) . $command;
}
$process = proc_open(