Fix regression in even sizing of diff columns; forgot to restore a couple bits I...
[mediawiki.git] / includes / media / SVG.php
blob2dfbd02e24cb6cce4ad5755f81ca55c9e3a6c040
1 <?php
3 /**
4 * @addtogroup Media
5 */
6 class SvgHandler extends ImageHandler {
7 function isEnabled() {
8 global $wgSVGConverters, $wgSVGConverter;
9 if ( !isset( $wgSVGConverters[$wgSVGConverter] ) ) {
10 wfDebug( "\$wgSVGConverter is invalid, disabling SVG rendering.\n" );
11 return false;
12 } else {
13 return true;
17 function mustRender() {
18 return true;
21 function normaliseParams( $image, &$params ) {
22 global $wgSVGMaxSize;
23 if ( !parent::normaliseParams( $image, $params ) ) {
24 return false;
27 # Don't make an image bigger than wgMaxSVGSize
28 $params['physicalWidth'] = $params['width'];
29 $params['physicalHeight'] = $params['height'];
30 if ( $params['physicalWidth'] > $wgSVGMaxSize ) {
31 $srcWidth = $image->getWidth( $params['page'] );
32 $srcHeight = $image->getHeight( $params['page'] );
33 $params['physicalWidth'] = $wgSVGMaxSize;
34 $params['physicalHeight'] = Image::scaleHeight( $srcWidth, $srcHeight, $wgSVGMaxSize );
36 return true;
39 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
40 global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath;
42 if ( !$this->normaliseParams( $image, $params ) ) {
43 return new TransformParameterError( $params );
45 $clientWidth = $params['width'];
46 $clientHeight = $params['height'];
47 $physicalWidth = $params['physicalWidth'];
48 $physicalHeight = $params['physicalHeight'];
49 $srcPath = $image->getImagePath();
51 if ( $flags & self::TRANSFORM_LATER ) {
52 return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight, $dstPath );
55 if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
56 return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
57 wfMsg( 'thumbnail_dest_directory' ) );
60 $err = false;
61 if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
62 $cmd = str_replace(
63 array( '$path/', '$width', '$height', '$input', '$output' ),
64 array( $wgSVGConverterPath ? wfEscapeShellArg( "$wgSVGConverterPath/" ) : "",
65 intval( $physicalWidth ),
66 intval( $physicalHeight ),
67 wfEscapeShellArg( $srcPath ),
68 wfEscapeShellArg( $dstPath ) ),
69 $wgSVGConverters[$wgSVGConverter] ) . " 2>&1";
70 wfProfileIn( 'rsvg' );
71 wfDebug( __METHOD__.": $cmd\n" );
72 $err = wfShellExec( $cmd, $retval );
73 wfProfileOut( 'rsvg' );
76 $removed = $this->removeBadFile( $dstPath, $retval );
77 if ( $retval != 0 || $removed ) {
78 wfDebugLog( 'thumbnail',
79 sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
80 wfHostname(), $retval, trim($err), $cmd ) );
81 return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err );
82 } else {
83 return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight, $dstPath );
87 function getImageSize( $image, $path ) {
88 return wfGetSVGsize( $path );
91 function getThumbType( $ext, $mime ) {
92 return array( 'png', 'image/png' );