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