Minor tweaks to r74232, add a value for $botMax on calls for integer validation ...
[lhc/web/wiklou.git] / includes / media / GIF.php
index ef06aa7..b7c3f91 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 /**
+ * Handler for GIF images.
+ *
  * @file
  * @ingroup Media
  */
 class GIFHandler extends BitmapHandler {
        
        function getMetadata( $image, $filename ) {
-               if ( !isset($image->parsedGIFMetadata) )
-                       $image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
+               if ( !isset( $image->parsedGIFMetadata ) ) {
+                       try {
+                               $image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
+                       } catch( Exception $e ) {
+                               // Broken file?
+                               wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
+                               return '0';
+                       }
+               }
 
-               return serialize($image->parsedGIFMetadata);
+               return serialize( $image->parsedGIFMetadata );
 
        }
        
@@ -24,25 +33,49 @@ class GIFHandler extends BitmapHandler {
        }
        
        function getImageArea( $image, $width, $height ) {
-               $metadata = unserialize($image->getMetadata());
-               return $width * $height * $metadata['frameCount'];
+               $ser = $image->getMetadata();
+               if ($ser) {
+                       $metadata = unserialize($ser);
+                       return $width * $height * $metadata['frameCount'];
+               } else {
+                       return $width * $height;
+               }
+       }
+
+       function isAnimatedImage( $image ) {
+               $ser = $image->getMetadata();
+               if ($ser) {
+                       $metadata = unserialize($ser);
+                       if( $metadata['frameCount'] > 1 ) return true;
+               }
+               return false;
        }
        
        function getMetadataType( $image ) {
                return 'parsed-gif';
        }
        
+       function isMetadataValid( $image, $metadata ) {
+               wfSuppressWarnings();
+               $data = unserialize( $metadata );
+               wfRestoreWarnings();
+               return (boolean) $data;
+       }
+
        function getLongDesc( $image ) {
-               global $wgUser, $wgLang;
-               $sk = $wgUser->getSkin();
-               
-               $metadata = @unserialize($image->getMetadata());
+               global $wgLang;
+
+               $original = parent::getLongDesc( $image );
+
+               wfSuppressWarnings();
+               $metadata = unserialize($image->getMetadata());
+               wfRestoreWarnings();
                
-               if (!$metadata) return parent::getLongDesc( $image );
+               if (!$metadata || $metadata['frameCount'] <=  1)
+                       return $original;
                
                $info = array();
-               $info[] = $image->getMimeType();
-               $info[] = $sk->formatSize( $image->getSize() );
+               $info[] = substr( $original, 1, strlen( $original )-2 );
                
                if ($metadata['looped'])
                        $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );