Automatic EXIF update upon viewing
authorMagnus Manske <magnusmanske@users.mediawiki.org>
Thu, 21 Apr 2005 12:59:32 +0000 (12:59 +0000)
committerMagnus Manske <magnusmanske@users.mediawiki.org>
Thu, 21 Apr 2005 12:59:32 +0000 (12:59 +0000)
includes/Image.php
includes/ImagePage.php
includes/exifReader.inc

index 6d2350e..897224e 100644 (file)
@@ -1141,20 +1141,36 @@ class Image
        function getExifData () {
                global $wgShowEXIF ;
                if ( ! $wgShowEXIF ) return array () ;
+               
+               $ret = unserialize ( $this->exif ) ;
+               if ( count ( $ret ) == 0 ) { # No EXIF data was stored for this image
+                       $this->updateExifData() ;
+                       $ret = unserialize ( $this->exif ) ;
+                       }
 
-               return unserialize ( $this->exif ) ;
-               #return $this->retrieveExifData () ;
+               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 () ;
-               $exif = serialize ( $exif ) ;
+               $this->exif = serialize ( $exif ) ;
                
+               # Update EXIF data in database
+               $dbw =& wfGetDB( DB_MASTER );
+               $dbw->update( '`image`', 
+                       array( 'img_exif' => $this->exif ),
+                       array( 'img_name' => $this->name ),
+                       $fname
+               );
                }
-*/
+
 
 } //class
 
index ab2ea39..4c40fcb 100644 (file)
@@ -61,7 +61,8 @@ class ImagePage extends Article {
 
                # Get the EXIF data
                $exif = $this->img->getExifData () ;
-               if ( count ( $exif ) == 0 ) return ; # No EXIF data
+               if ( count ( $exif ) == 0 ) return ; # No EXIF data available
+               if ( count ( $exif ) == 1 && isset ( $exif["EXIF"] ) && $exif["EXIF"] == "NO" ) return ; # This image does not have EXIF data
                
                # Create the table
                $r = "<table border='1' cellspacing='0' cellpadding='0' align='right'>" ;
index 158621a..3bcc74f 100644 (file)
@@ -1406,7 +1406,7 @@ class phpExifReader {
 
         $imgInfo = $this->ImageInfo["h"];
 
-               if ( !isset ( $imgInfo["Width"] ) ) return array () ;
+               if ( !isset ( $imgInfo["Width"] ) ) return array ( "EXIF" => "NO" ) ; # Dummy entry to distinguish von empty (=never generated) one
 
         $retArr = $imgInfo;
         $retArr["FileName"] = $imgInfo["FileName"];