Revision: 43655
Author:   aaron
Date:     2008-11-18 01:18:12 +0000 (Tue, 18 Nov 2008)

Log Message:
-----------
Refactor SvgHandler to have transformSvgToPng() function, which can be used for 
non-thumbnail purposes

Modified Paths:
--------------
    trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
    trunk/phase3/includes/media/SVG.php

Modified: trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
===================================================================
--- trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php    
2008-11-18 00:56:43 UTC (rev 43654)
+++ trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php    
2008-11-18 01:18:12 UTC (rev 43655)
@@ -500,25 +500,10 @@
                @fwrite( $fp, $plot->svg );
                @fclose( $fp );
                // Rasterize due to IE suckage
-               global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath;
-               if( !isset( $wgSVGConverters[$wgSVGConverter] ) ) {
-                       return false; // this shouldn't happen
-               }
+               $svgHandler = new SvgHandler();
                $dstPath = preg_replace( '/\.svg$/','.png', $filePath );
-               $err = false;
-               $cmd = str_replace(
-                               array( '$path/', '$width', '$height', '$input', 
'$output' ),
-                               array( $wgSVGConverterPath ? wfEscapeShellArg( 
"$wgSVGConverterPath/" ) : "",
-                                       1000,
-                                       410,
-                                       wfEscapeShellArg( $filePath ),
-                                       wfEscapeShellArg( $dstPath ) 
-                               ),
-                               $wgSVGConverters[$wgSVGConverter] 
-                       ) . " 2>&1";
-               $err = wfShellExec( $cmd, $retval );
-               if( $retval != 0 ) {
-                       throw new MWException( $err );
+               $status = $svgHandler->transformSvgToPng( $filePath, $dstPath, 
1000, 410 );
+               if( $status !== true ) {
                        return false;
                }
                return true;

Modified: trunk/phase3/includes/media/SVG.php
===================================================================
--- trunk/phase3/includes/media/SVG.php 2008-11-18 00:56:43 UTC (rev 43654)
+++ trunk/phase3/includes/media/SVG.php 2008-11-18 01:18:12 UTC (rev 43655)
@@ -27,7 +27,6 @@
                if ( !parent::normaliseParams( $image, $params ) ) {
                        return false;
                }
-
                # Don't make an image bigger than wgMaxSVGSize
                $params['physicalWidth'] = $params['width'];
                $params['physicalHeight'] = $params['height'];
@@ -60,32 +59,49 @@
                        return new MediaTransformError( 'thumbnail_error', 
$clientWidth, $clientHeight,
                                wfMsg( 'thumbnail_dest_directory' ) );
                }
-
+               
+               $status = $this->transformSvgToPng( $srcPath, $dstPath, 
$physicalWidth, $physicalHeight );
+               if( $status === true ) {
+                       return new ThumbnailImage( $image, $dstUrl, 
$clientWidth, $clientHeight, $dstPath );
+               } else {
+                       return $status; // MediaTransformError
+               }
+       }
+       
+       /*
+       * Transform an SVG file to PNG
+       * This function can be called outside of thumbnail contexts
+       * @param string $srcPath
+       * @param string $dstPath
+       * @param string $width
+       * @param string $height
+       * @returns TRUE/MediaTransformError
+       */
+       public function transformSvgToPng( $srcPath, $dstPath, $width, $height 
) {
+               global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath;
                $err = false;
-               if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
+               if ( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
                        $cmd = str_replace(
                                array( '$path/', '$width', '$height', '$input', 
'$output' ),
                                array( $wgSVGConverterPath ? wfEscapeShellArg( 
"$wgSVGConverterPath/" ) : "",
-                                          intval( $physicalWidth ),
-                                          intval( $physicalHeight ),
+                                          intval( $width ),
+                                          intval( $height ),
                                           wfEscapeShellArg( $srcPath ),
                                           wfEscapeShellArg( $dstPath ) ),
-                               $wgSVGConverters[$wgSVGConverter] ) . " 2>&1";
+                               $wgSVGConverters[$wgSVGConverter]
+                       ) . " 2>&1";
                        wfProfileIn( 'rsvg' );
                        wfDebug( __METHOD__.": $cmd\n" );
                        $err = wfShellExec( $cmd, $retval );
                        wfProfileOut( 'rsvg' );
                }
-
                $removed = $this->removeBadFile( $dstPath, $retval );
                if ( $retval != 0 || $removed ) {
-                       wfDebugLog( 'thumbnail',
-                               sprintf( 'thumbnail failed on %s: error %d "%s" 
from "%s"',
+                       wfDebugLog( 'thumbnail', sprintf( 'thumbnail failed on 
%s: error %d "%s" from "%s"',
                                        wfHostname(), $retval, trim($err), $cmd 
) );
                        return new MediaTransformError( 'thumbnail_error', 
$clientWidth, $clientHeight, $err );
-               } else {
-                       return new ThumbnailImage( $image, $dstUrl, 
$clientWidth, $clientHeight, $dstPath );
                }
+               return true;
        }
 
        function getImageSize( $image, $path ) {



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to