* (bug 3598) Update message cache on message page deletion, patch by Tietew
[lhc/web/wiklou.git] / includes / Exif.php
index 5c89b68..cf79423 100644 (file)
@@ -30,7 +30,7 @@ if ( !defined( 'MEDIAWIKI' ) ) die();
 /**#@+
  * Exif tag type definition
  */
-define('MW_EXIF_BYTE', 1);             # An 8-bit unsigned integer.
+define('MW_EXIF_BYTE', 1);             # An 8-bit (1-byte) unsigned integer.
 define('MW_EXIF_ASCII', 2);            # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
 define('MW_EXIF_SHORT', 3);            # A 16-bit (2-byte) unsigned integer.
 define('MW_EXIF_LONG', 4);             # A 32-bit (4-byte) unsigned integer.
@@ -82,8 +82,18 @@ class Exif {
        
        /**#@-*/
 
+       /**
+        * The private log to log to
+        *
+        * @var string
+        * @access private
+        */
+       var $log = 'exif';
+
        /**
         * Constructor
+        *
+        * @param string $file
         */
        function Exif( $file ) {
                /**
@@ -271,12 +281,19 @@ class Exif {
                        ),
                );
 
+               $basename = basename( $file );
+               
                $this->makeFlatExifTags();
+               
+               $this->debugFile( $basename, __FUNCTION__, true );
                wfSuppressWarnings();
                $this->mRawExifData = exif_read_data( $file );
                wfRestoreWarnings();
+               
                $this->makeFilteredData();
                $this->makeFormattedData();
+               
+               $this->debugFile( $basename, __FUNCTION__, false );
        }
        
        /**#@+
@@ -305,8 +322,6 @@ class Exif {
                }
        }
        
-       /**#@-*/
-       
        /**
         * Make $this->mFilteredExifData
         */
@@ -377,7 +392,9 @@ class Exif {
 
        /**#@+
         * Validates if a tag value is of the type it should be according to the Exif spec
-        * 
+        *
+        * @access private
+        *
         * @param mixed $in The input value to check
         * @return bool
         */
@@ -402,11 +419,6 @@ class Exif {
                        return false;
                }
                
-               if ( strlen($in) > 1024 ) { // TODO: This might not be according to the spec
-                       $this->debug( $in, __FUNCTION__, 'input was too long' );
-                       return false;
-               }
-               
                return true;
        }
 
@@ -472,6 +484,8 @@ class Exif {
        /**
         * Validates if a tag has a legal value according to the Exif spec
         *
+        * @access private
+        *
         * @param string $tag The tag to check
         * @param mixed  $val The value of the tag
         * @return bool
@@ -516,6 +530,8 @@ class Exif {
        /**
         * Conviniance function for debugging output
         *
+        * @access private
+        *
         * @param mixed $in 
         * @param string $fname
         * @param mixed $action
@@ -527,13 +543,30 @@ class Exif {
                        $in = print_r( $in, true ); 
         
                if ( $action === true )
-                       wfDebug( "$class::$fname: accepted: '$in' (type: $type)\n");
+                       wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n");
                elseif ( $action === false ) 
-                       wfDebug( "$class::$fname: rejected: '$in' (type: $type)\n");
+                       wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n");
                elseif ( $action === null )
-                       wfDebug( "$class::$fname: input was: '$in' (type: $type)\n");
+                       wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)\n");
+               else
+                       wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n");
+       }
+
+       /**
+        * Conviniance function for debugging output
+        *
+        * @access private
+        *
+        * @param string $basename The name of the file being processed
+        * @paran string $fname The name of the function calling this function
+        * @param bool $bool $io Specify whether we're beginning or ending
+        */
+       function debugFile( $basename, $fname, $io ) {
+               $class = ucfirst( __CLASS__ );
+               if ( $io )
+                       wfDebugLog( $this->log, "$class::$fname: begin processing: '$basename'\n" );
                else
-                       wfDebug( "$class::$fname: $action (type: $type; content: '$in')\n");
+                       wfDebugLog( $this->log, "$class::$fname: end processing: '$basename'\n" );
        }
 
 }
@@ -573,6 +606,9 @@ class FormatExif {
                global $wgLang;
                
                $tags =& $this->mExif;
+
+               $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
+               unset( $tags['ResolutionUnit'] );
                
                foreach( $tags as $tag => $val ) {
                        switch( $tag ) {
@@ -622,18 +658,22 @@ class FormatExif {
                        
                        // TODO: YCbCrSubSampling
                        // TODO: YCbCrPositioning
-                       // TODO: If this field does not exists use 2
-                       case 'ResolutionUnit': #p26
-                               switch( $val ) {
-                               case 2: case 3:
-                                       $tags[$tag] = $this->msg( $tag, $val );
-                                       break;
-                               default:
-                                       $tags[$tag] = $val;
-                                       break;
+                       
+                       case 'XResolution':
+                       case 'YResolution':
+                               switch( $resolutionunit ) {
+                                       case 2:
+                                               $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
+                                               break;
+                                       case 3:
+                                               $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
+                                               break;
+                                       default:
+                                               $tags[$tag] = $val;
+                                               break;
                                }
                                break;
-                       
+                               
                        // TODO: YCbCrCoefficients  #p27 (see annex E)
                        case 'ExifVersion': case 'FlashpixVersion':
                                $tags[$tag] = "$val"/100;
@@ -945,6 +985,8 @@ class FormatExif {
        /**
         * Conviniance function for getFormattedData()
         *
+        * @access private
+        *
         * @param string $tag The tag name to pass on
         * @param string $val The value of the tag
         * @param string $arg An argument to pass ($1)
@@ -957,6 +999,11 @@ class FormatExif {
        }
 
        /**
+        * Format a number, convert numbers from fractions into floating point
+        * numbers
+        *
+        * @access private
+        *
         * @param mixed $num The value to format
         * @return mixed A floating point number or whatever we were fed
         */