* Map of allowed file extensions to their MIME types.
* @var array
*/
- protected static $fileTypes = array(
+ protected static $fileTypes = [
'svg' => 'image/svg+xml',
'png' => 'image/png',
'gif' => 'image/gif',
'jpg' => 'image/jpg',
- );
+ ];
/**
* @param string $name Image name
}
// Ensure that all files have common extension.
- $extensions = array();
+ $extensions = [];
$descriptor = (array)$descriptor;
array_walk_recursive( $descriptor, function ( $path ) use ( &$extensions ) {
$extensions[] = pathinfo( $path, PATHINFO_EXTENSION );
* @return string
*/
public function getUrl( ResourceLoaderContext $context, $script, $variant, $format ) {
- $query = array(
+ $query = [
'modules' => $this->getModule(),
'image' => $this->getName(),
'variant' => $variant,
'format' => $format,
'lang' => $context->getLanguage(),
'version' => $context->getVersion(),
- );
+ ];
return wfExpandUrl( wfAppendQuery( $script, $query ), PROTO_RELATIVE );
}
*/
protected function variantize( $variantConf, ResourceLoaderContext $context ) {
$dom = new DomDocument;
- $dom->load( $this->getPath( $context ) );
+ $dom->loadXML( file_get_contents( $this->getPath( $context ) ) );
$root = $dom->documentElement;
$wrapper = $dom->createElement( 'g' );
while ( $root->firstChild ) {
}
$root->appendChild( $wrapper );
$wrapper->setAttribute( 'fill', $variantConf['color'] );
- return $dom->saveXml();
+ return $dom->saveXML();
}
/**
*/
protected function massageSvgPathdata( $svg ) {
$dom = new DomDocument;
- $dom->loadXml( $svg );
+ $dom->loadXML( $svg );
foreach ( $dom->getElementsByTagName( 'path' ) as $node ) {
$pathData = $node->getAttribute( 'd' );
// Make sure there is at least one space between numbers, and that leading zero is not omitted.
$pathData = preg_replace( '/([ -])0(\d)/', '$1$2', $pathData );
$node->setAttribute( 'd', $pathData );
}
- return $dom->saveXml();
+ return $dom->saveXML();
}
/**
* @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;
$process = proc_open(
$command,
- array( 0 => array( 'pipe', 'r' ), 1 => array( 'pipe', 'w' ) ),
+ [ 0 => [ 'pipe', 'r' ], 1 => [ 'pipe', 'w' ] ],
$pipes
);