From 9db190c7e736ec8d063187d4241b59feaf7dc2d1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 22 Jun 2011 11:28:20 +0200 Subject: update to MediaWiki 1.17.0 --- includes/media/SVG.php | 121 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 116 insertions(+), 5 deletions(-) (limited to 'includes/media/SVG.php') diff --git a/includes/media/SVG.php b/includes/media/SVG.php index 4cc66fb1..9a8484f1 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -1,13 +1,19 @@ getMetadata(); + if ( $metadata ) { + $metadata = $this->unpackMetadata( $metadata ); + if( isset( $metadata['animated'] ) ) { + return $metadata['animated']; + } + } + return false; + } + function normaliseParams( $image, &$params ) { global $wgSVGMaxSize; if ( !parent::normaliseParams( $image, $params ) ) { @@ -57,7 +79,7 @@ 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 ); @@ -65,7 +87,7 @@ class SvgHandler extends ImageHandler { return $status; // MediaTransformError } } - + /* * Transform an SVG file to PNG * This function can be called outside of thumbnail contexts @@ -78,6 +100,7 @@ class SvgHandler extends ImageHandler { public function rasterize( $srcPath, $dstPath, $width, $height ) { global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath; $err = false; + $retval = ''; if ( isset( $wgSVGConverters[$wgSVGConverter] ) ) { $cmd = str_replace( array( '$path/', '$width', '$height', '$input', '$output' ), @@ -102,11 +125,19 @@ class SvgHandler extends ImageHandler { return true; } - function getImageSize( $image, $path ) { - return wfGetSVGsize( $path ); + function getImageSize( $file, $path, $metadata = false ) { + if ( $metadata === false ) { + $metadata = $file->getMetaData(); + } + $metadata = $this->unpackMetaData( $metadata ); + + if ( isset( $metadata['width'] ) && isset( $metadata['height'] ) ) { + return array( $metadata['width'], $metadata['height'], 'SVG', + "width=\"{$metadata['width']}\" height=\"{$metadata['height']}\"" ); + } } - function getThumbType( $ext, $mime ) { + function getThumbType( $ext, $mime, $params = null ) { return array( 'png', 'image/png' ); } @@ -117,4 +148,84 @@ class SvgHandler extends ImageHandler { $wgLang->formatNum( $file->getHeight() ), $wgLang->formatSize( $file->getSize() ) ); } + + function getMetadata( $file, $filename ) { + try { + $metadata = SVGMetadataExtractor::getMetadata( $filename ); + } catch( Exception $e ) { + // Broken file? + wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" ); + return '0'; + } + $metadata['version'] = self::SVG_METADATA_VERSION; + return serialize( $metadata ); + } + + function unpackMetadata( $metadata ) { + $unser = @unserialize( $metadata ); + if ( isset( $unser['version'] ) && $unser['version'] == self::SVG_METADATA_VERSION ) { + return $unser; + } else { + return false; + } + } + + function getMetadataType( $image ) { + return 'parsed-svg'; + } + + function isMetadataValid( $image, $metadata ) { + return $this->unpackMetadata( $metadata ) !== false; + } + + function visibleMetadataFields() { + $fields = array( 'title', 'description', 'animated' ); + return $fields; + } + + function formatMetadata( $file ) { + $result = array( + 'visible' => array(), + 'collapsed' => array() + ); + $metadata = $file->getMetadata(); + if ( !$metadata ) { + return false; + } + $metadata = $this->unpackMetadata( $metadata ); + if ( !$metadata ) { + return false; + } + unset( $metadata['version'] ); + unset( $metadata['metadata'] ); /* non-formatted XML */ + + /* TODO: add a formatter + $format = new FormatSVG( $metadata ); + $formatted = $format->getFormattedData(); + */ + + // Sort fields into visible and collapsed + $visibleFields = $this->visibleMetadataFields(); + + // Rename fields to be compatible with exif, so that + // the labels for these fields work. + $conversion = array( 'width' => 'imagewidth', + 'height' => 'imagelength', + 'description' => 'imagedescription', + 'title' => 'objectname', + ); + foreach ( $metadata as $name => $value ) { + $tag = strtolower( $name ); + if ( isset( $conversion[$tag] ) ) { + $tag = $conversion[$tag]; + } + self::addMeta( $result, + in_array( $tag, $visibleFields ) ? 'visible' : 'collapsed', + 'exif', + $tag, + $value + ); + } + return $result; + } } -- cgit v1.2.3-54-g00ecf