From b9b85843572bf283f48285001e276ba7e61b63f6 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 22 Feb 2009 13:37:51 +0100 Subject: updated to MediaWiki 1.14.0 --- includes/media/BMP.php | 9 ++++++++ includes/media/Bitmap.php | 36 ++++++++++++++++++++++++-------- includes/media/Bitmap_ClientOnly.php | 15 ++++++++++++++ includes/media/Generic.php | 15 ++++++++++++++ includes/media/SVG.php | 40 +++++++++++++++++++++++++----------- 5 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 includes/media/Bitmap_ClientOnly.php (limited to 'includes/media') diff --git a/includes/media/BMP.php b/includes/media/BMP.php index ce1b0362..39b29744 100644 --- a/includes/media/BMP.php +++ b/includes/media/BMP.php @@ -11,6 +11,15 @@ * @ingroup Media */ class BmpHandler extends BitmapHandler { + // We never want to use .bmp in an tag + function mustRender( $file ) { + return true; + } + + // Render files as PNG + function getThumbType( $text, $mime ) { + return array( 'png', 'image/png' ); + } /* * Get width and height from the bmp header. diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index e01386e9..b949ae3d 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -41,9 +41,10 @@ class BitmapHandler extends ImageHandler { } function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { - global $wgUseImageMagick, $wgImageMagickConvertCommand; + global $wgUseImageMagick, $wgImageMagickConvertCommand, $wgImageMagickTempDir; global $wgCustomConvertCommand; global $wgSharpenParameter, $wgSharpenReductionThreshold; + global $wgMaxAnimatedGifArea; if ( !$this->normaliseParams( $image, $params ) ) { return new TransformParameterError( $params ); @@ -59,7 +60,7 @@ class BitmapHandler extends ImageHandler { $retval = 0; wfDebug( __METHOD__.": creating {$physicalWidth}x{$physicalHeight} thumbnail at $dstPath\n" ); - if ( $physicalWidth == $srcWidth && $physicalHeight == $srcHeight ) { + if ( !$image->mustRender() && $physicalWidth == $srcWidth && $physicalHeight == $srcHeight ) { # normaliseParams (or the user) wants us to return the unscaled image wfDebug( __METHOD__.": returning unscaled image\n" ); return new ThumbnailImage( $image, $image->getURL(), $clientWidth, $clientHeight, $srcPath ); @@ -77,6 +78,7 @@ class BitmapHandler extends ImageHandler { } else { $scaler = 'client'; } + wfDebug( __METHOD__.": scaler $scaler\n" ); if ( $scaler == 'client' ) { # Client-side image scaling, use the source URL @@ -85,18 +87,22 @@ class BitmapHandler extends ImageHandler { } if ( $flags & self::TRANSFORM_LATER ) { + wfDebug( __METHOD__.": Transforming later per flags.\n" ); return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); } if ( !wfMkdirParents( dirname( $dstPath ) ) ) { - wfDebug( "Unable to create thumbnail destination directory, falling back to client scaling\n" ); + wfDebug( __METHOD__.": Unable to create thumbnail destination directory, falling back to client scaling\n" ); return new ThumbnailImage( $image, $image->getURL(), $clientWidth, $clientHeight, $srcPath ); } if ( $scaler == 'im' ) { # use ImageMagick + $quality = ''; $sharpen = ''; + $frame = ''; + $animation = ''; if ( $mimeType == 'image/jpeg' ) { $quality = "-quality 80"; // 80% # Sharpening, see bug 6193 @@ -105,8 +111,21 @@ class BitmapHandler extends ImageHandler { } } elseif ( $mimeType == 'image/png' ) { $quality = "-quality 95"; // zlib 9, adaptive filtering + } elseif( $mimeType == 'image/gif' ) { + if( $srcWidth * $srcHeight > $wgMaxAnimatedGifArea ) { + // Extract initial frame only; we're so big it'll + // be a total drag. :P + $frame = '[0]'; + } else { + // Coalesce is needed to scale animated GIFs properly (bug 1017). + $animation = ' -coalesce '; + } + } + + if ( strval( $wgImageMagickTempDir ) !== '' ) { + $tempEnv = 'MAGICK_TMPDIR=' . wfEscapeShellArg( $wgImageMagickTempDir ) . ' '; } else { - $quality = ''; // default + $tempEnv = ''; } # Specify white background color, will be used for transparent images @@ -116,11 +135,12 @@ class BitmapHandler extends ImageHandler { # It seems that ImageMagick has a bug wherein it produces thumbnails of # the wrong size in the second case. - $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) . + $cmd = + $tempEnv . + wfEscapeShellArg($wgImageMagickConvertCommand) . " {$quality} -background white -size {$physicalWidth} ". - wfEscapeShellArg($srcPath) . - // Coalesce is needed to scale animated GIFs properly (bug 1017). - ' -coalesce ' . + wfEscapeShellArg($srcPath . $frame) . + $animation . // For the -resize option a "!" is needed to force exact size, // or ImageMagick may decide your ratio is wrong and slice off // a pixel. diff --git a/includes/media/Bitmap_ClientOnly.php b/includes/media/Bitmap_ClientOnly.php new file mode 100644 index 00000000..9801f9be --- /dev/null +++ b/includes/media/Bitmap_ClientOnly.php @@ -0,0 +1,15 @@ +normaliseParams( $image, $params ) ) { + return new TransformParameterError( $params ); + } + return new ThumbnailImage( $image, $image->getURL(), $params['width'], + $params['height'], $image->getPath() ); + } +} diff --git a/includes/media/Generic.php b/includes/media/Generic.php index b2cb70f6..a9c681e1 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -239,6 +239,21 @@ abstract class MediaHandler { $sk->formatSize( $file->getSize() ), $file->getMimeType() ); } + + static function getGeneralShortDesc( $file ) { + global $wgLang; + $nbytes = '(' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), + $wgLang->formatNum( $file->getSize() ) ) . ')'; + return "$nbytes"; + } + + static function getGeneralLongDesc( $file ) { + global $wgUser; + $sk = $wgUser->getSkin(); + return wfMsgExt( 'file-info', 'parseinline', + $sk->formatSize( $file->getSize() ), + $file->getMimeType() ); + } function getDimensionsString( $file ) { return ''; diff --git a/includes/media/SVG.php b/includes/media/SVG.php index 2604e3b4..f0519e89 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -27,7 +27,6 @@ class SvgHandler extends ImageHandler { 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 @@ class SvgHandler extends ImageHandler { return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, wfMsg( 'thumbnail_dest_directory' ) ); } - + + $status = $this->rasterize( $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 rasterize( $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 new MediaTransformError( 'thumbnail_error', $width, $height, $err ); } + return true; } function getImageSize( $image, $path ) { -- cgit v1.2.2