Merge "Added DatabaseBase::startAtomic and endAtomic"
[lhc/web/wiklou.git] / includes / media / ExifBitmap.php
index 1a761f3..d3fa36d 100644 (file)
@@ -51,26 +51,28 @@ class ExifBitmapHandler extends BitmapHandler {
 
                // Treat Software as a special case because in can contain
                // an array of (SoftwareName, Version).
-               if (isset( $metadata['Software'] )
+               if ( isset( $metadata['Software'] )
                        && is_array( $metadata['Software'] )
-                       && is_array( $metadata['Software'][0])
+                       && is_array( $metadata['Software'][0] )
                        && isset( $metadata['Software'][0][0] )
-                       && isset( $metadata['Software'][0][1])
+                       && isset( $metadata['Software'][0][1] )
                ) {
                        $metadata['Software'] = $metadata['Software'][0][0] . ' (Version '
                                . $metadata['Software'][0][1] . ')';
                }
 
+               $formatter = new FormatMetadata;
+
                // ContactInfo also has to be dealt with specially
                if ( isset( $metadata['Contact'] ) ) {
                        $metadata['Contact'] =
-                               FormatMetadata::collapseContactInfo(
+                               $formatter->collapseContactInfo(
                                        $metadata['Contact'] );
                }
 
                foreach ( $metadata as &$val ) {
                        if ( is_array( $val ) ) {
-                               $val = FormatMetadata::flattenArray( $val, 'ul', $avoidHtml );
+                               $val = $formatter->flattenArrayReal( $val, 'ul', $avoidHtml );
                        }
                }
                $metadata['MEDIAWIKI_EXIF_VERSION'] = 1;
@@ -84,7 +86,7 @@ class ExifBitmapHandler extends BitmapHandler {
                        return self::METADATA_GOOD;
                }
                if ( $metadata === self::OLD_BROKEN_FILE ) {
-                       # Old special value indicating that there is no EXIF data in the file.
+                       # Old special value indicating that there is no Exif data in the file.
                        # or that there was an error well extracting the metadata.
                        wfDebug( __METHOD__ . ": back-compat version\n" );
                        return self::METADATA_COMPATIBLE;
@@ -117,25 +119,32 @@ class ExifBitmapHandler extends BitmapHandler {
         * @return array|bool
         */
        function formatMetadata( $image ) {
-               $metadata = $image->getMetadata();
+               $meta = $this->getCommonMetaArray( $image );
+               if ( count( $meta ) === 0 ) {
+                       return false;
+               }
+
+               return $this->formatMetadataHelper( $meta );
+       }
+
+       public function getCommonMetaArray( File $file ) {
+               $metadata = $file->getMetadata();
                if ( $metadata === self::OLD_BROKEN_FILE ||
                        $metadata === self::BROKEN_FILE ||
-                       $this->isMetadataValid( $image, $metadata ) === self::METADATA_BAD )
+                       $this->isMetadataValid( $file, $metadata ) === self::METADATA_BAD )
                {
                        // So we don't try and display metadata from PagedTiffHandler
                        // for example when using InstantCommons.
-                       return false;
+                       return array();
                }
 
                $exif = unserialize( $metadata );
                if ( !$exif ) {
-                       return false;
+                       return array();
                }
                unset( $exif['MEDIAWIKI_EXIF_VERSION'] );
-               if ( count( $exif ) == 0 ) {
-                       return false;
-               }
-               return $this->formatMetadataHelper( $exif );
+
+               return $exif;
        }
 
        function getMetadataType( $image ) {
@@ -190,7 +199,7 @@ class ExifBitmapHandler extends BitmapHandler {
                }
 
                $data = $file->getMetadata();
-               return self::getRotationForExif( $data );
+               return $this->getRotationForExif( $data );
        }
 
        /**