From: Catrope Date: Wed, 22 Aug 2012 00:49:24 +0000 (+0000) Subject: Merge "(bug 39431) Fix how SVG metadata is displayed (esp. animated status)" X-Git-Tag: 1.31.0-rc.0~22650 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=b09d02200b8998b1e44eebabea5dceac802a2352;hp=532b1c1d42ebf35133605a04bdcd3417fa9b3f7a;p=lhc%2Fweb%2Fwiklou.git Merge "(bug 39431) Fix how SVG metadata is displayed (esp. animated status)" --- 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 + //