(bug 39431) Fix how SVG metadata is displayed (esp. animated status)
authorBrian Wolff <bawolff+wn@gmail.com>
Fri, 17 Aug 2012 02:18:39 +0000 (23:18 -0300)
committerCatrope <roan.kattouw@gmail.com>
Wed, 22 Aug 2012 00:45:53 +0000 (17:45 -0700)
(Quite a few of these issues are my fault from 65c27ddeb19757cb8a)
*All fields were starting as collapsed, which was not the intent of the code
*Animated field used non-existent messages, and displayed a value of "1" instead
   of something meaningful to the user. Both (A)PNG and GIF handlers put
   the animated status in the long description which feels more natural to me
   so move the animated status to the long desc (long desc = subtitle under
   the image on the description page).
*Use human readable file sizes in the long description instead of
   total number of bytes. This bring it in line with the implementation
   in the parent class.
*Correctly mark scripted SVG's as animated. Mostly a moot point
   since we do not allow animated svgs past the upload checks
   but for completeness and for people who totally
   disable all upload verification.
   (Note: This would miss event attributes (onclick, etc)
   I didn't see much point in adding that since almost
   always there will be a script tag)

Patchset 3: trailing whitespace (d'oh)
patchset 4: rebasing so jenkins is happy

Change-Id: Ic58efbf2bf1e4b14e3129e5bce9ea920d9804111

RELEASE-NOTES-1.20
includes/media/SVG.php
includes/media/SVGMetadataExtractor.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 0a5360e..2ef7b3e 100644 (file)
@@ -129,6 +129,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 22749) Create Special:MostInterwikis.
 * Show change tags when transclude Special:Recentchanges(linked) or Special:Newpages.
 * (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 fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
index cfefeb2..a1e63c5 100644 (file)
@@ -214,13 +214,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 wfMessage( 'svg-long-desc' )->numParams( $file->getWidth(), $file->getHeight() )
-                       ->params( $wgLang->formatSize( $file->getSize() ) )->parse();
+               $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 ) {
@@ -255,7 +272,7 @@ class SvgHandler extends ImageHandler {
        }
 
        function visibleMetadataFields() {
-               $fields = array( 'title', 'description', 'animated' );
+               $fields = array( 'objectname', 'imagedescription' );
                return $fields;
        }
 
@@ -276,8 +293,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 );
@@ -288,8 +303,9 @@ 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',
+               // the labels for these fields work and reuse existing messages.
+               $conversion = array(
+                       'width' => 'imagewidth',
                        'height' => 'imagelength',
                        'description' => 'imagedescription',
                        'title' => 'objectname',
@@ -298,6 +314,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',
index 83f531c..89e1e0c 100644 (file)
@@ -139,6 +139,11 @@ class SVGReader {
                                $this->readField( $tag, 'description' );
                        } elseif ( $isSVG && $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
                                $this->readXml( $tag, 'metadata' );
+                       } elseif ( $isSVG && $tag == 'script' ) {
+                               // We normally do not allow scripted svgs.
+                               // However its possible to configure MW to let them
+                               // in, and such files should be considered animated.
+                               $this->metadata['animated'] = true;
                        } elseif ( $tag !== '#text' ) {
                                $this->debug( "Unhandled top-level XML tag $tag" );
 
@@ -219,6 +224,11 @@ class SVGReader {
                                break;
                        } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) {
                                switch( $this->reader->localName ) {
+                                       case 'script':
+                                               // Normally we disallow files with
+                                               // <script>, but its possible
+                                               // to configure MW to disable
+                                               // such checks.
                                        case 'animate':
                                        case 'set':
                                        case 'animateMotion':
index c343af8..e2cfd7a 100644 (file)
@@ -3819,6 +3819,7 @@ By executing it, your system may be compromised.",
 'file-info-size-pages'   => '$1 × $2 pixels, file size: $3, MIME type: $4, $5 {{PLURAL:$5|page|pages}}',
 'file-nohires'           => 'No higher resolution available.',
 'svg-long-desc'          => 'SVG file, nominally $1 × $2 pixels, file size: $3',
+'svg-long-desc-animated' => 'Animated SVG file, nominally $1 × $2 pixels, file size: $3',
 'show-big-image'         => 'Full resolution',
 'show-big-image-preview' => 'Size of this preview: $1.',
 'show-big-image-other'   => 'Other {{PLURAL:$2|resolution|resolutions}}: $1.',
index bcea82e..2eaddff 100644 (file)
@@ -3544,6 +3544,7 @@ Parameters:
 * $5 is the total number of pages in the document.',
 'file-nohires' => 'File info displayed on file description page. For example of message in use see [[:File:Mouse10.gif]].',
 'svg-long-desc' => 'Displayed under an SVG image at the image description page. Note that argument 3 is a string that includes the file size unit symbol. See for example [[:File:Yes check.svg]].',
+'svg-long-desc-animated' => 'Displayed under an SVG image at the image description page if the image is animated. Non-animated images use {{msg-mw|svg-long-desc}}. $1 is width, $2 is height, and $3 is file size, including unit (for example "10 KB").',
 'show-big-image' => 'Displayed under an image at the image description page, when it is displayed smaller there than it was uploaded.',
 'show-big-image-size' => '
 Parameters:
index f6be347..38ccee6 100644 (file)
@@ -2745,6 +2745,7 @@ $wgMessageStructure = array(
                'file-info-size-pages',
                'file-nohires',
                'svg-long-desc',
+               'svg-long-desc-animated',
                'show-big-image',
                'show-big-image-preview',
                'show-big-image-other',