* (bug 26484) add a lltitles param to prop=langlinks
[lhc/web/wiklou.git] / includes / media / PNGMetadataExtractor.php
index 2e87ff3..6a931e6 100644 (file)
@@ -1,11 +1,19 @@
 <?php
 /**
-  * PNG frame counter.
-  * Based on 
-  * Deliberately not using MWExceptions to avoid external dependencies, encouraging
-  * redistribution.
-  */
+ * PNG frame counter.
+ * Slightly derived from GIFMetadataExtractor.php
+ * Deliberately not using MWExceptions to avoid external dependencies, encouraging
+ * redistribution.
+ *
+ * @file
+ * @ingroup Media
+ */
 
+/**
+ * PNG frame counter.
+ *
+ * @ingroup Media
+ */
 class PNGMetadataExtractor {
        static $png_sig;
        static $CRC_size;
@@ -19,41 +27,50 @@ class PNGMetadataExtractor {
                $duration = 0.0;
 
                if (!$filename)
-                       throw new Exception( __METHOD__ . "No file name specified" );
+                       throw new Exception( __METHOD__ . "No file name specified" );
                elseif ( !file_exists($filename) || is_dir($filename) )
-                       throw new Exception( __METHOD__ . "File $filename does not exist" );
+                       throw new Exception( __METHOD__ . "File $filename does not exist" );
                
                $fh = fopen( $filename, 'r' );
                
-               if (!$fh)
-                       throw new Exception( __METHOD__ . "Unable to open file $filename" );
+               if (!$fh) {
+                       throw new Exception( __METHOD__ . ": Unable to open file $filename" );
+               }
                
                // Check for the PNG header
                $buf = fread( $fh, 8 );
-               if ( !($buf == self::$png_sig) ) {
-                       throw new Exception( __METHOD__ . "Not a valid PNG file; header: $buf" );
+               if ( $buf != self::$png_sig ) {
+                       throw new Exception( __METHOD__ . "Not a valid PNG file; header: $buf" );
                }
 
                // Read chunks
                while( !feof( $fh ) ) {
                        $buf = fread( $fh, 4 );
-                       if( !$buf ) { throw new Exception( __METHOD__ . "Read error" ); return; }
+                       if( !$buf ) {
+                               throw new Exception( __METHOD__ . ": Read error" );
+                       }
                        $chunk_size = unpack( "N", $buf);
                        $chunk_size = $chunk_size[1];
 
                        $chunk_type = fread( $fh, 4 );
-                       if( !$chunk_type ) { throw new Exception( __METHOD__ . "Read error" ); return; }
+                       if( !$chunk_type ) {
+                               throw new Exception( __METHOD__ . ": Read error" );
+                       }
 
                        if ( $chunk_type == "acTL" ) {
                                $buf = fread( $fh, $chunk_size );
-                               if( !$buf ) { throw new Exception( __METHOD__ . "Read error" ); return; }
+                               if( !$buf ) {
+                                       throw new Exception( __METHOD__ . ": Read error" );
+                               }
 
                                $actl = unpack( "Nframes/Nplays", $buf );
                                $frameCount = $actl['frames'];
                                $loopCount = $actl['plays'];
                        } elseif ( $chunk_type == "fcTL" ) {
                                $buf = fread( $fh, $chunk_size );
-                               if( !$buf ) { throw new Exception( __METHOD__ . "Read error" ); return; }
+                               if( !$buf ) {
+                                       throw new Exception( __METHOD__ . ": Read error" );
+                               }
                                $buf = substr( $buf, 20 );      
 
                                $fctldur = unpack( "ndelay_num/ndelay_den", $buf );