]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/media/GIF.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / media / GIF.php
1 <?php
2 /**
3  * Handler for GIF images.
4  *
5  * @file
6  * @ingroup Media
7  */
8
9 /**
10  * Handler for GIF images.
11  *
12  * @ingroup Media
13  */
14 class GIFHandler extends BitmapHandler {
15         
16         function getMetadata( $image, $filename ) {
17                 if ( !isset( $image->parsedGIFMetadata ) ) {
18                         try {
19                                 $image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
20                         } catch( Exception $e ) {
21                                 // Broken file?
22                                 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
23                                 return '0';
24                         }
25                 }
26
27                 return serialize( $image->parsedGIFMetadata );
28
29         }
30         
31         function formatMetadata( $image ) {
32                 return false;
33         }
34         
35         function getImageArea( $image, $width, $height ) {
36                 $ser = $image->getMetadata();
37                 if ($ser) {
38                         $metadata = unserialize($ser);
39                         return $width * $height * $metadata['frameCount'];
40                 } else {
41                         return $width * $height;
42                 }
43         }
44
45         function isAnimatedImage( $image ) {
46                 $ser = $image->getMetadata();
47                 if ($ser) {
48                         $metadata = unserialize($ser);
49                         if( $metadata['frameCount'] > 1 ) return true;
50                 }
51                 return false;
52         }
53         
54         function getMetadataType( $image ) {
55                 return 'parsed-gif';
56         }
57         
58         function isMetadataValid( $image, $metadata ) {
59                 wfSuppressWarnings();
60                 $data = unserialize( $metadata );
61                 wfRestoreWarnings();
62                 return (boolean) $data;
63         }
64
65         function getLongDesc( $image ) {
66                 global $wgLang;
67
68                 $original = parent::getLongDesc( $image );
69
70                 wfSuppressWarnings();
71                 $metadata = unserialize($image->getMetadata());
72                 wfRestoreWarnings();
73                 
74                 if (!$metadata || $metadata['frameCount'] <=  1)
75                         return $original;
76                 
77                 $info = array();
78                 $info[] = $original;
79                 
80                 if ($metadata['looped'])
81                         $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
82                 
83                 if ($metadata['frameCount'] > 1)
84                         $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
85                 
86                 if ($metadata['duration'])
87                         $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
88                 
89                 return $wgLang->commaList( $info );
90         }
91 }