diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-08-12 09:28:15 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-08-12 09:28:15 +0200 |
commit | 08aa4418c30cfc18ccc69a0f0f9cb9e17be6c196 (patch) | |
tree | 577a29fb579188d16003a209ce2a2e9c5b0aa2bd /includes/media/Exif.php | |
parent | cacc939b34e315b85e2d72997811eb6677996cc1 (diff) |
Update to MediaWiki 1.21.1
Diffstat (limited to 'includes/media/Exif.php')
-rw-r--r-- | includes/media/Exif.php | 169 |
1 files changed, 84 insertions, 85 deletions
diff --git a/includes/media/Exif.php b/includes/media/Exif.php index 784a6018..17671808 100644 --- a/includes/media/Exif.php +++ b/includes/media/Exif.php @@ -31,15 +31,15 @@ */ 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 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. + 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 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 @@ -102,8 +102,9 @@ class Exif { /** * Constructor * - * @param $file String: filename. - * @param $byteOrder String 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. * @@ -289,8 +290,8 @@ class Exif { // Only give a warning for b/c, since originally we didn't // require this. The number of things affected by this is // rather small. - wfWarn( 'Exif class did not have byte order specified. ' - . 'Some properties may be decoded incorrectly.' ); + wfWarn( 'Exif class did not have byte order specified. ' . + 'Some properties may be decoded incorrectly.' ); $this->byteOrder = 'BE'; // BE seems about twice as popular as LE in jpg's. } @@ -321,7 +322,7 @@ class Exif { foreach ( array_keys( $this->mRawExifData ) as $section ) { if ( !in_array( $section, array_keys( $this->mExifTags ) ) ) { - $this->debug( $section , __FUNCTION__, "'$section' is not a valid Exif section" ); + $this->debug( $section, __FUNCTION__, "'$section' is not a valid Exif section" ); continue; } @@ -345,24 +346,24 @@ class Exif { } /** - * Collapse some fields together. - * This converts some fields from exif form, to a more friendly form. - * For example GPS latitude to a single number. - * - * The rationale behind this is that we're storing data, not presenting to the user - * For example a longitude is a single number describing how far away you are from - * the prime meridian. Well it might be nice to split it up into minutes and seconds - * for the user, it doesn't really make sense to split a single number into 4 parts - * for storage. (degrees, minutes, second, direction vs single floating point number). - * - * Other things this might do (not really sure if they make sense or not): - * Dates -> mediawiki date format. - * convert values that can be in different units to be in one standardized unit. - * - * As an alternative approach, some of this could be done in the validate phase - * if we make up our own types like Exif::DATE. - */ - function collapseData( ) { + * Collapse some fields together. + * This converts some fields from exif form, to a more friendly form. + * For example GPS latitude to a single number. + * + * The rationale behind this is that we're storing data, not presenting to the user + * For example a longitude is a single number describing how far away you are from + * the prime meridian. Well it might be nice to split it up into minutes and seconds + * for the user, it doesn't really make sense to split a single number into 4 parts + * for storage. (degrees, minutes, second, direction vs single floating point number). + * + * Other things this might do (not really sure if they make sense or not): + * Dates -> mediawiki date format. + * convert values that can be in different units to be in one standardized unit. + * + * As an alternative approach, some of this could be done in the validate phase + * if we make up our own types like Exif::DATE. + */ + function collapseData() { $this->exifGPStoNumber( 'GPSLatitude' ); $this->exifGPStoNumber( 'GPSDestLatitude' ); @@ -386,22 +387,22 @@ class Exif { $this->exifPropToOrd( 'SceneType' ); $this->charCodeString( 'UserComment' ); - $this->charCodeString( 'GPSProcessingMethod'); + $this->charCodeString( 'GPSProcessingMethod' ); $this->charCodeString( 'GPSAreaInformation' ); - + //ComponentsConfiguration should really be an array instead of a string... //This turns a string of binary numbers into an array of numbers. if ( isset ( $this->mFilteredExifData['ComponentsConfiguration'] ) ) { $val = $this->mFilteredExifData['ComponentsConfiguration']; $ccVals = array(); - for ($i = 0; $i < strlen($val); $i++) { - $ccVals[$i] = ord( substr($val, $i, 1) ); + for ( $i = 0; $i < strlen( $val ); $i++ ) { + $ccVals[$i] = ord( substr( $val, $i, 1 ) ); } $ccVals['_type'] = 'ol'; //this is for formatting later. $this->mFilteredExifData['ComponentsConfiguration'] = $ccVals; } - + //GPSVersion(ID) is treated as the wrong type by php exif support. //Go through each byte turning it into a version string. //For example: "\x02\x02\x00\x00" -> "2.2.0.0" @@ -412,11 +413,11 @@ class Exif { if ( isset ( $this->mFilteredExifData['GPSVersion'] ) ) { $val = $this->mFilteredExifData['GPSVersion']; $newVal = ''; - for ($i = 0; $i < strlen($val); $i++) { + for ( $i = 0; $i < strlen( $val ); $i++ ) { if ( $i !== 0 ) { $newVal .= '.'; } - $newVal .= ord( substr($val, $i, 1) ); + $newVal .= ord( substr( $val, $i, 1 ) ); } if ( $this->byteOrder === 'LE' ) { // Need to reverse the string @@ -433,26 +434,25 @@ class Exif { } /** - * Do userComment tags and similar. See pg. 34 of exif standard. - * basically first 8 bytes is charset, rest is value. - * This has not been tested on any shift-JIS strings. - * @param $prop String prop name. - */ + * Do userComment tags and similar. See pg. 34 of exif standard. + * basically first 8 bytes is charset, rest is value. + * This has not been tested on any shift-JIS strings. + * @param string $prop prop name. + */ private function charCodeString ( $prop ) { if ( isset( $this->mFilteredExifData[$prop] ) ) { - if ( strlen($this->mFilteredExifData[$prop]) <= 8 ) { + if ( strlen( $this->mFilteredExifData[$prop] ) <= 8 ) { //invalid. Must be at least 9 bytes long. - $this->debug( $this->mFilteredExifData[$prop] , __FUNCTION__, false ); - unset($this->mFilteredExifData[$prop]); + $this->debug( $this->mFilteredExifData[$prop], __FUNCTION__, false ); + unset( $this->mFilteredExifData[$prop] ); return; } - $charCode = substr( $this->mFilteredExifData[$prop], 0, 8); - $val = substr( $this->mFilteredExifData[$prop], 8); - - - switch ($charCode) { + $charCode = substr( $this->mFilteredExifData[$prop], 0, 8 ); + $val = substr( $this->mFilteredExifData[$prop], 8 ); + + switch ( $charCode ) { case "\x4A\x49\x53\x00\x00\x00\x00\x00": //JIS $charset = "Shift-JIS"; @@ -466,9 +466,9 @@ class Exif { } // This could possibly check to see if iconv is really installed // or if we're using the compatibility wrapper in globalFunctions.php - if ($charset) { + if ( $charset ) { wfSuppressWarnings(); - $val = iconv($charset, 'UTF-8//IGNORE', $val); + $val = iconv( $charset, 'UTF-8//IGNORE', $val ); wfRestoreWarnings(); } else { // if valid utf-8, assume that, otherwise assume windows-1252 @@ -476,17 +476,17 @@ class Exif { UtfNormal::quickIsNFCVerify( $valCopy ); //validates $valCopy. if ( $valCopy !== $val ) { wfSuppressWarnings(); - $val = iconv('Windows-1252', 'UTF-8//IGNORE', $val); + $val = iconv( 'Windows-1252', 'UTF-8//IGNORE', $val ); wfRestoreWarnings(); } } - + //trim and check to make sure not only whitespace. - $val = trim($val); + $val = trim( $val ); if ( strlen( $val ) === 0 ) { //only whitespace. - $this->debug( $this->mFilteredExifData[$prop] , __FUNCTION__, "$prop: Is only whitespace" ); - unset($this->mFilteredExifData[$prop]); + $this->debug( $this->mFilteredExifData[$prop], __FUNCTION__, "$prop: Is only whitespace" ); + unset( $this->mFilteredExifData[$prop] ); return; } @@ -495,21 +495,21 @@ class Exif { } } /** - * Convert an Exif::UNDEFINED from a raw binary string - * to its value. This is sometimes needed depending on - * the type of UNDEFINED field - * @param $prop String name of property - */ + * 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 + */ private function exifPropToOrd ( $prop ) { if ( isset( $this->mFilteredExifData[$prop] ) ) { $this->mFilteredExifData[$prop] = ord( $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) - */ + * 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) + */ private function exifGPStoNumber ( $prop ) { $loc =& $this->mFilteredExifData[$prop]; $dir =& $this->mFilteredExifData[$prop . 'Ref']; @@ -545,7 +545,7 @@ class Exif { * * @deprecated since 1.18 */ - function makeFormattedData( ) { + function makeFormattedData() { wfDeprecated( __METHOD__, '1.18' ); $this->mFormattedExifData = FormatMetadata::getFormattedData( $this->mFilteredExifData ); @@ -580,7 +580,7 @@ class Exif { */ function getFormattedData() { wfDeprecated( __METHOD__, '1.18' ); - if (!$this->mFormattedExifData) { + if ( !$this->mFormattedExifData ) { $this->makeFormattedData(); } return $this->mFormattedExifData; @@ -612,7 +612,7 @@ class Exif { * @return bool */ private function isByte( $in ) { - if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) { + if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 255 ) { $this->debug( $in, __FUNCTION__, true ); return true; } else { @@ -648,7 +648,7 @@ class Exif { * @return bool */ private function isShort( $in ) { - if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) { + if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 65536 ) { $this->debug( $in, __FUNCTION__, true ); return true; } else { @@ -662,7 +662,7 @@ class Exif { * @return bool */ private function isLong( $in ) { - if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) { + if ( !is_array( $in ) && sprintf( '%d', $in ) == $in && $in >= 0 && $in <= 4294967296 ) { $this->debug( $in, __FUNCTION__, true ); return true; } else { @@ -677,7 +677,7 @@ class Exif { */ 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 + if ( !is_array( $in ) && preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero return $this->isLong( $m[1] ) && $this->isLong( $m[2] ); } else { $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' ); @@ -727,8 +727,8 @@ class Exif { * Validates if a tag has a legal value according to the Exif spec * * @private - * @param $section String: section where tag is located. - * @param $tag String: the tag to check. + * @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. * @return bool @@ -748,10 +748,10 @@ class Exif { return false; } if( $count > 1 ) { - foreach( $val as $v ) { + foreach( $val as $v ) { if( !$this->validate( $section, $tag, $v, true ) ) { - return false; - } + return false; + } } return true; } @@ -813,13 +813,13 @@ class Exif { } if ( $action === true ) { - wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n"); + wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n" ); } elseif ( $action === false ) { - wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n"); + wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n" ); } elseif ( $action === null ) { - wfDebugLog( $this->log, "$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"); + wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n" ); } } @@ -828,7 +828,7 @@ class Exif { * * @private * - * @param $fname String: the name of the function calling this function + * @param string $fname the name of the function calling this function * @param $io Boolean: Specify whether we're beginning or ending */ private function debugFile( $fname, $io ) { @@ -843,4 +843,3 @@ class Exif { } } } - |