X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FSVGMetadataExtractor.php;h=d332c3f3c1b89654eed9e32f73d1df7b2d38ed9e;hb=008c561245742cdff111d4821839c9242f75ecb0;hp=592403ad5d39823ba55e4faac368ed24d5dd1306;hpb=1f8441b6830111631c860c5c677d812de833a58f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/SVGMetadataExtractor.php b/includes/media/SVGMetadataExtractor.php index 592403ad5d..d332c3f3c1 100644 --- a/includes/media/SVGMetadataExtractor.php +++ b/includes/media/SVGMetadataExtractor.php @@ -31,6 +31,7 @@ class SVGMetadataExtractor { static function getMetadata( $filename ) { $svg = new SVGReader( $filename ); + return $svg->getMetadata(); } } @@ -44,8 +45,10 @@ class SVGReader { const NS_SVG = 'http://www.w3.org/2000/svg'; private $reader = null; + private $mDebug = false; - private $metadata = Array(); + + private $metadata = array(); /** * Constructor @@ -101,7 +104,7 @@ class SVGReader { wfSuppressWarnings(); try { $this->read(); - } catch( Exception $e ) { + } catch ( Exception $e ) { // Note, if this happens, the width/height will be taken to be 0x0. // Should we consider it the default 512x512 instead? wfRestoreWarnings(); @@ -128,7 +131,7 @@ class SVGReader { $keepReading = $this->reader->read(); /* Skip until first element */ - while( $keepReading && $this->reader->nodeType != XmlReader::ELEMENT ) { + while ( $keepReading && $this->reader->nodeType != XmlReader::ELEMENT ) { $keepReading = $this->reader->read(); } @@ -144,11 +147,13 @@ class SVGReader { while ( $keepReading ) { $tag = $this->reader->localName; $type = $this->reader->nodeType; - $isSVG = ($this->reader->namespaceURI == self::NS_SVG); + $isSVG = ( $this->reader->namespaceURI == self::NS_SVG ); $this->debug( "$tag" ); - if ( $isSVG && $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) { + if ( $isSVG && $tag == 'svg' && $type == XmlReader::END_ELEMENT + && $this->reader->depth <= $exitDepth + ) { break; } elseif ( $isSVG && $tag == 'title' ) { $this->readField( $tag, 'title' ); @@ -187,14 +192,17 @@ class SVGReader { */ private function readField( $name, $metafield = null ) { $this->debug( "Read field $metafield" ); - if( !$metafield || $this->reader->nodeType != XmlReader::ELEMENT ) { + if ( !$metafield || $this->reader->nodeType != XmlReader::ELEMENT ) { return; } $keepReading = $this->reader->read(); - while( $keepReading ) { - if( $this->reader->localName == $name && $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::END_ELEMENT ) { + while ( $keepReading ) { + if ( $this->reader->localName == $name + && $this->reader->namespaceURI == self::NS_SVG + && $this->reader->nodeType == XmlReader::END_ELEMENT + ) { break; - } elseif( $this->reader->nodeType == XmlReader::TEXT ) { + } elseif ( $this->reader->nodeType == XmlReader::TEXT ) { $this->metadata[$metafield] = trim( $this->reader->value ); } $keepReading = $this->reader->read(); @@ -209,14 +217,16 @@ class SVGReader { */ private function readXml( $metafield = null ) { $this->debug( "Read top level metadata" ); - if( !$metafield || $this->reader->nodeType != XmlReader::ELEMENT ) { + if ( !$metafield || $this->reader->nodeType != XmlReader::ELEMENT ) { return; } // TODO: find and store type of xml snippet. metadata['metadataType'] = "rdf" - if( method_exists( $this->reader, 'readInnerXML' ) ) { + if ( method_exists( $this->reader, 'readInnerXML' ) ) { $this->metadata[$metafield] = trim( $this->reader->readInnerXML() ); } else { - throw new MWException( "The PHP XMLReader extension does not come with readInnerXML() method. Your libxml is probably out of date (need 2.6.20 or later)." ); + throw new MWException( "The PHP XMLReader extension does not come " . + "with readInnerXML() method. Your libxml is probably out of " . + "date (need 2.6.20 or later)." ); } $this->reader->next(); } @@ -228,7 +238,7 @@ class SVGReader { */ private function animateFilter( $name ) { $this->debug( "animate filter for tag $name" ); - if( $this->reader->nodeType != XmlReader::ELEMENT ) { + if ( $this->reader->nodeType != XmlReader::ELEMENT ) { return; } if ( $this->reader->isEmptyElement ) { @@ -236,12 +246,15 @@ class SVGReader { } $exitDepth = $this->reader->depth; $keepReading = $this->reader->read(); - while( $keepReading ) { - if( $this->reader->localName == $name && $this->reader->depth <= $exitDepth - && $this->reader->nodeType == XmlReader::END_ELEMENT ) { + while ( $keepReading ) { + if ( $this->reader->localName == $name && $this->reader->depth <= $exitDepth + && $this->reader->nodeType == XmlReader::END_ELEMENT + ) { break; - } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) { - switch( $this->reader->localName ) { + } elseif ( $this->reader->namespaceURI == + self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT + ) { + switch ( $this->reader->localName ) { case 'script': // Normally we disallow files with //