Merge "Make the width/height in the SVG metadata box be in the SVG's units"
authorCatrope <roan.kattouw@gmail.com>
Thu, 23 Aug 2012 20:39:52 +0000 (20:39 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 23 Aug 2012 20:39:52 +0000 (20:39 +0000)
RELEASE-NOTES-1.20
includes/media/SVG.php
includes/media/SVGMetadataExtractor.php
tests/phpunit/includes/media/SVGMetadataExtractorTest.php

index fcab721..20fdcea 100644 (file)
@@ -131,6 +131,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 23226) Add |class= parameter to image links in order to add class(es) to HTML img tag.
 * (bug 39431) SVG animated status is now shown in long description
 * (bug 39376) jquery.form upgraded to 3.14
+* SVG files will now show the actual width in the SVG's specified units
+  in the metadata box.
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
index a5ce1fa..a9d1758 100644 (file)
@@ -275,7 +275,15 @@ 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() {
@@ -312,8 +320,8 @@ class SvgHandler extends ImageHandler {
                // Rename fields to be compatible with exif, so that
                // the labels for these fields work and reuse existing messages.
                $conversion = array(
-                       'width' => 'imagewidth',
-                       'height' => 'imagelength',
+                       'originalwidth' => 'imagewidth',
+                       'originalheight' => 'imagelength',
                        'description' => 'imagedescription',
                        'title' => 'objectname',
                );
index 89e1e0c..851fe42 100644 (file)
@@ -83,6 +83,12 @@ class SVGReader {
                $this->metadata['width'] = self::DEFAULT_WIDTH;
                $this->metadata['height'] = self::DEFAULT_HEIGHT;
 
+               // The size in the units specified by the SVG file
+               // (for the metadata box)
+               // Per the SVG spec, if unspecified, default to '100%'
+               $this->metadata['originalWidth'] = '100%';
+               $this->metadata['originalHeight'] = '100%';
+
                // Because we cut off the end of the svg making an invalid one. Complicated
                // try catch thing to make sure warnings get restored. Seems like there should
                // be a better way.
@@ -90,6 +96,8 @@ class SVGReader {
                try {
                        $this->read();
                } catch( Exception $e ) {
+                       // Note, if this happens, the width/height will be taken to be 0x0.
+                       // Should we consider it the default 512x512 instead?
                        wfRestoreWarnings();
                        throw $e;
                }
@@ -288,9 +296,11 @@ class SVGReader {
                }
                if( $this->reader->getAttribute('width') ) {
                        $width = $this->scaleSVGUnit( $this->reader->getAttribute('width'), $defaultWidth );
+                       $this->metadata['originalWidth'] = $this->reader->getAttribute( 'width' );
                }
                if( $this->reader->getAttribute('height') ) {
                        $height = $this->scaleSVGUnit( $this->reader->getAttribute('height'), $defaultHeight );
+                       $this->metadata['originalHeight'] = $this->reader->getAttribute( 'height' );
                }
 
                if( !isset( $width ) && !isset( $height ) ) {
index 526beae..3017dbb 100644 (file)
@@ -45,21 +45,27 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
                                "$base/Wikimedia-logo.svg",
                                array(
                                        'width' => 1024,
-                                       'height' => 1024
+                                       'height' => 1024,
+                                       'originalWidth' => '1024',
+                                       'originalHeight' => '1024',
                                )
                        ),
                        array(
                                "$base/QA_icon.svg",
                                array(
                                        'width' => 60,
-                                       'height' => 60
+                                       'height' => 60,
+                                       'originalWidth' => '60',
+                                       'originalHeight' => '60',
                                )
                        ),
                        array(
                                "$base/Gtk-media-play-ltr.svg",
                                array(
                                        'width' => 60,
-                                       'height' => 60
+                                       'height' => 60,
+                                       'originalWidth' => '60.0000000',
+                                       'originalHeight' => '60.0000000',
                                )
                        ),
                        array(
@@ -67,7 +73,9 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
                                // This file triggered bug 31719, needs entity expansion in the xmlns checks
                                array(
                                        'width' => 385,
-                                       'height' => 385
+                                       'height' => 385,
+                                       'originalWidth' => '385',
+                                       'originalHeight' => '385.0004883',
                                )
                        )
                );
@@ -89,7 +97,9 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
                                array(
                                        'height' => 593,
                                        'metadata' => $metadata,
-                                       'width' => 959
+                                       'width' => 959,
+                                       'originalWidth' => '958.69',
+                                       'originalHeight' => '592.78998',
                                )
                        ),
                );