| Index: branches/wmf/1.17wmf1/includes/media/SVGMetadataExtractor.php |
| — | — | @@ -35,6 +35,7 @@ |
| 36 | 36 | class SVGReader { |
| 37 | 37 | const DEFAULT_WIDTH = 512; |
| 38 | 38 | const DEFAULT_HEIGHT = 512; |
| | 39 | + const NS_SVG = 'http://www.w3.org/2000/svg'; |
| 39 | 40 | |
| 40 | 41 | private $reader = null; |
| 41 | 42 | private $mDebug = false; |
| — | — | @@ -101,9 +102,9 @@ |
| 102 | 103 | $keepReading = $this->reader->read(); |
| 103 | 104 | } |
| 104 | 105 | |
| 105 | | - if ( $this->reader->name != 'svg' ) { |
| | 106 | + if ( $this->reader->localName != 'svg' || $this->reader->namespaceURI != self::NS_SVG ) { |
| 106 | 107 | throw new MWException( "Expected <svg> tag, got ". |
| 107 | | - $this->reader->name ); |
| | 108 | + $this->reader->localName . " in NS " . $this->reader->namespaceURI ); |
| 108 | 109 | } |
| 109 | 110 | $this->debug( "<svg> tag is correct." ); |
| 110 | 111 | $this->handleSVGAttribs(); |
| — | — | @@ -111,18 +112,19 @@ |
| 112 | 113 | $exitDepth = $this->reader->depth; |
| 113 | 114 | $keepReading = $this->reader->read(); |
| 114 | 115 | while ( $keepReading ) { |
| 115 | | - $tag = $this->reader->name; |
| | 116 | + $tag = $this->reader->localName; |
| 116 | 117 | $type = $this->reader->nodeType; |
| | 118 | + $isSVG = ($this->reader->namespaceURI == self::NS_SVG); |
| 117 | 119 | |
| 118 | 120 | $this->debug( "$tag" ); |
| 119 | 121 | |
| 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 ) { |
| 121 | 123 | break; |
| 122 | | - } elseif ( $tag == 'title' ) { |
| | 124 | + } elseif ( $isSVG && $tag == 'title' ) { |
| 123 | 125 | $this->readField( $tag, 'title' ); |
| 124 | | - } elseif ( $tag == 'desc' ) { |
| | 126 | + } elseif ( $isSVG && $tag == 'desc' ) { |
| 125 | 127 | $this->readField( $tag, 'description' ); |
| 126 | | - } elseif ( $tag == 'metadata' && $type == XmlReader::ELEMENT ) { |
| | 128 | + } elseif ( $isSVG && $tag == 'metadata' && $type == XmlReader::ELEMENT ) { |
| 127 | 129 | $this->readXml( $tag, 'metadata' ); |
| 128 | 130 | } elseif ( $tag !== '#text' ) { |
| 129 | 131 | $this->debug( "Unhandled top-level XML tag $tag" ); |
| — | — | @@ -155,7 +157,7 @@ |
| 156 | 158 | } |
| 157 | 159 | $keepReading = $this->reader->read(); |
| 158 | 160 | 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 ) { |
| 160 | 162 | break; |
| 161 | 163 | } elseif( $this->reader->nodeType == XmlReader::TEXT ){ |
| 162 | 164 | $this->metadata[$metafield] = trim( $this->reader->value ); |
| — | — | @@ -175,7 +177,7 @@ |
| 176 | 178 | return; |
| 177 | 179 | } |
| 178 | 180 | // 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() ); |
| 180 | 182 | $this->reader->next(); |
| 181 | 183 | } |
| 182 | 184 | |
| — | — | @@ -192,11 +194,11 @@ |
| 193 | 195 | $exitDepth = $this->reader->depth; |
| 194 | 196 | $keepReading = $this->reader->read(); |
| 195 | 197 | while( $keepReading ) { |
| 196 | | - if( $this->reader->name == $name && $this->reader->depth <= $exitDepth |
| | 198 | + if( $this->reader->localName == $name && $this->reader->depth <= $exitDepth |
| 197 | 199 | && $this->reader->nodeType == XmlReader::END_ELEMENT ) { |
| 198 | 200 | 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 ) { |
| 201 | 203 | case 'animate': |
| 202 | 204 | case 'set': |
| 203 | 205 | case 'animateMotion': |