X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FPNG.php;h=d2c17efd4f4e140d33f363686e21a4ea15402fbf;hb=075b90235e86de663c000db2c90253509bb97375;hp=9dfd5d1a4ab9287d0ed6277c77a5025105161453;hpb=7c4eccb559754ea70c005dd87705af6bf46089c5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/PNG.php b/includes/media/PNG.php index 9dfd5d1a4a..d2c17efd4f 100644 --- a/includes/media/PNG.php +++ b/includes/media/PNG.php @@ -38,7 +38,7 @@ class PNGHandler extends BitmapHandler { function getMetadata( $image, $filename ) { try { $metadata = BitmapMetadataHandler::PNG( $filename ); - } catch( Exception $e ) { + } catch ( Exception $e ) { // Broken file? wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" ); return self::BROKEN_FILE; @@ -52,20 +52,32 @@ class PNGHandler extends BitmapHandler { * @return array|bool */ function formatMetadata( $image ) { + $meta = $this->getCommonMetaArray( $image ); + if ( count( $meta ) === 0 ) { + return false; + } + + return $this->formatMetadataHelper( $meta ); + } + + /** + * Get a file type independent array of metadata. + * + * @param $image File + * @return array The metadata array + */ + public function getCommonMetaArray( File $image ) { $meta = $image->getMetadata(); if ( !$meta ) { - return false; + return array(); } $meta = unserialize( $meta ); - if ( !isset( $meta['metadata'] ) || count( $meta['metadata'] ) <= 1 ) { - return false; - } - - if ( isset( $meta['metadata']['_MW_PNG_VERSION'] ) ) { - unset( $meta['metadata']['_MW_PNG_VERSION'] ); + if ( !isset( $meta['metadata'] ) ) { + return array(); } - return $this->formatMetadataHelper( $meta['metadata'] ); + unset( $meta['metadata']['_MW_PNG_VERSION'] ); + return $meta['metadata']; } /** @@ -107,13 +119,13 @@ class PNGHandler extends BitmapHandler { wfRestoreWarnings(); if ( !$data || !is_array( $data ) ) { - wfDebug( __METHOD__ . ' invalid png metadata' ); + wfDebug( __METHOD__ . " invalid png metadata\n" ); return self::METADATA_BAD; } if ( !isset( $data['metadata']['_MW_PNG_VERSION'] ) || $data['metadata']['_MW_PNG_VERSION'] != PNGMetadataExtractor::VERSION ) { - wfDebug( __METHOD__ . ' old but compatible png metadata' ); + wfDebug( __METHOD__ . " old but compatible png metadata\n" ); return self::METADATA_COMPATIBLE; } return self::METADATA_GOOD;