Followup r68325, with comment describing intent of code.
[lhc/web/wiklou.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 /* Preserve original image info string, but strip the last char ')' so we can add even more */
78 $info = array();
79 $info[] = substr( $original, 1, strlen( $original )-2 );
80
81 if ($metadata['looped'])
82 $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
83
84 if ($metadata['frameCount'] > 1)
85 $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
86
87 if ($metadata['duration'])
88 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
89
90 $infoString = $wgLang->commaList( $info );
91
92 return "($infoString)";
93 }
94 }