Bug 23733 - Add IDs to messages used on CSS/JS pages
[mediawiki.git] / includes / media / GIF.php
blob434762fa1ae139d3821107ffa439a9a0d6608f40
1 <?php
2 /**
3 * @file
4 * @ingroup Media
5 */
7 /**
8 * Handler for GIF images.
10 * @ingroup Media
12 class GIFHandler extends BitmapHandler {
14 function getMetadata( $image, $filename ) {
15 if ( !isset($image->parsedGIFMetadata) ) {
16 try {
17 $image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
18 } catch( Exception $e ) {
19 // Broken file?
20 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
21 return '0';
25 return serialize($image->parsedGIFMetadata);
29 function formatMetadata( $image ) {
30 return false;
33 function getImageArea( $image, $width, $height ) {
34 $ser = $image->getMetadata();
35 if ($ser) {
36 $metadata = unserialize($ser);
37 return $width * $height * $metadata['frameCount'];
38 } else {
39 return $width * $height;
43 function isAnimatedImage( $image ) {
44 $ser = $image->getMetadata();
45 if ($ser) {
46 $metadata = unserialize($ser);
47 if( $metadata['frameCount'] > 1 ) return true;
49 return false;
52 function getMetadataType( $image ) {
53 return 'parsed-gif';
56 function isMetadataValid( $image, $metadata ) {
57 $data = @unserialize( $metadata );
58 return (boolean) $data;
61 function getLongDesc( $image ) {
62 global $wgUser, $wgLang;
63 $sk = $wgUser->getSkin();
65 $metadata = @unserialize($image->getMetadata());
67 if (!$metadata) return parent::getLongDesc( $image );
69 $info = array();
70 $info[] = $image->getMimeType();
71 $info[] = $sk->formatSize( $image->getSize() );
73 if ($metadata['looped'])
74 $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
76 if ($metadata['frameCount'] > 1)
77 $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
79 if ($metadata['duration'])
80 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
82 $infoString = $wgLang->commaList( $info );
84 return "($infoString)";