diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-01-18 16:46:04 +0100 |
commit | 63601400e476c6cf43d985f3e7b9864681695ed4 (patch) | |
tree | f7846203a952e38aaf66989d0a4702779f549962 /includes/media/SVG.php | |
parent | 8ff01378c9e0207f9169b81966a51def645b6a51 (diff) |
Update to MediaWiki 1.20.2
this update includes:
* adjusted Arch Linux skin
* updated FluxBBAuthPlugin
* patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'includes/media/SVG.php')
-rw-r--r-- | includes/media/SVG.php | 79 |
1 files changed, 63 insertions, 16 deletions
diff --git a/includes/media/SVG.php b/includes/media/SVG.php index aac838e1..55fa5547 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -2,6 +2,21 @@ /** * Handler for SVG images. * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file * @ingroup Media */ @@ -49,6 +64,13 @@ class SvgHandler extends ImageHandler { } /** + * We do not support making animated svg thumbnails + */ + function canAnimateThumb( $file ) { + return false; + } + + /** * @param $image File * @param $params * @return bool @@ -93,20 +115,20 @@ class SvgHandler extends ImageHandler { $clientHeight = $params['height']; $physicalWidth = $params['physicalWidth']; $physicalHeight = $params['physicalHeight']; - $srcPath = $image->getLocalRefPath(); if ( $flags & self::TRANSFORM_LATER ) { - return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $dstPath, $params ); } if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) ) { return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, - wfMsg( 'thumbnail_dest_directory' ) ); + wfMessage( 'thumbnail_dest_directory' )->text() ); } + $srcPath = $image->getLocalRefPath(); $status = $this->rasterize( $srcPath, $dstPath, $physicalWidth, $physicalHeight ); if( $status === true ) { - return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); + return new ThumbnailImage( $image, $dstUrl, $dstPath, $params ); } else { return $status; // MediaTransformError } @@ -119,7 +141,7 @@ class SvgHandler extends ImageHandler { * @param string $dstPath * @param string $width * @param string $height - * @return true|MediaTransformError + * @return bool|MediaTransformError */ public function rasterize( $srcPath, $dstPath, $width, $height ) { global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath; @@ -199,15 +221,30 @@ class SvgHandler extends ImageHandler { } /** + * Subtitle for the image. Different from the base + * class so it can be denoted that SVG's have + * a "nominal" resolution, and not a fixed one, + * as well as so animation can be denoted. + * * @param $file File * @return string */ function getLongDesc( $file ) { global $wgLang; - return wfMsgExt( 'svg-long-desc', 'parseinline', - $wgLang->formatNum( $file->getWidth() ), - $wgLang->formatNum( $file->getHeight() ), - $wgLang->formatSize( $file->getSize() ) ); + $size = $wgLang->formatSize( $file->getSize() ); + + if ( $this->isAnimatedImage( $file ) ) { + $msg = wfMessage( 'svg-long-desc-animated' ); + } else { + $msg = wfMessage( 'svg-long-desc' ); + } + + $msg->numParams( + $file->getWidth(), + $file->getHeight() + ); + $msg->Params( $size ); + return $msg->parse(); } function getMetadata( $file, $filename ) { @@ -238,11 +275,19 @@ class SvgHandler extends ImageHandler { } function isMetadataValid( $image, $metadata ) { - return $this->unpackMetadata( $metadata ) !== false; + $meta = $this->unpackMetadata( $metadata ); + if ( $meta === false ) { + return self::METADATA_BAD; + } + if ( !isset( $meta['originalWidth'] ) ) { + // Old but compatible + return self::METADATA_COMPATIBLE; + } + return self::METADATA_GOOD; } function visibleMetadataFields() { - $fields = array( 'title', 'description', 'animated' ); + $fields = array( 'objectname', 'imagedescription' ); return $fields; } @@ -263,8 +308,6 @@ class SvgHandler extends ImageHandler { if ( !$metadata ) { return false; } - unset( $metadata['version'] ); - unset( $metadata['metadata'] ); /* non-formatted XML */ /* TODO: add a formatter $format = new FormatSVG( $metadata ); @@ -275,9 +318,10 @@ class SvgHandler extends ImageHandler { $visibleFields = $this->visibleMetadataFields(); // Rename fields to be compatible with exif, so that - // the labels for these fields work. - $conversion = array( 'width' => 'imagewidth', - 'height' => 'imagelength', + // the labels for these fields work and reuse existing messages. + $conversion = array( + 'originalwidth' => 'imagewidth', + 'originalheight' => 'imagelength', 'description' => 'imagedescription', 'title' => 'objectname', ); @@ -285,6 +329,9 @@ class SvgHandler extends ImageHandler { $tag = strtolower( $name ); if ( isset( $conversion[$tag] ) ) { $tag = $conversion[$tag]; + } else { + // Do not output other metadata not in list + continue; } self::addMeta( $result, in_array( $tag, $visibleFields ) ? 'visible' : 'collapsed', |