* Reduced some pointless regex capture overhead
[mediawiki.git] / includes / media / GIF.php
blobb7c3f919ef66e020c8f9c9b6e5ca7bcc6048ee7e
1 <?php
2 /**
3 * Handler for GIF images.
5 * @file
6 * @ingroup Media
7 */
9 /**
10 * Handler for GIF images.
12 * @ingroup Media
14 class GIFHandler extends BitmapHandler {
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';
27 return serialize( $image->parsedGIFMetadata );
31 function formatMetadata( $image ) {
32 return false;
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;
45 function isAnimatedImage( $image ) {
46 $ser = $image->getMetadata();
47 if ($ser) {
48 $metadata = unserialize($ser);
49 if( $metadata['frameCount'] > 1 ) return true;
51 return false;
54 function getMetadataType( $image ) {
55 return 'parsed-gif';
58 function isMetadataValid( $image, $metadata ) {
59 wfSuppressWarnings();
60 $data = unserialize( $metadata );
61 wfRestoreWarnings();
62 return (boolean) $data;
65 function getLongDesc( $image ) {
66 global $wgLang;
68 $original = parent::getLongDesc( $image );
70 wfSuppressWarnings();
71 $metadata = unserialize($image->getMetadata());
72 wfRestoreWarnings();
74 if (!$metadata || $metadata['frameCount'] <= 1)
75 return $original;
77 $info = array();
78 $info[] = substr( $original, 1, strlen( $original )-2 );
80 if ($metadata['looped'])
81 $info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
83 if ($metadata['frameCount'] > 1)
84 $info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
86 if ($metadata['duration'])
87 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
89 $infoString = $wgLang->commaList( $info );
91 return "($infoString)";