Whitespace, braces, documentation
[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 function formatMetadata( $image ) {
31 return false;
32 }
33
34 /**
35 * @param $image File
36 * @param $width
37 * @param $height
38 * @return
39 */
40 function getImageArea( $image, $width, $height ) {
41 $ser = $image->getMetadata();
42 if ( $ser ) {
43 $metadata = unserialize( $ser );
44 return $width * $height * $metadata['frameCount'];
45 } else {
46 return $width * $height;
47 }
48 }
49
50 /**
51 * @param $image File
52 * @return bool
53 */
54 function isAnimatedImage( $image ) {
55 $ser = $image->getMetadata();
56 if ( $ser ) {
57 $metadata = unserialize($ser);
58 if( $metadata['frameCount'] > 1 ) {
59 return true;
60 }
61 }
62 return false;
63 }
64
65 function getMetadataType( $image ) {
66 return 'parsed-gif';
67 }
68
69 function isMetadataValid( $image, $metadata ) {
70 wfSuppressWarnings();
71 $data = unserialize( $metadata );
72 wfRestoreWarnings();
73 return (boolean) $data;
74 }
75
76 /**
77 * @param $image File
78 * @return string
79 */
80 function getLongDesc( $image ) {
81 global $wgLang;
82
83 $original = parent::getLongDesc( $image );
84
85 wfSuppressWarnings();
86 $metadata = unserialize($image->getMetadata());
87 wfRestoreWarnings();
88
89 if (!$metadata || $metadata['frameCount'] <= 1) {
90 return $original;
91 }
92
93 /* Preserve original image info string, but strip the last char ')' so we can add even more */
94 $info = array();
95 $info[] = $original;
96
97 if ( $metadata['looped'] ) {
98 $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
99 }
100
101 if ( $metadata['frameCount'] > 1 ) {
102 $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
103 }
104
105 if ( $metadata['duration'] ) {
106 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
107 }
108
109 return $wgLang->commaList( $info );
110 }
111 }