From 9ceb38a9fb48ae09d9dd64355755b958b2c08a7a Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Thu, 16 Aug 2012 23:18:39 -0300 Subject: [PATCH] (bug 39431) Fix how SVG metadata is displayed (esp. animated status) (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 | 1 + includes/media/SVG.php | 33 +++++++++++++++++++------ includes/media/SVGMetadataExtractor.php | 10 ++++++++ languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 1 + maintenance/language/messages.inc | 1 + 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 0a5360ee85..2ef7b3e07f 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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. diff --git a/includes/media/SVG.php b/includes/media/SVG.php index cfefeb2975..a1e63c5776 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -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', diff --git a/includes/media/SVGMetadataExtractor.php b/includes/media/SVGMetadataExtractor.php index 83f531c135..89e1e0c14b 100644 --- a/includes/media/SVGMetadataExtractor.php +++ b/includes/media/SVGMetadataExtractor.php @@ -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 + //