Merge "Revert "Revert "jQuery 1.8"""
[lhc/web/wiklou.git] / includes / media / SVG.php
index 9846c71..a9d1758 100644 (file)
@@ -63,6 +63,13 @@ class SvgHandler extends ImageHandler {
                return false;
        }
 
+       /**
+        * We do not support making animated svg thumbnails
+        */
+       function canAnimateThumb( $file ) {
+               return false;
+       }
+
        /**
         * @param $image File
         * @param  $params
@@ -115,7 +122,7 @@ class SvgHandler extends ImageHandler {
 
                if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) ) {
                        return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
-                               wfMsg( 'thumbnail_dest_directory' ) );
+                               wfMessage( 'thumbnail_dest_directory' )->text() );
                }
 
                $srcPath = $image->getLocalRefPath();
@@ -214,15 +221,30 @@ class SvgHandler extends ImageHandler {
        }
 
        /**
+        * Subtitle for the image. Different from the base
+        * class so it can be denoted that SVG's have
+        * a "nominal" resolution, and not a fixed one,
+        * as well as so animation can be denoted.
+        *
         * @param $file File
         * @return string
         */
        function getLongDesc( $file ) {
                global $wgLang;
-               return wfMsgExt( 'svg-long-desc', 'parseinline',
-                       $wgLang->formatNum( $file->getWidth() ),
-                       $wgLang->formatNum( $file->getHeight() ),
-                       $wgLang->formatSize( $file->getSize() ) );
+               $size = $wgLang->formatSize( $file->getSize() );
+
+               if ( $this->isAnimatedImage( $file ) ) {
+                       $msg = wfMessage( 'svg-long-desc-animated' );
+               } else {
+                       $msg = wfMessage( 'svg-long-desc' );
+               }
+
+               $msg->numParams(
+                       $file->getWidth(),
+                       $file->getHeight()
+               );
+               $msg->Params( $size );
+               return $msg->parse();
        }
 
        function getMetadata( $file, $filename ) {
@@ -253,11 +275,19 @@ class SvgHandler extends ImageHandler {
        }
 
        function isMetadataValid( $image, $metadata ) {
-               return $this->unpackMetadata( $metadata ) !== false;
+               $meta = $this->unpackMetadata( $metadata );
+               if ( $meta === false ) {
+                       return self::METADATA_BAD;
+               }
+               if ( !isset( $meta['originalWidth'] ) ) {
+                       // Old but compatible
+                       return self::METADATA_COMPATIBLE;
+               }
+               return self::METADATA_GOOD;
        }
 
        function visibleMetadataFields() {
-               $fields = array( 'title', 'description', 'animated' );
+               $fields = array( 'objectname', 'imagedescription' );
                return $fields;
        }
 
@@ -278,8 +308,6 @@ class SvgHandler extends ImageHandler {
                if ( !$metadata ) {
                        return false;
                }
-               unset( $metadata['version'] );
-               unset( $metadata['metadata'] ); /* non-formatted XML */
 
                /* TODO: add a formatter
                $format = new FormatSVG( $metadata );
@@ -290,9 +318,10 @@ class SvgHandler extends ImageHandler {
                $visibleFields = $this->visibleMetadataFields();
 
                // Rename fields to be compatible with exif, so that
-               // the labels for these fields work.
-               $conversion = array( 'width' => 'imagewidth',
-                       'height' => 'imagelength',
+               // the labels for these fields work and reuse existing messages.
+               $conversion = array(
+                       'originalwidth' => 'imagewidth',
+                       'originalheight' => 'imagelength',
                        'description' => 'imagedescription',
                        'title' => 'objectname',
                );
@@ -300,6 +329,9 @@ class SvgHandler extends ImageHandler {
                        $tag = strtolower( $name );
                        if ( isset( $conversion[$tag] ) ) {
                                $tag = $conversion[$tag];
+                       } else {
+                               // Do not output other metadata not in list
+                               continue;
                        }
                        self::addMeta( $result,
                                in_array( $tag, $visibleFields ) ? 'visible' : 'collapsed',