From 04b79884fbeedf786b3c3bfd099a8215fc1c5f84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 9 May 2005 11:26:44 +0000 Subject: [PATCH] * Improved the debug output of retrieveExifData() * Implemented the Exif::version() check, if the version in the stored metadata does not match the current version the exif data is regenerated and the current version saved in the metadata. Ensured that old images are updated in the future if the output format is changed. --- includes/Image.php | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/includes/Image.php b/includes/Image.php index 2352d6fd67..105c4269ee 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -1137,7 +1137,14 @@ class Image $db->freeResult( $res ); return $retVal; } - + /** + * Retrive Exif data from the database + * + * Retrive Exif data from the database and prune unrecognized tags + * and/or tags with invalid contents + * + * @return array + */ function retrieveExifData () { global $wgShowEXIF ; if ( ! $wgShowEXIF ) return array (); @@ -1147,14 +1154,14 @@ class Image foreach($exif as $k => $v) { if ( !in_array($k, $this->exif->mValidExif) ) { - wfDebug( "Image::retrieveExifData: '$k' was not a valid Exif tag (contents: '$v')\n"); + wfDebug( "Image::retrieveExifData: '$k' is not a valid Exif tag (type: '" . gettype($v) . "'; data: '$v')\n"); unset($exif[$k]); } } foreach($exif as $k => $v) { if ( !$this->exif->validate($k, $v) ) { - wfDebug( "Image::retrieveExifData: '$k' did not contain valid contents (contents: '$v')\n"); + wfDebug( "Image::retrieveExifData: '$k' contained invalid data (type: '" . gettype($v) . "'; data: '$v')\n"); unset($exif[$k]); } } @@ -1164,29 +1171,39 @@ class Image function getExifData () { global $wgRequest; + $purge = $wgRequest->getVal( 'action' ) == 'purge'; $ret = unserialize ( $this->metadata ); - if ( count( $ret) == 0 || $wgRequest->getVal( 'action' ) == 'purge' ) { # No EXIF data was stored for this image - $this->updateExifData() ; - $ret = unserialize ( $this->metadata ) ; + $oldver = isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) ? $ret['MEDIAWIKI_EXIF_VERSION'] : 0; + $newver = $this->exif->version(); + + if ( !count( $ret ) || $purge || $oldver != $newver ) { + echo "old: $oldver; new: $newver\n"; + echo "updating\n"; + $this->updateExifData( $newver ); + $ret = unserialize( $this->metadata ); } + if ( isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) ) + unset( $ret['MEDIAWIKI_EXIF_VERSION'] ); foreach($ret as $k => $v) { $ret[$k] = $this->exif->format($k, $v); } + return $ret; } - function updateExifData () { - global $wgShowEXIF ; - if ( ! $wgShowEXIF ) return ; - if ( false === $this->getImagePath() ) return ; # Not a local image + function updateExifData( $version ) { + global $wgShowEXIF; + $fname = 'Image:updateExifData'; - $fname = "Image:updateExifData" ; + if ( ! $wgShowEXIF || $this->getImagePath() === false ) # Not a local image + return; # Get EXIF data from image - $exif = $this->retrieveExifData () ; - $this->metadata = serialize ( $exif ); + $exif = $this->retrieveExifData(); + $exif['MEDIAWIKI_EXIF_VERSION'] = $version; + $this->metadata = serialize( $exif ); # Update EXIF data in database $dbw =& wfGetDB( DB_MASTER ); -- 2.20.1