Merge "Move up devunt's name to Developers"
[lhc/web/wiklou.git] / includes / media / Exif.php
index b4cc43e..95fa859 100644 (file)
@@ -116,13 +116,13 @@ class Exif {
                 *
                 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
                 */
-               $this->mExifTags = array(
+               $this->mExifTags = [
                        # TIFF Rev. 6.0 Attribute Information (p22)
-                       'IFD0' => array(
+                       'IFD0' => [
                                # Tags relating to image structure
                                'ImageWidth' => Exif::SHORT_OR_LONG, # Image width
                                'ImageLength' => Exif::SHORT_OR_LONG, # Image height
-                               'BitsPerSample' => array( Exif::SHORT, 3 ), # Number of bits per component
+                               'BitsPerSample' => [ Exif::SHORT, 3 ], # Number of bits per component
                                # "When a primary image is JPEG compressed, this designation is not"
                                # "necessary and is omitted." (p23)
                                'Compression' => Exif::SHORT, # Compression scheme #p23
@@ -130,7 +130,7 @@ class Exif {
                                'Orientation' => Exif::SHORT, # Orientation of image #p24
                                'SamplesPerPixel' => Exif::SHORT, # Number of components
                                'PlanarConfiguration' => Exif::SHORT, # Image data arrangement #p24
-                               'YCbCrSubSampling' => array( Exif::SHORT, 2 ), # Subsampling ratio of Y to C #p24
+                               'YCbCrSubSampling' => [ Exif::SHORT, 2 ], # Subsampling ratio of Y to C #p24
                                'YCbCrPositioning' => Exif::SHORT, # Y and C positioning #p24-25
                                'XResolution' => Exif::RATIONAL, # Image resolution in width direction
                                'YResolution' => Exif::RATIONAL, # Image resolution in height direction
@@ -145,11 +145,11 @@ class Exif {
 
                                # Tags relating to image data characteristics
                                'TransferFunction' => Exif::IGNORE, # Transfer function
-                               'WhitePoint' => array( Exif::RATIONAL, 2 ), # White point chromaticity
-                               'PrimaryChromaticities' => array( Exif::RATIONAL, 6 ), # Chromaticities of primarities
+                               'WhitePoint' => [ Exif::RATIONAL, 2 ], # White point chromaticity
+                               'PrimaryChromaticities' => [ Exif::RATIONAL, 6 ], # Chromaticities of primarities
                                # Color space transformation matrix coefficients #p27
-                               'YCbCrCoefficients' => array( Exif::RATIONAL, 3 ),
-                               'ReferenceBlackWhite' => array( Exif::RATIONAL, 6 ), # Pair of black and white reference values
+                               'YCbCrCoefficients' => [ Exif::RATIONAL, 3 ],
+                               'ReferenceBlackWhite' => [ Exif::RATIONAL, 6 ], # Pair of black and white reference values
 
                                # Other tags
                                'DateTime' => Exif::ASCII, # File change date and time
@@ -159,10 +159,10 @@ class Exif {
                                'Software' => Exif::ASCII, # Software used
                                'Artist' => Exif::ASCII, # Person who created the image
                                'Copyright' => Exif::ASCII, # Copyright holder
-                       ),
+                       ],
 
                        # Exif IFD Attribute Information (p30-31)
-                       'EXIF' => array(
+                       'EXIF' => [
                                # @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
@@ -174,8 +174,8 @@ class Exif {
                                # Tags relating to image configuration
                                'ComponentsConfiguration' => Exif::UNDEFINED, # Meaning of each component #p33
                                'CompressedBitsPerPixel' => Exif::RATIONAL, # Image compression mode
-                               'PixelYDimension' => Exif::SHORT_OR_LONG, # Valid image width
-                               'PixelXDimension' => Exif::SHORT_OR_LONG, # Valid image height
+                               'PixelYDimension' => Exif::SHORT_OR_LONG, # Valid image height
+                               'PixelXDimension' => Exif::SHORT_OR_LONG, # Valid image width
 
                                # Tags relating to related user information
                                'MakerNote' => Exif::IGNORE, # Manufacturer notes
@@ -209,13 +209,13 @@ class Exif {
                                'LightSource' => Exif::SHORT, # Light source #p40-41
                                'Flash' => Exif::SHORT, # Flash #p41-42
                                'FocalLength' => Exif::RATIONAL, # Lens focal length
-                               'SubjectArea' => array( Exif::SHORT, 4 ), # Subject area
+                               'SubjectArea' => [ Exif::SHORT, 4 ], # Subject area
                                'FlashEnergy' => Exif::RATIONAL, # Flash energy
                                'SpatialFrequencyResponse' => Exif::IGNORE, # Spatial frequency response. Not supported atm.
                                'FocalPlaneXResolution' => Exif::RATIONAL, # Focal plane X resolution
                                'FocalPlaneYResolution' => Exif::RATIONAL, # Focal plane Y resolution
                                'FocalPlaneResolutionUnit' => Exif::SHORT, # Focal plane resolution unit #p46
-                               'SubjectLocation' => array( Exif::SHORT, 2 ), # Subject location
+                               'SubjectLocation' => [ Exif::SHORT, 2 ], # Subject location
                                'ExposureIndex' => Exif::RATIONAL, # Exposure index
                                'SensingMethod' => Exif::SHORT, # Sensing method #p46
                                'FileSource' => Exif::UNDEFINED, # File source #p47
@@ -237,22 +237,22 @@ class Exif {
                                'SubjectDistanceRange' => Exif::SHORT, # Subject distance range #p51
 
                                'ImageUniqueID' => Exif::ASCII, # Unique image ID
-                       ),
+                       ],
 
                        # GPS Attribute Information (p52)
-                       'GPS' => array(
+                       'GPS' => [
                                'GPSVersion' => Exif::UNDEFINED,
                                # Should be an array of 4 Exif::BYTE's. However php treats it as an undefined
                                # Note exif standard calls this GPSVersionID, but php doesn't like the id suffix
                                'GPSLatitudeRef' => Exif::ASCII, # North or South Latitude #p52-53
-                               'GPSLatitude' => array( Exif::RATIONAL, 3 ), # Latitude
+                               'GPSLatitude' => [ Exif::RATIONAL, 3 ], # Latitude
                                'GPSLongitudeRef' => Exif::ASCII, # East or West Longitude #p53
-                               'GPSLongitude' => array( Exif::RATIONAL, 3 ), # Longitude
+                               'GPSLongitude' => [ Exif::RATIONAL, 3 ], # Longitude
                                'GPSAltitudeRef' => Exif::UNDEFINED,
                                # Altitude reference. Note, the exif standard says this should be an EXIF::Byte,
                                # but php seems to disagree.
                                'GPSAltitude' => Exif::RATIONAL, # Altitude
-                               'GPSTimeStamp' => array( Exif::RATIONAL, 3 ), # GPS time (atomic clock)
+                               'GPSTimeStamp' => [ Exif::RATIONAL, 3 ], # GPS time (atomic clock)
                                'GPSSatellites' => Exif::ASCII, # Satellites used for measurement
                                'GPSStatus' => Exif::ASCII, # Receiver status #p54
                                'GPSMeasureMode' => Exif::ASCII, # Measurement mode #p54-55
@@ -265,9 +265,9 @@ class Exif {
                                'GPSImgDirection' => Exif::RATIONAL, # Direction of image
                                'GPSMapDatum' => Exif::ASCII, # Geodetic survey data used
                                'GPSDestLatitudeRef' => Exif::ASCII, # Reference for latitude of destination #p56
-                               'GPSDestLatitude' => array( Exif::RATIONAL, 3 ), # Latitude destination
+                               'GPSDestLatitude' => [ Exif::RATIONAL, 3 ], # Latitude destination
                                'GPSDestLongitudeRef' => Exif::ASCII, # Reference for longitude of destination #p57
-                               'GPSDestLongitude' => array( Exif::RATIONAL, 3 ), # Longitude of destination
+                               'GPSDestLongitude' => [ Exif::RATIONAL, 3 ], # Longitude of destination
                                'GPSDestBearingRef' => Exif::ASCII, # Reference for bearing of destination #p57
                                'GPSDestBearing' => Exif::RATIONAL, # Bearing of destination
                                'GPSDestDistanceRef' => Exif::ASCII, # Reference for distance to destination #p57-58
@@ -276,8 +276,8 @@ class Exif {
                                'GPSAreaInformation' => Exif::UNDEFINED, # Name of GPS area
                                'GPSDateStamp' => Exif::ASCII, # GPS date
                                'GPSDifferential' => Exif::SHORT, # GPS differential correction
-                       ),
-               );
+                       ],
+               ];
 
                $this->file = $file;
                $this->basename = wfBaseName( $this->file );
@@ -306,7 +306,7 @@ class Exif {
                 * when somebody uploads a file called something.jpeg
                 * containing random gibberish.
                 */
-               $this->mRawExifData = $data ?: array();
+               $this->mRawExifData = $data ?: [];
                $this->makeFilteredData();
                $this->collapseData();
                $this->debugFile( __FUNCTION__, false );
@@ -316,7 +316,7 @@ class Exif {
         * Make $this->mFilteredExifData
         */
        function makeFilteredData() {
-               $this->mFilteredExifData = array();
+               $this->mFilteredExifData = [];
 
                foreach ( array_keys( $this->mRawExifData ) as $section ) {
                        if ( !array_key_exists( $section, $this->mExifTags ) ) {
@@ -390,27 +390,27 @@ class Exif {
                $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.
+               // 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();
+                       $ccVals = [];
 
                        $strLen = strlen( $val );
                        for ( $i = 0; $i < $strLen; $i++ ) {
                                $ccVals[$i] = ord( substr( $val, $i, 1 ) );
                        }
-                       $ccVals['_type'] = 'ol'; //this is for formatting later.
+                       $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"
+               // 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"
 
-               //Also change exif tag name from GPSVersion (what php exif thinks it is)
-               //to GPSVersionID (what the exif standard thinks it is).
+               // Also change exif tag name from GPSVersion (what php exif thinks it is)
+               // to GPSVersionID (what the exif standard thinks it is).
 
                if ( isset( $this->mFilteredExifData['GPSVersion'] ) ) {
                        $val = $this->mFilteredExifData['GPSVersion'];
@@ -448,7 +448,7 @@ class Exif {
                if ( isset( $this->mFilteredExifData[$prop] ) ) {
 
                        if ( strlen( $this->mFilteredExifData[$prop] ) <= 8 ) {
-                               //invalid. Must be at least 9 bytes long.
+                               // invalid. Must be at least 9 bytes long.
 
                                $this->debug( $this->mFilteredExifData[$prop], __FUNCTION__, false );
                                unset( $this->mFilteredExifData[$prop] );
@@ -460,13 +460,13 @@ class Exif {
 
                        switch ( $charCode ) {
                                case "\x4A\x49\x53\x00\x00\x00\x00\x00":
-                                       //JIS
+                                       // JIS
                                        $charset = "Shift-JIS";
                                        break;
                                case "UNICODE\x00":
                                        $charset = "UTF-16" . $this->byteOrder;
                                        break;
-                               default: //ascii or undefined.
+                               default: // ascii or undefined.
                                        $charset = "";
                                        break;
                        }
@@ -477,7 +477,7 @@ class Exif {
                        } else {
                                // if valid utf-8, assume that, otherwise assume windows-1252
                                $valCopy = $val;
-                               UtfNormal\Validator::quickIsNFCVerify( $valCopy ); //validates $valCopy.
+                               UtfNormal\Validator::quickIsNFCVerify( $valCopy ); // validates $valCopy.
                                if ( $valCopy !== $val ) {
                                        MediaWiki\suppressWarnings();
                                        $val = iconv( 'Windows-1252', 'UTF-8//IGNORE', $val );
@@ -485,17 +485,17 @@ class Exif {
                                }
                        }
 
-                       //trim and check to make sure not only whitespace.
+                       // trim and check to make sure not only whitespace.
                        $val = trim( $val );
                        if ( strlen( $val ) === 0 ) {
-                               //only whitespace.
+                               // only whitespace.
                                $this->debug( $this->mFilteredExifData[$prop], __FUNCTION__, "$prop: Is only whitespace" );
                                unset( $this->mFilteredExifData[$prop] );
 
                                return;
                        }
 
-                       //all's good.
+                       // all's good.
                        $this->mFilteredExifData[$prop] = $val;
                }
        }
@@ -666,7 +666,7 @@ class Exif {
         * @return bool
         */
        private function isRational( $in ) {
-               $m = array();
+               $m = [];
 
                # Avoid division by zero
                if ( !is_array( $in )
@@ -711,7 +711,7 @@ class Exif {
         * @return bool
         */
        private function isSrational( $in ) {
-               $m = array();
+               $m = [];
 
                # Avoid division by zero
                if ( !is_array( $in ) &&