| Index: trunk/phase3/includes/media/SVGMetadataExtractor.php |
| — | — | @@ -74,7 +74,7 @@ |
| 75 | 75 | $keepReading = $this->reader->read(); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | | - if ( $this->reader->name != 'svg' ) { |
| | 78 | + if ( !$this->qualifiedNameEquals( $this->reader->name, 'svg', 'svg' ) ) { |
| 79 | 79 | throw new MWException( "Expected <svg> tag, got ". |
| 80 | 80 | $this->reader->name ); |
| 81 | 81 | } |
| — | — | @@ -90,13 +90,13 @@ |
| 91 | 91 | |
| 92 | 92 | $this->debug( "$tag" ); |
| 93 | 93 | |
| 94 | | - if ( $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) { |
| | 94 | + if ( $this->qualifiedNameEquals( $tag, 'svg', 'svg' ) && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) { |
| 95 | 95 | break; |
| 96 | | - } elseif ( $tag == 'title' ) { |
| | 96 | + } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'title' ) ) { |
| 97 | 97 | $this->readField( $tag, 'title' ); |
| 98 | | - } elseif ( $tag == 'desc' ) { |
| | 98 | + } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'desc' ) ) { |
| 99 | 99 | $this->readField( $tag, 'description' ); |
| 100 | | - } elseif ( $tag == 'metadata' && $type == XmlReader::ELEMENT ) { |
| | 100 | + } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'metadata' ) && $type == XmlReader::ELEMENT ) { |
| 101 | 101 | $this->readXml( $tag, 'metadata' ); |
| 102 | 102 | } elseif ( $tag !== '#text' ) { |
| 103 | 103 | $this->debug( "Unhandled top-level XML tag $tag" ); |
| — | — | @@ -172,10 +172,15 @@ |
| 173 | 173 | } elseif ( $this->reader->nodeType == XmlReader::ELEMENT ) { |
| 174 | 174 | switch( $this->reader->name ) { |
| 175 | 175 | case 'animate': |
| | 176 | + case 'svg:animate': |
| 176 | 177 | case 'set': |
| | 178 | + case 'svg:set': |
| 177 | 179 | case 'animateMotion': |
| | 180 | + case 'svg:animateMotion': |
| 178 | 181 | case 'animateColor': |
| | 182 | + case 'svg:animateColor': |
| 179 | 183 | case 'animateTransform': |
| | 184 | + case 'svg:animateTransform': |
| 180 | 185 | $this->debug( "HOUSTON WE HAVE ANIMATION" ); |
| 181 | 186 | $this->metadata['animated'] = true; |
| 182 | 187 | break; |
| — | — | @@ -284,4 +289,22 @@ |
| 285 | 290 | return floatval( $length ); |
| 286 | 291 | } |
| 287 | 292 | } |
| | 293 | + |
| | 294 | + /** |
| | 295 | + * XML namespace check |
| | 296 | + * |
| | 297 | + * Check if a read node name matches the expected nodeName |
| | 298 | + * @param $qualifiedName as read by XMLReader |
| | 299 | + * @param $prefix the namespace prefix that you expect for this element, defaults to svg namespace |
| | 300 | + * @param $localName the localName part of the element that you want to match |
| | 301 | + * |
| | 302 | + * @return boolean |
| | 303 | + */ |
| | 304 | + private function qualifiedNameEquals( $qualifiedName, $prefix="svg", $localName ) { |
| | 305 | + if( ($qualifiedName == $localName && $prefix == "svg" ) || |
| | 306 | + $qualifiedName == ($prefix . ":" . $localName) ) { |
| | 307 | + return true; |
| | 308 | + } |
| | 309 | + return false; |
| | 310 | + } |
| 288 | 311 | } |