r92286 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92285‎ | r92286 | r92287 >
Date:19:19, 15 July 2011
Author:reedy
Status:ok
Tags:
Comment:
1.17wmf1 MFT r88871, without test stuff (moved location)
Modified paths:
  • /branches/wmf/1.17wmf1/includes/media/SVGMetadataExtractor.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/media/SVGMetadataExtractor.php
@@ -35,6 +35,7 @@
3636 class SVGReader {
3737 const DEFAULT_WIDTH = 512;
3838 const DEFAULT_HEIGHT = 512;
 39+ const NS_SVG = 'http://www.w3.org/2000/svg';
3940
4041 private $reader = null;
4142 private $mDebug = false;
@@ -101,9 +102,9 @@
102103 $keepReading = $this->reader->read();
103104 }
104105
105 - if ( $this->reader->name != 'svg' ) {
 106+ if ( $this->reader->localName != 'svg' || $this->reader->namespaceURI != self::NS_SVG ) {
106107 throw new MWException( "Expected <svg> tag, got ".
107 - $this->reader->name );
 108+ $this->reader->localName . " in NS " . $this->reader->namespaceURI );
108109 }
109110 $this->debug( "<svg> tag is correct." );
110111 $this->handleSVGAttribs();
@@ -111,18 +112,19 @@
112113 $exitDepth = $this->reader->depth;
113114 $keepReading = $this->reader->read();
114115 while ( $keepReading ) {
115 - $tag = $this->reader->name;
 116+ $tag = $this->reader->localName;
116117 $type = $this->reader->nodeType;
 118+ $isSVG = ($this->reader->namespaceURI == self::NS_SVG);
117119
118120 $this->debug( "$tag" );
119121
120 - if ( $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
 122+ if ( $isSVG && $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
121123 break;
122 - } elseif ( $tag == 'title' ) {
 124+ } elseif ( $isSVG && $tag == 'title' ) {
123125 $this->readField( $tag, 'title' );
124 - } elseif ( $tag == 'desc' ) {
 126+ } elseif ( $isSVG && $tag == 'desc' ) {
125127 $this->readField( $tag, 'description' );
126 - } elseif ( $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
 128+ } elseif ( $isSVG && $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
127129 $this->readXml( $tag, 'metadata' );
128130 } elseif ( $tag !== '#text' ) {
129131 $this->debug( "Unhandled top-level XML tag $tag" );
@@ -155,7 +157,7 @@
156158 }
157159 $keepReading = $this->reader->read();
158160 while( $keepReading ) {
159 - if( $this->reader->name == $name && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
 161+ if( $this->reader->localName == $name && $this->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
160162 break;
161163 } elseif( $this->reader->nodeType == XmlReader::TEXT ){
162164 $this->metadata[$metafield] = trim( $this->reader->value );
@@ -175,7 +177,7 @@
176178 return;
177179 }
178180 // TODO: find and store type of xml snippet. metadata['metadataType'] = "rdf"
179 - $this->metadata[$metafield] = $this->reader->readInnerXML();
 181+ $this->metadata[$metafield] = trim( $this->reader->readInnerXML() );
180182 $this->reader->next();
181183 }
182184
@@ -192,11 +194,11 @@
193195 $exitDepth = $this->reader->depth;
194196 $keepReading = $this->reader->read();
195197 while( $keepReading ) {
196 - if( $this->reader->name == $name && $this->reader->depth <= $exitDepth
 198+ if( $this->reader->localName == $name && $this->reader->depth <= $exitDepth
197199 && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
198200 break;
199 - } elseif ( $this->reader->nodeType == XmlReader::ELEMENT ) {
200 - switch( $this->reader->name ) {
 201+ } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) {
 202+ switch( $this->reader->localName ) {
201203 case 'animate':
202204 case 'set':
203205 case 'animateMotion':

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88871* (bug 27465) Fix metadata extraction for SVG files using unusual namespace n...brion23:59, 25 May 2011

Status & tagging log