Merge "[JobQueue] Pushed stats down to job queue subclasses."
[lhc/web/wiklou.git] / includes / media / SVGMetadataExtractor.php
index 89e1e0c..456c016 100644 (file)
@@ -52,6 +52,7 @@ class SVGReader {
         *
         * Creates an SVGReader drawing from the source provided
         * @param $source String: URI from which to read
+        * @throws MWException|Exception
         */
        function __construct( $source ) {
                global $wgSVGMetadataCutoff;
@@ -74,15 +75,21 @@ class SVGReader {
                        $this->reader->open( $source, null, LIBXML_NOERROR | LIBXML_NOWARNING );
                }
 
-               // Expand entities, since Adobe Illustrator uses them for xmlns 
-               // attributes (bug 31719). Note that libxml2 has some protection 
-               // against large recursive entity expansions so this is not as 
+               // Expand entities, since Adobe Illustrator uses them for xmlns
+               // attributes (bug 31719). Note that libxml2 has some protection
+               // against large recursive entity expansions so this is not as
                // insecure as it might appear to be.
                $this->reader->setParserProperty( XMLReader::SUBST_ENTITIES, true );
 
                $this->metadata['width'] = self::DEFAULT_WIDTH;
                $this->metadata['height'] = self::DEFAULT_HEIGHT;
 
+               // The size in the units specified by the SVG file
+               // (for the metadata box)
+               // Per the SVG spec, if unspecified, default to '100%'
+               $this->metadata['originalWidth'] = '100%';
+               $this->metadata['originalHeight'] = '100%';
+
                // Because we cut off the end of the svg making an invalid one. Complicated
                // try catch thing to make sure warnings get restored. Seems like there should
                // be a better way.
@@ -90,6 +97,8 @@ class SVGReader {
                try {
                        $this->read();
                } 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();
                        throw $e;
                }
@@ -105,6 +114,7 @@ class SVGReader {
 
        /**
         * Read the SVG
+        * @throws MWException
         * @return bool
         */
        public function read() {
@@ -188,6 +198,7 @@ class SVGReader {
         * Read an XML snippet from an element
         *
         * @param String $metafield that we will fill with the result
+        * @throws MWException
         */
        private function readXml( $metafield=null ) {
                $this->debug ( "Read top level metadata" );
@@ -288,9 +299,11 @@ class SVGReader {
                }
                if( $this->reader->getAttribute('width') ) {
                        $width = $this->scaleSVGUnit( $this->reader->getAttribute('width'), $defaultWidth );
+                       $this->metadata['originalWidth'] = $this->reader->getAttribute( 'width' );
                }
                if( $this->reader->getAttribute('height') ) {
                        $height = $this->scaleSVGUnit( $this->reader->getAttribute('height'), $defaultHeight );
+                       $this->metadata['originalHeight'] = $this->reader->getAttribute( 'height' );
                }
 
                if( !isset( $width ) && !isset( $height ) ) {