X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderImage.php;h=c1b3dc34caf0a1dd9254fc9367f024c591b15d3f;hb=6ea72c551abafac831b31d37fd7678b4cdbe1e99;hp=ef116283fc3183b7b8fb51305437908e03ed15b1;hpb=9ef78ab4c18ccb352043b87f371cc0a642f0166c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php index ef116283fc..c1b3dc34ca 100644 --- a/includes/resourceloader/ResourceLoaderImage.php +++ b/includes/resourceloader/ResourceLoaderImage.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\Shell\Shell; + /** * Class encapsulating an image used in a ResourceLoaderImageModule. * @@ -38,6 +40,21 @@ class ResourceLoaderImage { '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 @@ -73,7 +90,7 @@ class ResourceLoaderImage { } // Remove 'deprecated' key if ( is_array( $this->descriptor ) ) { - unset( $this->descriptor[ 'deprecated' ] ); + unset( $this->descriptor['deprecated'] ); } // Ensure that all files have common extension. @@ -129,6 +146,7 @@ class ResourceLoaderImage { * * @param ResourceLoaderContext $context Any context * @return string + * @throws MWException If no matching path is found */ public function getPath( ResourceLoaderContext $context ) { $desc = $this->descriptor; @@ -150,7 +168,11 @@ class ResourceLoaderImage { if ( isset( $desc[$context->getDirection()] ) ) { return $this->basePath . '/' . $desc[$context->getDirection()]; } - return $this->basePath . '/' . $desc['default']; + if ( isset( $desc['default'] ) ) { + return $this->basePath . '/' . $desc['default']; + } else { + throw new MWException( 'No matching path found' ); + } } /** @@ -295,9 +317,20 @@ class ResourceLoaderImage { $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 `` root node to the `` 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 `` node + $titleNode = $node; + } + $wrapper->appendChild( $node ); + } + if ( $titleNode ) { + // Reattach the `` node to the `<svg>` root node rather than the `<g>` wrapper + $root->appendChild( $titleNode ); } $root->appendChild( $wrapper ); $wrapper->setAttribute( 'fill', $variantConf['color'] ); @@ -362,7 +395,7 @@ class ResourceLoaderImage { if ( strpos( $wgSVGConverter, 'rsvg' ) === 0 ) { $command = 'rsvg-convert'; if ( $wgSVGConverterPath ) { - $command = wfEscapeShellArg( "$wgSVGConverterPath/" ) . $command; + $command = Shell::escape( "$wgSVGConverterPath/" ) . $command; } $process = proc_open(