Merge "[Upload] Async upload code cleanups."
[lhc/web/wiklou.git] / includes / media / FormatMetadata.php
index 0ae9a05..f2710f7 100644 (file)
@@ -100,14 +100,20 @@ class FormatMetadata {
                                ) {
                                        continue;
                                }
-                               $tags[$tag] = intval( $h[0] / $h[1] )
+                               $tags[$tag] = str_pad( intval( $h[0] / $h[1] ), 2, '0', STR_PAD_LEFT )
                                        . ':' . str_pad( intval( $m[0] / $m[1] ), 2, '0', STR_PAD_LEFT )
                                        . ':' . str_pad( intval( $s[0] / $s[1] ), 2, '0', STR_PAD_LEFT );
 
-                               $time = wfTimestamp( TS_MW, '1971:01:01 ' . $tags[$tag] );
-                               // the 1971:01:01 is just a placeholder, and not shown to user.
-                               if ( $time && intval( $time ) > 0 ) {
-                                       $tags[$tag] = $wgLang->time( $time );
+                               try {
+                                       $time = wfTimestamp( TS_MW, '1971:01:01 ' . $tags[$tag] );
+                                       // the 1971:01:01 is just a placeholder, and not shown to user.
+                                       if ( $time && intval( $time ) > 0 ) {
+                                               $tags[$tag] = $wgLang->time( $time );
+                                       }
+                               } catch ( TimestampException $e ) {
+                                       // This shouldn't happen, but we've seen bad formats
+                                       // such as 4-digit seconds in the wild.
+                                       // leave $tags[$tag] as-is
                                }
                                continue;
                        }
