r82336 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82335‎ | r82336 | r82337 >
Date:16:01, 17 February 2011
Author:reedy
Status:ok
Tags:
Comment:
MFT r82307
Modified paths:
  • /branches/wmf/1.17wmf1/includes/media/SVGMetadataExtractor.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/media/SVGMetadataExtractor.php
@@ -74,7 +74,7 @@
7575 $keepReading = $this->reader->read();
7676 }
7777
78 - if ( $this->reader->name != 'svg' ) {
 78+ if ( !$this->qualifiedNameEquals( $this->reader->name, 'svg', 'svg' ) ) {
7979 throw new MWException( "Expected <svg> tag, got ".
8080 $this->reader->name );
8181 }
@@ -90,13 +90,13 @@
9191
9292 $this->debug( "$tag" );
9393
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 ) {
9595 break;
96 - } elseif ( $tag == 'title' ) {
 96+ } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'title' ) ) {
9797 $this->readField( $tag, 'title' );
98 - } elseif ( $tag == 'desc' ) {
 98+ } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'desc' ) ) {
9999 $this->readField( $tag, 'description' );
100 - } elseif ( $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
 100+ } elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'metadata' ) && $type == XmlReader::ELEMENT ) {
101101 $this->readXml( $tag, 'metadata' );
102102 } elseif ( $tag !== '#text' ) {
103103 $this->debug( "Unhandled top-level XML tag $tag" );
@@ -172,10 +172,15 @@
173173 } elseif ( $this->reader->nodeType == XmlReader::ELEMENT ) {
174174 switch( $this->reader->name ) {
175175 case 'animate':
 176+ case 'svg:animate':
176177 case 'set':
 178+ case 'svg:set':
177179 case 'animateMotion':
 180+ case 'svg:animateMotion':
178181 case 'animateColor':
 182+ case 'svg:animateColor':
179183 case 'animateTransform':
 184+ case 'svg:animateTransform':
180185 $this->debug( "HOUSTON WE HAVE ANIMATION" );
181186 $this->metadata['animated'] = true;
182187 break;
@@ -284,4 +289,22 @@
285290 return floatval( $length );
286291 }
287292 }
 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+ }
288311 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82307Add support for namespace prefixed elements in svg. ie. <svg:svg>...hartman22:45, 16 February 2011

Status & tagging log