Index: trunk/phase3/tests/phpunit/includes/media/Wikimedia-logo.svg |
— | — | @@ -0,0 +1,14 @@ |
| 2 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
| 3 | +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> |
| 4 | +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Wikimedia logo" viewBox="-599 -599 1198 1198" width="1024" height="1024"> |
| 5 | +<defs> |
| 6 | + <clipPath id="mask"> |
| 7 | + <path d="M 47.5,-87.5 v 425 h -95 v -425 l -552,-552 v 1250 h 1199 v -1250 z"/> |
| 8 | + </clipPath> |
| 9 | +</defs> |
| 10 | +<g clip-path="url(#mask)"> |
| 11 | + <circle id="green parts" fill="#396" r="336.5"/> |
| 12 | + <circle id="blue arc" fill="none" stroke="#069" r="480.25" stroke-width="135.5"/> |
| 13 | +</g> |
| 14 | +<circle fill="#900" cy="-379.5" r="184.5" id="red circle"/> |
| 15 | +</svg> |
\ No newline at end of file |
Index: trunk/phase3/tests/phpunit/includes/media/SVGMetadataExtractorTest.php |
— | — | @@ -26,6 +26,13 @@ |
27 | 27 | $base = dirname( __FILE__ ); |
28 | 28 | return array( |
29 | 29 | array( |
| 30 | + "$base/Wikimedia-logo.svg", |
| 31 | + array( |
| 32 | + 'width' => 1024, |
| 33 | + 'height' => 1024 |
| 34 | + ) |
| 35 | + ), |
| 36 | + array( |
30 | 37 | "$base/QA_icon.svg", |
31 | 38 | array( |
32 | 39 | 'width' => 60, |
— | — | @@ -42,8 +49,15 @@ |
43 | 50 | array( |
44 | 51 | "$base/US_states_by_total_state_tax_revenue.svg", |
45 | 52 | array( |
46 | | - 'width' => 593, |
47 | | - 'height' => 959 |
| 53 | + 'height' => 593, |
| 54 | + 'metadata' => |
| 55 | + '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> |
| 56 | + <ns4:Work xmlns:ns4="http://creativecommons.org/ns#" rdf:about=""> |
| 57 | + <ns5:format xmlns:ns5="http://purl.org/dc/elements/1.1/">image/svg+xml</ns5:format> |
| 58 | + <ns5:type xmlns:ns5="http://purl.org/dc/elements/1.1/" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> |
| 59 | + </ns4:Work> |
| 60 | + </rdf:RDF>', |
| 61 | + 'width' => 959 |
48 | 62 | ) |
49 | 63 | ), |
50 | 64 | ); |
Index: trunk/phase3/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 | |
— | — | @@ -195,11 +197,11 @@ |
196 | 198 | $exitDepth = $this->reader->depth; |
197 | 199 | $keepReading = $this->reader->read(); |
198 | 200 | while( $keepReading ) { |
199 | | - if( $this->reader->name == $name && $this->reader->depth <= $exitDepth |
| 201 | + if( $this->reader->localName == $name && $this->reader->depth <= $exitDepth |
200 | 202 | && $this->reader->nodeType == XmlReader::END_ELEMENT ) { |
201 | 203 | break; |
202 | | - } elseif ( $this->reader->nodeType == XmlReader::ELEMENT ) { |
203 | | - switch( $this->reader->name ) { |
| 204 | + } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) { |
| 205 | + switch( $this->reader->localName ) { |
204 | 206 | case 'animate': |
205 | 207 | case 'set': |
206 | 208 | case 'animateMotion': |