/**#@+
* 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.
*/
var $mFormattedExifData;
+ /**#@-*/
+
+ /**#@+
+ * @var string
+ * @access private
+ */
+
+ /**
+ * The file being processed
+ */
+ var $file;
+
+ /**
+ * The basename of the file being processed
+ */
+ var $basename;
+
+ /**
+ * The private log to log to
+ */
+ var $log = 'exif';
+
/**#@-*/
/**
),
);
+ $this->file = $file;
+ $this->basename = basename( $this->file );
+
$this->makeFlatExifTags();
+
+ $this->debugFile( $this->basename, __FUNCTION__, true );
wfSuppressWarnings();
- $this->mRawExifData = exif_read_data( $file );
+ $data = exif_read_data( $this->file );
wfRestoreWarnings();
+ /**
+ * exif_read_data() will return false on invalid input, such as
+ * when somebody uploads a file called something.jpeg
+ * containing random gibberish.
+ */
+ $this->mRawExifData = $data ? $data : array();
+
$this->makeFilteredData();
$this->makeFormattedData();
+
+ $this->debugFile( __FUNCTION__, false );
}
/**#@+
$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
- wfDebug( "$class::$fname: $action (type: $type; content: '$in')\n");
+ 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( $fname, $io ) {
+ $class = ucfirst( __CLASS__ );
+ if ( $io )
+ wfDebugLog( $this->log, "$class::$fname: begin processing: '{$this->basename}'\n" );
+ else
+ wfDebugLog( $this->log, "$class::$fname: end processing: '{$this->basename}'\n" );
}
}
case 'Software':
$tags[$tag] = $this->msg( $tag, '', $val );
break;
+
+ case 'ExposureTime':
+ // Show the pretty fraction as well as decimal version
+ $tags[$tag] = wfMsg( 'exif-exposuretime-format',
+ $this->formatFraction( $val ), $this->formatNum( $val ) );
+ break;
+
+ case 'FNumber':
+ $tags[$tag] = wfMsg( 'exif-fnumber-format',
+ $this->formatNum( $val ) );
+ break;
+
+ case 'FocalLength':
+ $tags[$tag] = wfMsg( 'exif-focallength-format',
+ $this->formatNum( $val ) );
+ break;
+
default:
$tags[$tag] = $this->formatNum( $val );
break;
* @return string A wfMsg of "exif-$tag-$val" in lower case
*/
function msg( $tag, $val, $arg = null ) {
+ global $wgContLang;
+
if ($val === '')
$val = 'value';
- return wfMsg( strtolower( "exif-$tag-$val" ), $arg );
+ return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
}
/**
else
return $num;
}
+
+ /**
+ * Format a rational number, reducing fractions
+ *
+ * @access private
+ *
+ * @param mixed $num The value to format
+ * @return mixed A floating point number or whatever we were fed
+ */
+ function formatFraction( $num ) {
+ if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
+ $numerator = intval( $m[1] );
+ $denominator = intval( $m[2] );
+ $gcd = $this->gcd( $numerator, $denominator );
+ if( $gcd != 0 ) {
+ // 0 shouldn't happen! ;)
+ return $numerator / $gcd . '/' . $denominator / $gcd;
+ }
+ }
+ return $this->formatNum( $num );
+ }
+
+ /**
+ * Calculate the greatest common divisor of two integers.
+ *
+ * @param int $a
+ * @param int $b
+ * @return int
+ * @access private
+ */
+ function gcd( $a, $b ) {
+ /*
+ // http://en.wikipedia.org/wiki/Euclidean_algorithm
+ // Recursive form would be:
+ if( $b == 0 )
+ return $a;
+ else
+ return gcd( $b, $a % $b );
+ */
+ while( $b != 0 ) {
+ $remainder = $a % $b;
+
+ // tail recursion...
+ $a = $b;
+ $b = $remainder;
+ }
+ return $a;
+ }
}