From: Sam Reed Date: Mon, 11 Apr 2011 20:43:04 +0000 (+0000) Subject: Spaces, braces and trailing whitespace X-Git-Tag: 1.31.0-rc.0~30925 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=9dcdeee0dcc9026816e9bf802f2a534bb0d98748;p=lhc%2Fweb%2Fwiklou.git Spaces, braces and trailing whitespace --- diff --git a/includes/media/GIF.php b/includes/media/GIF.php index 3adb7c456c..f8fe47589b 100644 --- a/includes/media/GIF.php +++ b/includes/media/GIF.php @@ -12,7 +12,7 @@ * @ingroup Media */ class GIFHandler extends BitmapHandler { - + function getMetadata( $image, $filename ) { if ( !isset( $image->parsedGIFMetadata ) ) { try { @@ -25,9 +25,8 @@ class GIFHandler extends BitmapHandler { } return serialize( $image->parsedGIFMetadata ); - } - + function formatMetadata( $image ) { return false; } @@ -56,15 +55,17 @@ class GIFHandler extends BitmapHandler { $ser = $image->getMetadata(); if ($ser) { $metadata = unserialize($ser); - if( $metadata['frameCount'] > 1 ) return true; + if( $metadata['frameCount'] > 1 ) { + return true; + } } return false; } - + function getMetadataType( $image ) { return 'parsed-gif'; } - + function isMetadataValid( $image, $metadata ) { wfSuppressWarnings(); $data = unserialize( $metadata ); @@ -85,21 +86,25 @@ class GIFHandler extends BitmapHandler { $metadata = unserialize($image->getMetadata()); wfRestoreWarnings(); - if (!$metadata || $metadata['frameCount'] <= 1) + if (!$metadata || $metadata['frameCount'] <= 1) { return $original; + } /* Preserve original image info string, but strip the last char ')' so we can add even more */ $info = array(); $info[] = $original; - if ($metadata['looped']) + if ( $metadata['looped'] ) { $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' ); + } - if ($metadata['frameCount'] > 1) + if ( $metadata['frameCount'] > 1 ) { $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] ); + } - if ($metadata['duration']) + if ( $metadata['duration'] ) { $info[] = $wgLang->formatTimePeriod( $metadata['duration'] ); + } return $wgLang->commaList( $info ); } diff --git a/includes/media/GIFMetadataExtractor.php b/includes/media/GIFMetadataExtractor.php index bc1a4804aa..8d0e87e383 100644 --- a/includes/media/GIFMetadataExtractor.php +++ b/includes/media/GIFMetadataExtractor.php @@ -25,54 +25,56 @@ class GIFMetadataExtractor { self::$gif_frame_sep = pack( "C", ord("," ) ); self::$gif_extension_sep = pack( "C", ord("!" ) ); self::$gif_term = pack( "C", ord(";" ) ); - + $frameCount = 0; $duration = 0.0; $isLooped = false; - - if (!$filename) + + if ( !$filename ) { throw new Exception( "No file name specified" ); - elseif ( !file_exists($filename) || is_dir($filename) ) + } elseif ( !file_exists( $filename ) || is_dir( $filename ) ) { throw new Exception( "File $filename does not exist" ); - + } + $fh = fopen( $filename, 'r' ); - - if (!$fh) + + if ( !$fh ) { throw new Exception( "Unable to open file $filename" ); - + } + // Check for the GIF header $buf = fread( $fh, 6 ); if ( !($buf == 'GIF87a' || $buf == 'GIF89a') ) { throw new Exception( "Not a valid GIF file; header: $buf" ); } - + // Skip over width and height. fread( $fh, 4 ); - + // Read BPP $buf = fread( $fh, 1 ); $bpp = self::decodeBPP( $buf ); - + // Skip over background and aspect ratio fread( $fh, 2 ); - + // Skip over the GCT self::readGCT( $fh, $bpp ); - + while( !feof( $fh ) ) { $buf = fread( $fh, 1 ); - + if ($buf == self::$gif_frame_sep) { // Found a frame $frameCount++; - + ## Skip bounding box fread( $fh, 8 ); - + ## Read BPP $buf = fread( $fh, 1 ); $bpp = self::decodeBPP( $buf ); - + ## Read GCT self::readGCT( $fh, $bpp ); fread( $fh, 1 ); @@ -81,54 +83,55 @@ class GIFMetadataExtractor { $buf = fread( $fh, 1 ); $extension_code = unpack( 'C', $buf ); $extension_code = $extension_code[1]; - + if ($extension_code == 0xF9) { // Graphics Control Extension. fread( $fh, 1 ); // Block size - + fread( $fh, 1 ); // Transparency, disposal method, user input - + $buf = fread( $fh, 2 ); // Delay, in hundredths of seconds. $delay = unpack( 'v', $buf ); $delay = $delay[1]; $duration += $delay * 0.01; - + fread( $fh, 1 ); // Transparent colour index - + $term = fread( $fh, 1 ); // Should be a terminator $term = unpack( 'C', $term ); $term = $term[1]; - if ($term != 0 ) + if ($term != 0 ) { throw new Exception( "Malformed Graphics Control Extension block" ); + } } elseif ($extension_code == 0xFF) { // Application extension (Netscape info about the animated gif) $blockLength = fread( $fh, 1 ); $blockLength = unpack( 'C', $blockLength ); $blockLength = $blockLength[1]; $data = fread( $fh, $blockLength ); - + // NETSCAPE2.0 (application name) if ($blockLength != 11 || $data != 'NETSCAPE2.0') { fseek( $fh, -($blockLength + 1), SEEK_CUR ); self::skipBlock( $fh ); continue; } - + $data = fread( $fh, 2 ); // Block length and introduction, should be 03 01 - + if ($data != "\x03\x01") { throw new Exception( "Expected \x03\x01, got $data" ); } - + // Unsigned little-endian integer, loop count or zero for "forever" $loopData = fread( $fh, 2 ); $loopData = unpack( 'v', $loopData ); $loopCount = $loopData[1]; - + if ($loopCount != 1) { $isLooped = true; } - + // Read out terminator byte fread( $fh, 1 ); } else { @@ -142,43 +145,42 @@ class GIFMetadataExtractor { throw new Exception( "At position: ".ftell($fh). ", Unknown byte ".$byte ); } } - + return array( 'frameCount' => $frameCount, 'looped' => $isLooped, 'duration' => $duration ); - } - + static function readGCT( $fh, $bpp ) { - if ($bpp > 0) { - for( $i=1; $i<=pow(2,$bpp); ++$i ) { + if ( $bpp > 0 ) { + for( $i=1; $i<=pow( 2, $bpp ); ++$i ) { fread( $fh, 3 ); } } } - + static function decodeBPP( $data ) { $buf = unpack( 'C', $data ); $buf = $buf[1]; $bpp = ( $buf & 7 ) + 1; $buf >>= 7; - + $have_map = $buf & 1; - + return $have_map ? $bpp : 0; } - + static function skipBlock( $fh ) { while ( !feof( $fh ) ) { $buf = fread( $fh, 1 ); $block_len = unpack( 'C', $buf ); $block_len = $block_len[1]; - if ($block_len == 0) + if ($block_len == 0) { return; + } fread( $fh, $block_len ); } } - }