* @ingroup Media
*/
class Exif {
- const BYTE = 1; //!< An 8-bit (1-byte) unsigned integer.
- const ASCII = 2; //!< An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
- const SHORT = 3; //!< A 16-bit (2-byte) unsigned integer.
- const LONG = 4; //!< A 32-bit (4-byte) unsigned integer.
- const RATIONAL = 5; //!< Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator
- const SHORT_OR_LONG = 6; //!< A 16-bit (2-byte) or 32-bit (4-byte) unsigned integer.
- const UNDEFINED = 7; //!< An 8-bit byte that can take any value depending on the field definition
- const SLONG = 9; //!< A 32-bit (4-byte) signed integer (2's complement notation),
- const SRATIONAL = 10; //!< Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
- const IGNORE = -1; // A fake value for things we don't want or don't support.
-
- //@{
- /* @var array
- * @private
- */
+ /** An 8-bit (1-byte) unsigned integer. */
+ const BYTE = 1;
- /**
- * Exif tags grouped by category, the tagname itself is the key and the type
- * is the value, in the case of more than one possible value type they are
- * separated by commas.
+ /** An 8-bit byte containing one 7-bit ASCII code.
+ * The final byte is terminated with NULL.
*/
- var $mExifTags;
+ const ASCII = 2;
- /**
- * The raw Exif data returned by exif_read_data()
- */
- var $mRawExifData;
+ /** A 16-bit (2-byte) unsigned integer. */
+ const SHORT = 3;
- /**
- * A Filtered version of $mRawExifData that has been pruned of invalid
- * tags and tags that contain content they shouldn't contain according
- * to the Exif specification
- */
- var $mFilteredExifData;
+ /** A 32-bit (4-byte) unsigned integer. */
+ const LONG = 4;
- /**
- * Filtered and formatted Exif data, see FormatMetadata::getFormattedData()
+ /** Two LONGs. The first LONG is the numerator and the second LONG expresses
+ * the denominator
*/
- var $mFormattedExifData;
+ const RATIONAL = 5;
- //@}
+ /** A 16-bit (2-byte) or 32-bit (4-byte) unsigned integer. */
+ const SHORT_OR_LONG = 6;
- //@{
- /* @var string
- * @private
- */
+ /** An 8-bit byte that can take any value depending on the field definition */
+ const UNDEFINED = 7;
- /**
- * The file being processed
+ /** A 32-bit (4-byte) signed integer (2's complement notation), */
+ const SLONG = 9;
+
+ /** Two SLONGs. The first SLONG is the numerator and the second SLONG is
+ * the denominator.
*/
- var $file;
+ const SRATIONAL = 10;
- /**
- * The basename of the file being processed
+ /** A fake value for things we don't want or don't support. */
+ const IGNORE = -1;
+
+ /** @var array Exif tags grouped by category, the tagname itself is the key
+ * and the type is the value, in the case of more than one possible value
+ * type they are separated by commas.
*/
- var $basename;
+ private $mExifTags;
- /**
- * The private log to log to, e.g. 'exif'
+ /** @var array The raw Exif data returned by exif_read_data() */
+ private $mRawExifData;
+
+ /** @var array A Filtered version of $mRawExifData that has been pruned
+ * of invalid tags and tags that contain content they shouldn't contain
+ * according to the Exif specification
*/
- var $log = false;
+ private $mFilteredExifData;
- /**
- * The byte order of the file. Needed because php's
- * extension doesn't fully process some obscure props.
+ /** @var string The file being processed */
+ private $file;
+
+ /** @var string The basename of the file being processed */
+ private $basename;
+
+ /** @var string The private log to log to, e.g. 'exif' */
+ private $log = false;
+
+ /** @var string The byte order of the file. Needed because php's extension
+ * doesn't fully process some obscure props.
*/
private $byteOrder;
- //@}
-
/**
* Constructor
*
- * @param string $file filename.
- * @param string $byteOrder Type of byte ordering either 'BE' (Big Endian) or 'LE' (Little Endian). Default ''.
+ * @param string $file Filename.
+ * @param string $byteOrder Type of byte ordering either 'BE' (Big Endian)
+ * or 'LE' (Little Endian). Default ''.
* @throws MWException
* @todo FIXME: The following are broke:
- * SubjectArea. Need to test the more obscure tags.
- *
- * DigitalZoomRatio = 0/0 is rejected. need to determine if that's valid.
- * possibly should treat 0/0 = 0. need to read exif spec on that.
+ * SubjectArea. Need to test the more obscure tags.
+ * DigitalZoomRatio = 0/0 is rejected. need to determine if that's valid.
+ * Possibly should treat 0/0 = 0. need to read exif spec on that.
*/
function __construct( $file, $byteOrder = '' ) {
/**
'TransferFunction' => Exif::IGNORE, # Transfer function
'WhitePoint' => array( Exif::RATIONAL, 2 ), # White point chromaticity
'PrimaryChromaticities' => array( Exif::RATIONAL, 6 ), # Chromaticities of primarities
- 'YCbCrCoefficients' => array( Exif::RATIONAL, 3 ), # Color space transformation matrix coefficients #p27
+ # Color space transformation matrix coefficients #p27
+ 'YCbCrCoefficients' => array( Exif::RATIONAL, 3 ),
'ReferenceBlackWhite' => array( Exif::RATIONAL, 6 ), # Pair of black and white reference values
# Other tags
# Exif IFD Attribute Information (p30-31)
'EXIF' => array(
- # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
+ # @todo NOTE: Nonexistence of this field is taken to mean nonconformance
# to the Exif 2.1 AND 2.2 standards
'ExifVersion' => Exif::UNDEFINED, # Exif version
'FlashPixVersion' => Exif::UNDEFINED, # Supported Flashpix version #p32
$data = exif_read_data( $this->file, 0, true );
wfRestoreWarnings();
} else {
- throw new MWException( "Internal error: exif_read_data not present. \$wgShowEXIF may be incorrectly set or not checked by an extension." );
+ throw new MWException( "Internal error: exif_read_data not present. " .
+ "\$wgShowEXIF may be incorrectly set or not checked by an extension." );
}
/**
* 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->mRawExifData = $data ?: array();
$this->makeFilteredData();
$this->collapseData();
$this->debugFile( __FUNCTION__, false );
$this->exifGPStoNumber( 'GPSLongitude' );
$this->exifGPStoNumber( 'GPSDestLongitude' );
- if ( isset( $this->mFilteredExifData['GPSAltitude'] ) && isset( $this->mFilteredExifData['GPSAltitudeRef'] ) ) {
-
- // We know altitude data is a <num>/<denom> from the validation functions ran earlier.
- // But multiplying such a string by -1 doesn't work well, so convert.
+ if ( isset( $this->mFilteredExifData['GPSAltitude'] )
+ && isset( $this->mFilteredExifData['GPSAltitudeRef'] )
+ ) {
+ // We know altitude data is a <num>/<denom> from the validation
+ // functions ran earlier. But multiplying such a string by -1
+ // doesn't work well, so convert.
list( $num, $denom ) = explode( '/', $this->mFilteredExifData['GPSAltitude'] );
$this->mFilteredExifData['GPSAltitude'] = $num / $denom;
if ( isset( $this->mFilteredExifData['ComponentsConfiguration'] ) ) {
$val = $this->mFilteredExifData['ComponentsConfiguration'];
$ccVals = array();
- for ( $i = 0; $i < strlen( $val ); $i++ ) {
+
+ $strLen = strlen( $val );
+ for ( $i = 0; $i < $strLen; $i++ ) {
$ccVals[$i] = ord( substr( $val, $i, 1 ) );
}
$ccVals['_type'] = 'ol'; //this is for formatting later.
if ( isset( $this->mFilteredExifData['GPSVersion'] ) ) {
$val = $this->mFilteredExifData['GPSVersion'];
$newVal = '';
- for ( $i = 0; $i < strlen( $val ); $i++ ) {
+
+ $strLen = strlen( $val );
+ for ( $i = 0; $i < $strLen; $i++ ) {
if ( $i !== 0 ) {
$newVal .= '.';
}
$newVal .= ord( substr( $val, $i, 1 ) );
}
+
if ( $this->byteOrder === 'LE' ) {
// Need to reverse the string
$newVal2 = '';
* Convert an Exif::UNDEFINED from a raw binary string
* to its value. This is sometimes needed depending on
* the type of UNDEFINED field
- * @param string $prop name of property
+ * @param string $prop Name of property
*/
private function exifPropToOrd( $prop ) {
if ( isset( $this->mFilteredExifData[$prop] ) ) {
/**
* Convert gps in exif form to a single floating point number
* for example 10 degress 20`40`` S -> -10.34444
- * @param string $prop a gps coordinate exif tag name (like GPSLongitude)
+ * @param string $prop A GPS coordinate exif tag name (like GPSLongitude)
*/
private function exifGPStoNumber( $prop ) {
$loc =& $this->mFilteredExifData[$prop];
$dir =& $this->mFilteredExifData[$prop . 'Ref'];
$res = false;
- if ( isset( $loc ) && isset( $dir ) && ( $dir === 'N' || $dir === 'S' || $dir === 'E' || $dir === 'W' ) ) {
+ if ( isset( $loc ) && isset( $dir )
+ && ( $dir === 'N' || $dir === 'S' || $dir === 'E' || $dir === 'W' )
+ ) {
list( $num, $denom ) = explode( '/', $loc[0] );
$res = $num / $denom;
list( $num, $denom ) = explode( '/', $loc[1] );
}
}
- /**
- * Use FormatMetadata to create formatted values for display to user
- * (is this ever used?)
- *
- * @deprecated since 1.18
- */
- function makeFormattedData() {
- wfDeprecated( __METHOD__, '1.18' );
- $this->mFormattedExifData = FormatMetadata::getFormattedData(
- $this->mFilteredExifData );
- }
-
/**#@-*/
/**#@+
return $this->mFilteredExifData;
}
- /**
- * Get $this->mFormattedExifData
- *
- * This returns the data for display to user.
- * Its unclear if this is ever used.
- *
- * @deprecated since 1.18
- */
- function getFormattedData() {
- wfDeprecated( __METHOD__, '1.18' );
- if ( !$this->mFormattedExifData ) {
- $this->makeFormattedData();
- }
-
- return $this->mFormattedExifData;
- }
-
/**#@-*/
/**
/**#@+
* Validates if a tag value is of the type it should be according to the Exif spec
*
- * @private
- *
- * @param $in Mixed: the input value to check
+ * @param mixed $in The input value to check
* @return bool
*/
private function isByte( $in ) {
}
/**
- * @param $in
+ * @param mixed $in The input value to check
* @return bool
*/
private function isASCII( $in ) {
}
/**
- * @param $in
+ * @param mixed $in The input value to check
* @return bool
*/
private function isShort( $in ) {
}
/**
- * @param $in
+ * @param mixed $in The input value to check
* @return bool
*/
private function isLong( $in ) {
}
/**
- * @param $in
+ * @param mixed $in The input value to check
* @return bool
*/
private function isRational( $in ) {
$m = array();
- if ( !is_array( $in ) && preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
+
+ # Avoid division by zero
+ if ( !is_array( $in )
+ && preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m )
+ ) {
return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
} else {
$this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
}
/**
- * @param $in
+ * @param mixed $in The input value to check
* @return bool
*/
private function isUndefined( $in ) {
}
/**
- * @param $in
+ * @param mixed $in The input value to check
* @return bool
*/
private function isSlong( $in ) {
}
/**
- * @param $in
+ * @param mixed $in The input value to check
* @return bool
*/
private function isSrational( $in ) {
$m = array();
- if ( !is_array( $in ) && preg_match( '/^(-?\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
+
+ # Avoid division by zero
+ if ( !is_array( $in ) &&
+ preg_match( '/^(-?\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m )
+ ) {
return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
} else {
$this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
/**
* Validates if a tag has a legal value according to the Exif spec
*
- * @private
* @param string $section section where tag is located.
* @param string $tag the tag to check.
- * @param $val Mixed: the value of the tag.
- * @param $recursive Boolean: true if called recursively for array types.
+ * @param mixed $val The value of the tag.
+ * @param bool $recursive True if called recursively for array types.
* @return bool
*/
private function validate( $section, $tag, $val, $recursive = false ) {
/**
* Convenience function for debugging output
*
- * @private
- *
- * @param $in Mixed:
- * @param $fname String:
- * @param $action Mixed: , default NULL.
+ * @param mixed $in Arrays will be processed with print_r().
+ * @param string $fname Function name to log.
+ * @param string|bool|null $action Default null.
*/
private function debug( $in, $fname, $action = null ) {
if ( !$this->log ) {
/**
* Convenience function for debugging output
*
- * @private
- *
* @param string $fname the name of the function calling this function
- * @param $io Boolean: Specify whether we're beginning or ending
+ * @param bool $io Specify whether we're beginning or ending
*/
private function debugFile( $fname, $io ) {
if ( !$this->log ) {