Merge "Fixed "Undefined property: stdClass::$page_namespace" error"
[lhc/web/wiklou.git] / includes / media / SVG.php
index 4c055a5..d6f8483 100644 (file)
 class SvgHandler extends ImageHandler {
        const SVG_METADATA_VERSION = 2;
 
+       /**
+        * A list of metadata tags that can be converted
+        * to the commonly used exif tags. This allows messages
+        * to be reused, and consistent tag names for {{#formatmetadata:..}}
+        */
+       private static $metaConversion = array(
+               'originalwidth' => 'ImageWidth',
+               'originalheight' => 'ImageLength',
+               'description' => 'ImageDescription',
+               'title' => 'ObjectName',
+       );
+
        function isEnabled() {
                global $wgSVGConverters, $wgSVGConverter;
                if ( !isset( $wgSVGConverters[$wgSVGConverter] ) ) {
@@ -177,7 +189,7 @@ class SvgHandler extends ImageHandler {
                                                wfEscapeShellArg( $srcPath ),
                                                wfEscapeShellArg( $dstPath ) ),
                                        $wgSVGConverters[$wgSVGConverter]
-                               ) . " 2>&1";
+                               );
 
                                $env = array();
                                if ( $lang !== false ) {
@@ -186,7 +198,7 @@ class SvgHandler extends ImageHandler {
 
                                wfProfileIn( 'rsvg' );
                                wfDebug( __METHOD__ . ": $cmd\n" );
-                               $err = wfShellExec( $cmd, $retval, $env );
+                               $err = wfShellExecWithStderr( $cmd, $retval, $env );
                                wfProfileOut( 'rsvg' );
                        }
                }
@@ -340,19 +352,11 @@ class SvgHandler extends ImageHandler {
                // Sort fields into visible and collapsed
                $visibleFields = $this->visibleMetadataFields();
 
-               // Rename fields to be compatible with exif, so that
-               // the labels for these fields work and reuse existing messages.
-               $conversion = array(
-                       'originalwidth' => 'imagewidth',
-                       'originalheight' => 'imagelength',
-                       'description' => 'imagedescription',
-                       'title' => 'objectname',
-               );
                $showMeta = false;
                foreach ( $metadata as $name => $value ) {
                        $tag = strtolower( $name );
-                       if ( isset( $conversion[$tag] ) ) {
-                               $tag = $conversion[$tag];
+                       if ( isset( self::$metaConversion[$tag] ) ) {
+                               $tag = strtolower( self::$metaConversion[$tag] );
                        } else {
                                // Do not output other metadata not in list
                                continue;
@@ -368,7 +372,6 @@ class SvgHandler extends ImageHandler {
                return $showMeta ? $result : false;
        }
 
-
        /**
         * @param string $name Parameter name
         * @param $string $value Parameter value
@@ -431,4 +434,29 @@ class SvgHandler extends ImageHandler {
                        'lang' => $params['lang'],
                );
        }
+
+       public function getCommonMetaArray( File $file ) {
+               $metadata = $file->getMetadata();
+               if ( !$metadata ) {
+                       return array();
+               }
+               $metadata = $this->unpackMetadata( $metadata );
+               if ( !$metadata || isset( $metadata['error'] ) ) {
+                       return array();
+               }
+               $stdMetadata = array();
+               foreach ( $metadata as $name => $value ) {
+                       $tag = strtolower( $name );
+                       if ( $tag === 'originalwidth' || $tag === 'originalheight' ) {
+                               // Skip these. In the exif metadata stuff, it is assumed these
+                               // are measured in px, which is not the case here.
+                               continue;
+                       }
+                       if ( isset( self::$metaConversion[$tag] ) ) {
+                               $tag = self::$metaConversion[$tag];
+                               $stdMetadata[$tag] = $value;
+                       }
+               }
+               return $stdMetadata;
+       }
 }