Merge "Revert "Revert "jQuery 1.8"""
[lhc/web/wiklou.git] / includes / media / SVGMetadataExtractor.php
index da7d428..851fe42 100644 (file)
@@ -19,7 +19,7 @@
  *
  * @file
  * @ingroup Media
- * @author Derk-Jan Hartman <hartman _at_ videolan d0t org>
+ * @author "Derk-Jan Hartman <hartman _at_ videolan d0t org>"
  * @author Brion Vibber
  * @copyright Copyright © 2010-2010 Brion Vibber, Derk-Jan Hartman
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
@@ -83,6 +83,12 @@ class SVGReader {
                $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 +96,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;
                }
@@ -139,6 +147,11 @@ class SVGReader {
                                $this->readField( $tag, 'description' );
                        } elseif ( $isSVG && $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
                                $this->readXml( $tag, 'metadata' );
+                       } elseif ( $isSVG && $tag == 'script' ) {
+                               // We normally do not allow scripted svgs.
+                               // However its possible to configure MW to let them
+                               // in, and such files should be considered animated.
+                               $this->metadata['animated'] = true;
                        } elseif ( $tag !== '#text' ) {
                                $this->debug( "Unhandled top-level XML tag $tag" );
 
@@ -219,6 +232,11 @@ class SVGReader {
                                break;
                        } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) {
                                switch( $this->reader->localName ) {
+                                       case 'script':
+                                               // Normally we disallow files with
+                                               // <script>, but its possible
+                                               // to configure MW to disable
+                                               // such checks.
                                        case 'animate':
                                        case 'set':
                                        case 'animateMotion':
@@ -255,7 +273,7 @@ class SVGReader {
        /**
         * Parse the attributes of an SVG element
         *
-        * The parser has to be in the start element of <svg>
+        * The parser has to be in the start element of "<svg>"
         */
        private function handleSVGAttribs( ) {
                $defaultWidth = self::DEFAULT_WIDTH;
@@ -278,9 +296,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 ) ) {