r78882 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78881‎ | r78882 | r78883 >
Date:11:20, 23 December 2010
Author:bawolff
Status:deferred
Tags:
Comment:
Stylistic changes only. No content changes.
Modified paths:
  • /branches/img_metadata/phase3/includes/media/PNGMetadataExtractor.php (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/includes/media/PNGMetadataExtractor.php
@@ -24,7 +24,7 @@
2525 static function getMetadata( $filename ) {
2626 self::$png_sig = pack( "C8", 137, 80, 78, 71, 13, 10, 26, 10 );
2727 self::$CRC_size = 4;
28 - /* based on list at http://owl.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html#TextualData
 28+ /* based on list at http://owl.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html#TextualData
2929 * and http://www.w3.org/TR/PNG/#11keywords
3030 */
3131 self::$text_chunks = array(
@@ -53,23 +53,24 @@
5454 );
5555
5656 $showXMP = function_exists( 'xml_parser_create_ns' );
57 -
 57+
5858 $frameCount = 0;
5959 $loopCount = 1;
6060 $duration = 0.0;
6161 $text = array();
6262
63 - if (!$filename)
 63+ if ( !$filename ) {
6464 throw new Exception( __METHOD__ . ": No file name specified" );
65 - elseif ( !file_exists($filename) || is_dir($filename) )
 65+ } elseif ( !file_exists( $filename ) || is_dir( $filename ) ) {
6666 throw new Exception( __METHOD__ . ": File $filename does not exist" );
67 -
 67+ }
 68+
6869 $fh = fopen( $filename, 'r' );
69 -
70 - if (!$fh) {
 70+
 71+ if ( !$fh ) {
7172 throw new Exception( __METHOD__ . ": Unable to open file $filename" );
7273 }
73 -
 74+
7475 // Check for the PNG header
7576 $buf = fread( $fh, 8 );
7677 if ( $buf != self::$png_sig ) {
@@ -77,22 +78,22 @@
7879 }
7980
8081 // Read chunks
81 - while( !feof( $fh ) ) {
 82+ while ( !feof( $fh ) ) {
8283 $buf = fread( $fh, 4 );
83 - if( !$buf ) {
 84+ if ( !$buf ) {
8485 throw new Exception( __METHOD__ . ": Read error" );
8586 }
86 - $chunk_size = unpack( "N", $buf);
 87+ $chunk_size = unpack( "N", $buf );
8788 $chunk_size = $chunk_size[1];
8889
8990 $chunk_type = fread( $fh, 4 );
90 - if( !$chunk_type ) {
 91+ if ( !$chunk_type ) {
9192 throw new Exception( __METHOD__ . ": Read error" );
9293 }
9394
9495 if ( $chunk_type == "acTL" ) {
9596 $buf = fread( $fh, $chunk_size );
96 - if( !$buf ) {
 97+ if ( !$buf ) {
9798 throw new Exception( __METHOD__ . ": Read error" );
9899 }
99100
@@ -101,21 +102,23 @@
102103 $loopCount = $actl['plays'];
103104 } elseif ( $chunk_type == "fcTL" ) {
104105 $buf = fread( $fh, $chunk_size );
105 - if( !$buf ) {
 106+ if ( !$buf ) {
106107 throw new Exception( __METHOD__ . ": Read error" );
107108 }
108 - $buf = substr( $buf, 20 );
 109+ $buf = substr( $buf, 20 );
109110
110111 $fctldur = unpack( "ndelay_num/ndelay_den", $buf );
111 - if( $fctldur['delay_den'] == 0 ) $fctldur['delay_den'] = 100;
112 - if( $fctldur['delay_num'] ) {
 112+ if ( $fctldur['delay_den'] == 0 ) {
 113+ $fctldur['delay_den'] = 100;
 114+ }
 115+ if ( $fctldur['delay_num'] ) {
113116 $duration += $fctldur['delay_num'] / $fctldur['delay_den'];
114117 }
115118 } elseif ( $chunk_type == "iTXt" ) {
116119 // Extracts iTXt chunks, uncompressing if necessary.
117120 $buf = fread( $fh, $chunk_size );
118121 $items = array();
119 - if ( preg_match(
 122+ if ( preg_match(
120123 '/^([^\x00]{1,79})\x00(\x00|\x01)\x00([^\x00]*)(.)[^\x00]*\x00(.*)$/Ds',
121124 $buf, $items )
122125 ) {
@@ -137,7 +140,7 @@
138141 // if no lang specified use x-default like in xmp.
139142 $items[3] = 'x-default';
140143 }
141 -
 144+
142145 // if compressed
143146 if ( $items[2] == "\x01" ) {
144147 if ( function_exists( 'gzuncompress' ) && $items[4] === "\x00" ) {
@@ -146,7 +149,7 @@
147150 wfRestoreWarnings();
148151
149152 if ( $items[5] === false ) {
150 - //decompression failed
 153+ // decompression failed
151154 wfDebug( __METHOD__ . ' Error decompressing iTxt chunk - ' . $items[1] );
152155 fseek( $fh, self::$CRC_size, SEEK_CUR );
153156 continue;
@@ -164,9 +167,8 @@
165168 $text[ $finalKeyword ]['_type'] = 'lang';
166169
167170 } else {
168 - //Error reading iTXt chunk
 171+ // Error reading iTXt chunk
169172 throw new Exception( __METHOD__ . ": Read error on iTXt chunk" );
170 - return;
171173 }
172174
173175 } elseif ( $chunk_type == 'tEXt' ) {
@@ -177,7 +179,6 @@
178180 list( $keyword, $content ) = explode( "\x00", $buf, 2 );
179181 if ( $keyword === '' || $content === '' ) {
180182 throw new Exception( __METHOD__ . ": Read error on tEXt chunk" );
181 - return;
182183 }
183184
184185 // Theoretically should be case-sensitive, but in practise...
@@ -188,12 +189,11 @@
189190 continue;
190191 }
191192 wfSuppressWarnings();
192 - $content = iconv( 'ISO-8859-1', 'UTF-8', $content);
 193+ $content = iconv( 'ISO-8859-1', 'UTF-8', $content );
193194 wfRestoreWarnings();
194195
195196 if ( $content === false ) {
196197 throw new Exception( __METHOD__ . ": Read error (error with iconv)" );
197 - return;
198198 }
199199
200200 $finalKeyword = self::$text_chunks[ $keyword ];
@@ -209,7 +209,6 @@
210210 list( $keyword, $postKeyword ) = explode( "\x00", $buf, 2 );
211211 if ( $keyword === '' || $postKeyword === '' ) {
212212 throw new Exception( __METHOD__ . ": Read error on zTXt chunk" );
213 - return;
214213 }
215214 // Theoretically should be case-sensitive, but in practise...
216215 $keyword = strtolower( $keyword );
@@ -232,19 +231,18 @@
233232 wfRestoreWarnings();
234233
235234 if ( $content === false ) {
236 - //decompression failed
 235+ // decompression failed
237236 wfDebug( __METHOD__ . ' Error decompressing zTXt chunk - ' . $keyword );
238237 fseek( $fh, self::$CRC_size, SEEK_CUR );
239238 continue;
240239 }
241240
242241 wfSuppressWarnings();
243 - $content = iconv( 'ISO-8859-1', 'UTF-8', $content);
 242+ $content = iconv( 'ISO-8859-1', 'UTF-8', $content );
244243 wfRestoreWarnings();
245244
246245 if ( $content === false ) {
247246 throw new Exception( __METHOD__ . ": Read error (error with iconv)" );
248 - return;
249247 }
250248
251249 $finalKeyword = self::$text_chunks[ $keyword ];
@@ -257,9 +255,13 @@
258256 }
259257 } elseif ( $chunk_type == 'tIME' ) {
260258 // last mod timestamp.
261 - if( $chunk_size !== 7 ) { throw new Exception( __METHOD__ . ": tIME wrong size" ); return; }
 259+ if ( $chunk_size !== 7 ) {
 260+ throw new Exception( __METHOD__ . ": tIME wrong size" );
 261+ }
262262 $buf = fread( $fh, $chunk_size );
263 - if( !$buf ) { throw new Exception( __METHOD__ . ": Read error" ); return; }
 263+ if ( !$buf ) {
 264+ throw new Exception( __METHOD__ . ": Read error" );
 265+ }
264266
265267 // Note: spec says this should be UTC.
266268 $t = unpack( "ny/Cm/Cd/Ch/Cmin/Cs", $buf );
@@ -275,9 +277,14 @@
276278
277279 } elseif ( $chunk_type == 'pHYs' ) {
278280 // how big pixels are (dots per meter).
279 - if( $chunk_size !== 9 ) { throw new Exception( __METHOD__ . ": pHYs wrong size" ); return; }
 281+ if ( $chunk_size !== 9 ) {
 282+ throw new Exception( __METHOD__ . ": pHYs wrong size" );
 283+ }
 284+
280285 $buf = fread( $fh, $chunk_size );
281 - if( !$buf ) { throw new Exception( __METHOD__ . ": Read error" ); return; }
 286+ if ( !$buf ) {
 287+ throw new Exception( __METHOD__ . ": Read error" );
 288+ }
282289
283290 $dim = unpack( "Nwidth/Nheight/Cunit", $buf );
284291 if ( $dim['unit'] == 1 ) {
@@ -300,7 +307,7 @@
301308 }
302309 fclose( $fh );
303310
304 - if( $loopCount > 1 ) {
 311+ if ( $loopCount > 1 ) {
305312 $duration *= $loopCount;
306313 }
307314
@@ -336,6 +343,6 @@
337344 'duration' => $duration,
338345 'text' => $text,
339346 );
340 -
 347+
341348 }
342349 }

Status & tagging log