Few style/whitespace/comment issues from r86169
authorSam Reed <reedy@users.mediawiki.org>
Mon, 18 Apr 2011 13:08:20 +0000 (13:08 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Mon, 18 Apr 2011 13:08:20 +0000 (13:08 +0000)
includes/filerepo/File.php
includes/media/BitmapMetadataHandler.php
includes/media/Exif.php
includes/media/FormatMetadata.php
includes/media/IPTC.php
includes/media/Jpeg.php
includes/media/JpegMetadataExtractor.php
includes/media/PNG.php
includes/media/XMP.php
includes/media/XMPValidate.php

index 0e1ac94..c3d90ca 100644 (file)
@@ -312,12 +312,12 @@ abstract class File {
        */
        public function convertMetadataVersion($metadata, $version) {
                $handler = $this->getHandler();
-               if (!is_array($metadata)) {
+               if ( !is_array( $metadata ) ) {
                        //just to make the return type consistant
                        $metadata = unserialize( $metadata ); 
                }
                if ( $handler ) {
-                       return $handler->convertMetadataVersion($metadata, $version);
+                       return $handler->convertMetadataVersion( $metadata, $version );
                } else {
                        return $metadata;
                }
index e618762..ce71a58 100644 (file)
@@ -10,16 +10,16 @@ and the various metadata extractors.
 */
 class BitmapMetadataHandler {
 
-       private $metadata = Array();
-       private $metaPriority = Array(
-               20 => Array( 'other' ),
-               40 => Array( 'native' ),
-               60 => Array( 'iptc-good-hash', 'iptc-no-hash' ),
-               70 => Array( 'xmp-deprecated' ),
-               80 => Array( 'xmp-general' ),
-               90 => Array( 'xmp-exif' ),
-               100 => Array( 'iptc-bad-hash' ),
-               120 => Array( 'exif' ),
+       private $metadata = array();
+       private $metaPriority = array(
+               20 => array( 'other' ),
+               40 => array( 'native' ),
+               60 => array( 'iptc-good-hash', 'iptc-no-hash' ),
+               70 => array( 'xmp-deprecated' ),
+               80 => array( 'xmp-general' ),
+               90 => array( 'xmp-exif' ),
+               100 => array( 'iptc-bad-hash' ),
+               120 => array( 'exif' ),
        );
        private $iptcType = 'iptc-no-hash';
 
index adaec1d..d41b654 100644 (file)
@@ -584,6 +584,10 @@ class Exif {
                }
        }
 
+       /**
+        * @param $in
+        * @return bool
+        */
        private function isASCII( $in ) {
                if ( is_array( $in ) ) {
                        return false;
@@ -602,6 +606,10 @@ class Exif {
                return true;
        }
 
+       /**
+        * @param $in
+        * @return bool
+        */
        private function isShort( $in ) {
                if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
                        $this->debug( $in, __FUNCTION__, true );
@@ -612,6 +620,10 @@ class Exif {
                }
        }
 
+       /**
+        * @param $in
+        * @return bool
+        */
        private function isLong( $in ) {
                if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
                        $this->debug( $in, __FUNCTION__, true );
@@ -622,6 +634,10 @@ class Exif {
                }
        }
 
+       /**
+        * @param $in
+        * @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
@@ -632,24 +648,19 @@ class Exif {
                }
        }
 
+       /**
+        * @param $in
+        * @return bool
+        */
        private function isUndefined( $in ) {
-
                $this->debug( $in, __FUNCTION__, true );
                return true;
-
-               /* Exif::UNDEFINED means string of bytes
-               so this validation does not make sense.
-               comment out for now.
-               if ( !is_array( $in ) && preg_match( '/^\d{4}$/', $in ) ) { // Allow ExifVersion and FlashpixVersion
-                       $this->debug( $in, __FUNCTION__, true );
-                       return true;
-               } else {
-                       $this->debug( $in, __FUNCTION__, false );
-                       return false;
-               }
-               */
        }
 
+       /**
+        * @param $in
+        * @return bool
+        */
        private function isSlong( $in ) {
                if ( $this->isLong( abs( $in ) ) ) {
                        $this->debug( $in, __FUNCTION__, true );
@@ -660,6 +671,10 @@ class Exif {
                }
        }
 
+       /**
+        * @param $in
+        * @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
@@ -756,17 +771,19 @@ class Exif {
                }
                $type = gettype( $in );
                $class = ucfirst( __CLASS__ );
-               if ( $type === 'array' )
+               if ( $type === 'array' ) {
                        $in = print_r( $in, true );
+               }
 
-               if ( $action === true )
+               if ( $action === true ) {
                        wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n");
-               elseif ( $action === false )
+               } elseif ( $action === false ) {
                        wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n");
-               elseif ( $action === null )
+               } elseif ( $action === null ) {
                        wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)\n");
-               else
+               } else {
                        wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n");
+               }
        }
 
        /**
index e5d0d7a..f6abb70 100644 (file)
@@ -567,8 +567,6 @@ class FormatMetadata {
                                        }
                                        break;
 
-       
-
                                // This is not in the Exif standard, just a special
                                // case for our purposes which enables wikis to wikify
                                // the make, model and software name to link to their articles.
@@ -1171,8 +1169,6 @@ class FormatMetadata {
         * Format a coordinate value, convert numbers from floating point
         * into degree minute second representation.
         *
-        * @private
-        *
         * @param $coords Array: degrees, minutes and seconds
         * @param $type String: latitude or longitude (for if its a NWS or E)
         * @return mixed A floating point number or whatever we were fed
@@ -1345,8 +1341,8 @@ class FormatExif {
                wfDeprecated(__METHOD__);
                $this->meta = $meta;
        }
+
        function getFormattedData ( ) {
                return FormatMetadata::getFormattedData( $this->meta );
        }
-
 }
index 83aaf3e..dcc21e7 100644 (file)
@@ -157,8 +157,6 @@ class IPTC {
                                        } else {
                                                $data['Software'] = $software;
                                        }
-
-
                                        break;
                                case '2#075':
                                        /* Object cycle.
@@ -430,8 +428,11 @@ class IPTC {
                        // most of the time if there is no 1:90 tag, it is either ascii, latin1, or utf-8
                        $oldData = $data;
                        UtfNormal::quickIsNFCVerify( $data ); //make $data valid utf-8
-                       if ($data === $oldData) return $data; //if validation didn't change $data
-                       else return self::convIPTCHelper ( $oldData, 'Windows-1252' );
+                       if ($data === $oldData) {
+                               return $data; //if validation didn't change $data
+                       } else {
+                               return self::convIPTCHelper ( $oldData, 'Windows-1252' );
+                       }
                }
                return trim( $data );
        }
index c8a1043..4d0d826 100644 (file)
@@ -135,6 +135,4 @@ class JpegHandler extends BitmapHandler {
                }
                return $this->formatMetadataHelper( $exif );
        }
-
-
 }
index a556aa9..d95dbaf 100644 (file)
@@ -6,6 +6,7 @@
 * Based somewhat on GIFMetadataExtrator.
 */
 class JpegMetadataExtractor {
+
        const MAX_JPEG_SEGMENTS = 200;
        // the max segment is a sanity check.
        // A jpeg file should never even remotely have
@@ -27,17 +28,25 @@ class JpegMetadataExtractor {
 
                $segmentCount = 0;
 
-               $segments = Array( 'XMP_ext' => array(), 'COM' => array() );
+               $segments = array( 'XMP_ext' => array(), 'COM' => array() );
 
-               if ( !$filename ) throw new MWException( "No filename specified for " . __METHOD__ );
-               if ( !file_exists( $filename ) || is_dir( $filename ) ) throw new MWException( "Invalid file $filename passed to " . __METHOD__ );
+               if ( !$filename ) {
+                       throw new MWException( "No filename specified for " . __METHOD__ );
+               }
+               if ( !file_exists( $filename ) || is_dir( $filename ) ) {
+                       throw new MWException( "Invalid file $filename passed to " . __METHOD__ );
+               }
 
                $fh = fopen( $filename, "rb" );
 
-               if ( !$fh ) throw new MWException( "Could not open file $filename" );
+               if ( !$fh ) {
+                       throw new MWException( "Could not open file $filename" );
+               }
 
                $buffer = fread( $fh, 2 );
-               if ( $buffer !== "\xFF\xD8" ) throw new MWException( "Not a jpeg, no SOI" );
+               if ( $buffer !== "\xFF\xD8" ) {
+                       throw new MWException( "Not a jpeg, no SOI" );
+               }
                while ( !feof( $fh ) ) {
                        $buffer = fread( $fh, 1 );
                        $segmentCount++;
@@ -136,7 +145,9 @@ class JpegMetadataExtractor {
        * @return String if the iptc hash is good or not.
        */
        public static function doPSIR ( $app13 ) {
-               if ( !$app13 ) return;
+               if ( !$app13 ) {
+                       return;
+               }
                // First compare hash with real thing
                // 0x404 contains IPTC, 0x425 has hash
                // This is used to determine if the iptc is newer than
@@ -171,7 +182,9 @@ class JpegMetadataExtractor {
 
                        $lenName = ord( substr( $app13, $offset, 1 ) ) + 1;
                        // we never use the name so skip it. +1 for length byte
-                       if ( $lenName % 2 == 1 ) $lenName++; // pad to even.
+                       if ( $lenName % 2 == 1 ) {
+                               $lenName++;
+                       } // pad to even.
                        $offset += $lenName;
 
                        // now length of data (unsigned long big endian)
index 3206d96..f688b4c 100644 (file)
@@ -109,16 +109,19 @@ class PNGHandler extends BitmapHandler {
                $info = array();
                $info[] = $original;
                
-               if ($metadata['loopCount'] == 0)
+               if ( $metadata['loopCount'] == 0 ) {
                        $info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' );
-               elseif ($metadata['loopCount'] > 1)
+               } elseif ( $metadata['loopCount'] > 1 ) {
                        $info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] );
+               }
                
-               if ($metadata['frameCount'] > 0)
+               if ( $metadata['frameCount'] > 0 ) {
                        $info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] );
+               }
                
-               if ($metadata['duration'])
+               if ( $metadata['duration'] ) {
                        $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
+               }
                
                return $wgLang->commaList( $info );
        }
index 1b00119..fd95f3c 100644 (file)
@@ -296,10 +296,9 @@ class XMPReader {
                // or programs that make such files..
                $guid = substr( $content, 0, 32 );
                if ( !isset( $this->results['xmp-special']['HasExtendedXMP'] )
-                       || $this->results['xmp-special']['HasExtendedXMP'] !== $guid )
-               {
+                       || $this->results['xmp-special']['HasExtendedXMP'] !== $guid ) {
                        wfDebugLog('XMP', __METHOD__ . " Ignoring XMPExtended block due to wrong guid (guid= '$guid' )");
-                       return;
+                       return false;
                }
                $len  = unpack( 'Nlength/Noffset', substr( $content, 32, 8 ) );
 
@@ -646,7 +645,6 @@ class XMPReader {
                }
        }
 
-
        /**
        * Hit an opening element while in MODE_IGNORE
        *
@@ -664,6 +662,7 @@ class XMPReader {
                        array_unshift( $this->mode, self::MODE_IGNORE );
                }
        }
+
        /**
        *  Start element in MODE_BAG (unordered array)
        * this should always be <rdf:Bag>
@@ -679,6 +678,7 @@ class XMPReader {
                }
 
        }
+
        /**
        * Start element in MODE_SEQ (ordered array)
        * this should always be <rdf:Seq>
@@ -699,6 +699,7 @@ class XMPReader {
                }
 
        }
+
        /**
        * Start element in MODE_LANG (language alternative)
        * this should always be <rdf:Alt>
@@ -721,6 +722,7 @@ class XMPReader {
                }
 
        }
+
        /**
        * Handle an opening element when in MODE_SIMPLE
        *
@@ -761,6 +763,7 @@ class XMPReader {
                }
 
        }
+
        /**
        * Start an element when in MODE_QDESC.
        * This generally happens when a simple element has an inner
@@ -784,6 +787,7 @@ class XMPReader {
                        array_unshift( $this->curItem, $elm );
                }
        }
+
        /**
        * Starting an element when in MODE_INITIAL
        * This usually happens when we hit an element inside
@@ -836,6 +840,7 @@ class XMPReader {
                // process attributes
                $this->doAttribs( $attribs );
        }
+
        /**
        * Hit an opening element when in a Struct (MODE_STRUCT)
        * This is generally for fields of a compound property.
@@ -887,6 +892,7 @@ class XMPReader {
                        array_unshift( $this->curItem, $this->curItem[0] );
                }
        }
+
        /**
        * opening element in MODE_LI
        * process elements of arrays.
@@ -937,6 +943,7 @@ class XMPReader {
                }
 
        }
+
        /**
        * Opening element in MODE_LI_LANG.
        * process elements of language alternatives
@@ -1055,9 +1062,6 @@ class XMPReader {
                                throw new MWException( 'StartElement in unknown mode: ' . $this->mode[0] );
                                break;
                }
-
-
-
        }
        /**
        * Process attributes.
@@ -1162,6 +1166,4 @@ class XMPReader {
                        $this->results['xmp-' . $info['map_group']][$finalName] = $val;
                }
        }
-
-
 }
index 382a514..0f1d375 100644 (file)
@@ -37,6 +37,7 @@ class XMPValidate {
                }
 
        }
+
        /**
        * function to validate rational properties ( 12/10 )
        *
@@ -55,6 +56,7 @@ class XMPValidate {
                }
 
        }
+
        /**
        * function to validate rating properties -1, 0-5
        *
@@ -93,6 +95,7 @@ class XMPValidate {
                        }
                }
        }
+
        /**
        * function to validate integers
        *
@@ -111,6 +114,7 @@ class XMPValidate {
                }
 
        }
+
        /**
        * function to validate properties with a fixed number of allowed
        * choices. (closed choice)
@@ -141,6 +145,7 @@ class XMPValidate {
                        $val = null;
                }
        }
+
        /**
        * function to validate and modify flash structure
        *
@@ -169,6 +174,7 @@ class XMPValidate {
                                | ( ( $val['RedEyeMode'] === 'True' ) << 6 ) );
                }
        }
+
        /**
        * function to validate LangCode properties ( en-GB, etc )
        *
@@ -193,6 +199,7 @@ class XMPValidate {
                }
 
        }
+
        /**
        * function to validate date properties, and convert to Exif format.
        *
@@ -263,6 +270,7 @@ class XMPValidate {
                }
 
        }
+
        /** function to validate, and more importantly
         * translate the XMP DMS form of gps coords to
         * the decimal form we use.
@@ -311,7 +319,5 @@ class XMPValidate {
                        $val = null;
                        return;
                }
-
        }
-
 }