X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FExifBitmap.php;h=4bbafc1af6808160dae050ad58d8350fe447842c;hb=bad8847147778997818a2cbdd8c1ea0d5fe7ac65;hp=d3fa36dddc26dd3232f8c4d52f946e13c3fce36b;hpb=29b86059736b251162e3ecad21f2f4a2d1bc0bbc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/ExifBitmap.php b/includes/media/ExifBitmap.php index d3fa36dddc..4bbafc1af6 100644 --- a/includes/media/ExifBitmap.php +++ b/includes/media/ExifBitmap.php @@ -28,7 +28,6 @@ * @ingroup Media */ class ExifBitmapHandler extends BitmapHandler { - const BROKEN_FILE = '-1'; // error extracting metadata const OLD_BROKEN_FILE = '0'; // outdated error extracting metadata. @@ -76,9 +75,15 @@ class ExifBitmapHandler extends BitmapHandler { } } $metadata['MEDIAWIKI_EXIF_VERSION'] = 1; + return $metadata; } + /** + * @param $image + * @param array $metadata + * @return bool|int + */ function isMetadataValid( $image, $metadata ) { global $wgShowEXIF; if ( !$wgShowEXIF ) { @@ -89,6 +94,7 @@ class ExifBitmapHandler extends BitmapHandler { # 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; } if ( $metadata === self::BROKEN_FILE ) { @@ -97,25 +103,28 @@ class ExifBitmapHandler extends BitmapHandler { wfSuppressWarnings(); $exif = unserialize( $metadata ); wfRestoreWarnings(); - if ( !isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) || - $exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() ) - { - if ( isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) && - $exif['MEDIAWIKI_EXIF_VERSION'] == 1 ) - { + if ( !isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) + || $exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() + ) { + if ( isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) + && $exif['MEDIAWIKI_EXIF_VERSION'] == 1 + ) { //back-compatible but old wfDebug( __METHOD__ . ": back-compat version\n" ); + return self::METADATA_COMPATIBLE; } # Wrong (non-compatible) version wfDebug( __METHOD__ . ": wrong version\n" ); + return self::METADATA_BAD; } + return self::METADATA_GOOD; } /** - * @param $image File + * @param File $image * @return array|bool */ function formatMetadata( $image ) { @@ -129,10 +138,10 @@ class ExifBitmapHandler extends BitmapHandler { public function getCommonMetaArray( File $file ) { $metadata = $file->getMetadata(); - if ( $metadata === self::OLD_BROKEN_FILE || - $metadata === self::BROKEN_FILE || - $this->isMetadataValid( $file, $metadata ) === self::METADATA_BAD ) - { + if ( $metadata === self::OLD_BROKEN_FILE + || $metadata === self::BROKEN_FILE + || $this->isMetadataValid( $file, $metadata ) === self::METADATA_BAD + ) { // So we don't try and display metadata from PagedTiffHandler // for example when using InstantCommons. return array(); @@ -160,12 +169,11 @@ class ExifBitmapHandler extends BitmapHandler { * @return array */ function getImageSize( $image, $path ) { - global $wgEnableAutoRotation; $gis = parent::getImageSize( $image, $path ); // Don't just call $image->getMetadata(); FSFile::getPropsFromPath() calls us with a bogus object. // This may mean we read EXIF data twice on initial upload. - if ( $wgEnableAutoRotation ) { + if ( BitmapHandler::autoRotateEnabled() ) { $meta = $this->getMetadata( $image, $path ); $rotation = $this->getRotationForExif( $meta ); } else { @@ -177,6 +185,7 @@ class ExifBitmapHandler extends BitmapHandler { $gis[0] = $gis[1]; $gis[1] = $width; } + return $gis; } @@ -193,12 +202,12 @@ class ExifBitmapHandler extends BitmapHandler { * @return int 0, 90, 180 or 270 */ public function getRotation( $file ) { - global $wgEnableAutoRotation; - if ( !$wgEnableAutoRotation ) { + if ( !BitmapHandler::autoRotateEnabled() ) { return 0; } $data = $file->getMetadata(); + return $this->getRotationForExif( $data ); } @@ -208,8 +217,7 @@ class ExifBitmapHandler extends BitmapHandler { * * @param string $data * @return int 0, 90, 180 or 270 - * @todo FIXME orientation can include flipping as well; see if this is an - * issue! + * @todo FIXME: Orientation can include flipping as well; see if this is an issue! */ protected function getRotationForExif( $data ) { if ( !$data ) { @@ -231,6 +239,7 @@ class ExifBitmapHandler extends BitmapHandler { return 0; } } + return 0; } }