Follow up r68324.
[lhc/web/wiklou.git] / includes / media / PNG.php
1 <?php
2 /**
3 * @file
4 * @ingroup Media
5 */
6
7 /**
8 * Handler for PNG images.
9 *
10 * @ingroup Media
11 */
12 class PNGHandler extends BitmapHandler {
13
14 function getMetadata( $image, $filename ) {
15 if ( !isset($image->parsedPNGMetadata) ) {
16 try {
17 $image->parsedPNGMetadata = PNGMetadataExtractor::getMetadata( $filename );
18 } catch( Exception $e ) {
19 // Broken file?
20 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
21 return '0';
22 }
23 }
24
25 return serialize($image->parsedPNGMetadata);
26
27 }
28
29 function formatMetadata( $image ) {
30 return false;
31 }
32
33 function isAnimatedImage( $image ) {
34 $ser = $image->getMetadata();
35 if ($ser) {
36 $metadata = unserialize($ser);
37 if( $metadata['frameCount'] > 1 ) return true;
38 }
39 return false;
40 }
41
42 function getMetadataType( $image ) {
43 return 'parsed-png';
44 }
45
46 function isMetadataValid( $image, $metadata ) {
47 wfSuppressWarnings();
48 $data = unserialize( $metadata );
49 wfRestoreWarnings();
50 return (boolean) $data;
51 }
52 function getLongDesc( $image ) {
53 global $wgUser, $wgLang;
54 $sk = $wgUser->getSkin();
55 $original = parent::getLongDesc( $image );
56
57 wfSuppressWarnings();
58 $metadata = unserialize($image->getMetadata());
59 wfRestoreWarnings();
60
61 if( !metadata || $metadata['frameCount'] == 0 )
62 return $original;
63
64 $info = array();
65 $info[] = substr( $original, 1, strlen( $original )-2 );
66
67 if ($metadata['loopCount'] == 0)
68 $info[] = wfMsgExt( 'file-info-png-looped', 'parseinline' );
69 elseif ($metadata['loopCount'] > 1)
70 $info[] = wfMsgExt( 'file-info-png-repeat', 'parseinline', $metadata['loopCount'] );;
71
72 if ($metadata['frameCount'] > 0)
73 $info[] = wfMsgExt( 'file-info-png-frames', 'parseinline', $metadata['frameCount'] );
74
75 if ($metadata['duration'])
76 $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
77
78 $infoString = $wgLang->commaList( $info );
79
80 return "($infoString)";
81 }
82
83 }