@@ -233,7 +239,7 @@ class FormatMetadata {
                                case 'dc-date':
                                case 'DateTimeMetadata':
                                        if ( $val == '0000:00:00 00:00:00' || $val == '    :  :     :  :  ' ) {
-                                               $val = wfMsg( 'exif-unknowndate' );
+                                               $val = wfMessage( 'exif-unknowndate' )->text();
                                        } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/D', $val ) ) {
                                                // Full date.
                                                $time = wfTimestamp( TS_MW, $val );
@@ -591,7 +597,7 @@ class FormatMetadata {
                                case 'Software':
                                        if ( is_array( $val ) ) {
                                                //if its a software, version array.
-                                               $val = wfMsg( 'exif-software-version-value', $val[0], $val[1] );
+                                               $val = wfMessage( 'exif-software-version-value', $val[0], $val[1] )->text();
                                        } else {
                                                $val = self::msg( $tag, '', $val );
                                        }
@@ -599,8 +605,8 @@ class FormatMetadata {
 
                                case 'ExposureTime':
                                        // Show the pretty fraction as well as decimal version
-                                       $val = wfMsg( 'exif-exposuretime-format',
-                                               self::formatFraction( $val ), self::formatNum( $val ) );
+                                       $val = wfMessage( 'exif-exposuretime-format',
+                                               self::formatFraction( $val ), self::formatNum( $val ) )->text();
                                        break;
                                case 'ISOSpeedRatings':
                                        // If its = 65535 that means its at the
@@ -613,13 +619,13 @@ class FormatMetadata {
                                        }
                                        break;
                                case 'FNumber':
-                                       $val = wfMsg( 'exif-fnumber-format',
-                                               self::formatNum( $val ) );
+                                       $val = wfMessage( 'exif-fnumber-format',
+                                               self::formatNum( $val ) )->text();
                                        break;
 
                                case 'FocalLength': case 'FocalLengthIn35mmFilm':
-                                       $val = wfMsg( 'exif-focallength-format',
-                                               self::formatNum( $val ) );
+                                       $val = wfMessage( 'exif-focallength-format',
+                                               self::formatNum( $val ) )->text();
                                        break;
 
                                case 'MaxApertureValue':
@@ -633,10 +639,10 @@ class FormatMetadata {
                                        if ( is_numeric( $val ) ) {
                                                $fNumber = pow( 2, $val / 2 );
                                                if ( $fNumber !== false ) {
-                                                       $val = wfMsg( 'exif-maxaperturevalue-value',
+                                                       $val = wfMessage( 'exif-maxaperturevalue-value',
                                                                self::formatNum( $val ),
                                                                self::formatNum( $fNumber, 2 )
-                                                       );
+                                                       )->text();
                                                }
                                        }
                                        break;
@@ -696,7 +702,7 @@ class FormatMetadata {
                                case 'PixelYDimension':
                                case 'ImageWidth':
                                case 'ImageLength':
-                                       $val = self::formatNum( $val ) . ' ' . wfMsg( 'unit-pixel' );
+                                       $val = self::formatNum( $val ) . ' ' . wfMessage( 'unit-pixel' )->text();
                                        break;
 
                                // Do not transform fields with pure text.
@@ -958,12 +964,12 @@ class FormatMetadata {
 
                if ( $lang === false ) {
                        if ( $noHtml ) {
-                               return wfMsg( 'metadata-langitem-default',
-                                       $wrappedValue ) . "\n\n";
+                               return wfMessage( 'metadata-langitem-default',
+                                       $wrappedValue )->text() . "\n\n";
                        } /* else */
                        return '<li class="mw-metadata-lang-default">'
-                               . wfMsg( 'metadata-langitem-default',
-                                       $wrappedValue )
+                               . wfMessage( 'metadata-langitem-default',
+                                       $wrappedValue )->text()
                                . "</li>\n";
                }
 
@@ -981,8 +987,8 @@ class FormatMetadata {
                // else we have a language specified
 
                if ( $noHtml ) {
-                       return '*' . wfMsg( 'metadata-langitem',
-                               $wrappedValue, $langName, $lang );
+                       return '*' . wfMessage( 'metadata-langitem',
+                               $wrappedValue, $langName, $lang )->text();
                } /* else: */
 
                $item = '<li class="mw-metadata-lang-code-'
@@ -991,8 +997,8 @@ class FormatMetadata {
                        $item .= ' mw-metadata-lang-default';
                }
                $item .= '" lang="' . $lang . '">';
-               $item .= wfMsg( 'metadata-langitem',
-                       $wrappedValue, $langName, $lang );
+               $item .= wfMessage( 'metadata-langitem',
+                       $wrappedValue, $langName, $lang )->text();
                $item .= "</li>\n";
                return $item;
        }
@@ -1006,14 +1012,14 @@ class FormatMetadata {
         * @param $val String: the value of the tag
         * @param $arg String: an argument to pass ($1)
         * @param $arg2 String: a 2nd argument to pass ($2)
-        * @return string A wfMsg of "exif-$tag-$val" in lower case
+        * @return string A wfMessage of "exif-$tag-$val" in lower case
         */
        static function msg( $tag, $val, $arg = null, $arg2 = null ) {
                global $wgContLang;
 
                if ($val === '')
                        $val = 'value';
-               return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg, $arg2 );
+               return wfMessage( $wgContLang->lc( "exif-$tag-$val" ), $arg, $arg2 )->text();
        }
 
        /**
@@ -1214,7 +1220,7 @@ class FormatMetadata {
                $min = self::formatNum( $min );
                $sec = self::formatNum( $sec );
 
-               return wfMsg( 'exif-coordinate-format', $deg, $min, $sec, $ref, $coord );
+               return wfMessage( 'exif-coordinate-format', $deg, $min, $sec, $ref, $coord )->text();
        }
 
        /**
@@ -1335,9 +1341,9 @@ class FormatMetadata {
                                        . htmlspecialchars( $vals['CiUrlWork'] )
                                        . '</span>';
                        }
-                       return wfMsg( 'exif-contact-value', $email, $url,
+                       return wfMessage( 'exif-contact-value', $email, $url,
                                $street, $city, $region, $postal, $country,
-                               $tel );
+                               $tel )->text();
                }
        }
 }
@@ -1355,7 +1361,7 @@ class FormatExif {
         * @param $meta array
         */
        function FormatExif( $meta ) {
-               wfDeprecated(__METHOD__);
+               wfDeprecated( __METHOD__, '1.18' );
                $this->meta = $meta;
        }