+ function retrieveExifData () {
+ global $wgShowEXIF ;
+ if ( ! $wgShowEXIF ) return array ();
+ if ( $this->type !== '2' ) return array ();
+
+ $exif = exif_read_data( $this->imagePath );
+
+ $obj = new Exif;
+ // Some of the type checks in validate will spew warnings on invalid data
+ wfSuppressWarnings();
+ foreach($exif as $k => $v) {
+ if ( !in_array($k, $obj->mValidExif) || !$obj->validate($k, $v) )
+ unset($exif[$k]);
+ }
+ wfRestoreWarnings();
+
+ return $exif;
+ }
+
+ function getExifData () {
+ global $wgRequest;
+
+ $ret = unserialize ( $this->exif );
+
+ if ( count( $ret) == 0 || $wgRequest->getVal( 'action' ) == 'purge' ) { # No EXIF data was stored for this image
+ $this->updateExifData() ;
+ $ret = unserialize ( $this->exif ) ;
+ }
+
+ return $ret ;
+ }
+
+ function updateExifData () {
+ global $wgShowEXIF ;
+ if ( ! $wgShowEXIF ) return ;
+ if ( false === $this->getImagePath() ) return ; # Not a local image
+
+ $fname = "Image:updateExifData" ;
+
+ # Get EXIF data from image
+ $exif = $this->retrieveExifData () ;
+ $this->exif = serialize ( $exif ) ;
+
+ # Update EXIF data in database
+ $dbw =& wfGetDB( DB_MASTER );
+ $dbw->update( 'image',
+ array( 'img_metadata' => $this->exif ),
+ array( 'img_name' => $this->name ),
+ $fname
+ );
+ }
+