MediaWiki  1.23.8
PNG.php
Go to the documentation of this file.
1 <?php
29 class PNGHandler extends BitmapHandler {
30  const BROKEN_FILE = '0';
31 
37  function getMetadata( $image, $filename ) {
38  try {
39  $metadata = BitmapMetadataHandler::PNG( $filename );
40  } catch ( Exception $e ) {
41  // Broken file?
42  wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
43 
44  return self::BROKEN_FILE;
45  }
46 
47  return serialize( $metadata );
48  }
49 
54  function formatMetadata( $image ) {
55  $meta = $this->getCommonMetaArray( $image );
56  if ( count( $meta ) === 0 ) {
57  return false;
58  }
59 
60  return $this->formatMetadataHelper( $meta );
61  }
62 
69  public function getCommonMetaArray( File $image ) {
70  $meta = $image->getMetadata();
71 
72  if ( !$meta ) {
73  return array();
74  }
75  $meta = unserialize( $meta );
76  if ( !isset( $meta['metadata'] ) ) {
77  return array();
78  }
79  unset( $meta['metadata']['_MW_PNG_VERSION'] );
80 
81  return $meta['metadata'];
82  }
83 
88  function isAnimatedImage( $image ) {
89  $ser = $image->getMetadata();
90  if ( $ser ) {
91  $metadata = unserialize( $ser );
92  if ( $metadata['frameCount'] > 1 ) {
93  return true;
94  }
95  }
96 
97  return false;
98  }
99 
105  function canAnimateThumbnail( $image ) {
106  return false;
107  }
108 
109  function getMetadataType( $image ) {
110  return 'parsed-png';
111  }
112 
113  function isMetadataValid( $image, $metadata ) {
114 
115  if ( $metadata === self::BROKEN_FILE ) {
116  // Do not repetitivly regenerate metadata on broken file.
117  return self::METADATA_GOOD;
118  }
119 
121  $data = unserialize( $metadata );
123 
124  if ( !$data || !is_array( $data ) ) {
125  wfDebug( __METHOD__ . " invalid png metadata\n" );
126 
127  return self::METADATA_BAD;
128  }
129 
130  if ( !isset( $data['metadata']['_MW_PNG_VERSION'] )
131  || $data['metadata']['_MW_PNG_VERSION'] != PNGMetadataExtractor::VERSION
132  ) {
133  wfDebug( __METHOD__ . " old but compatible png metadata\n" );
134 
136  }
137 
138  return self::METADATA_GOOD;
139  }
140 
145  function getLongDesc( $image ) {
146  global $wgLang;
147  $original = parent::getLongDesc( $image );
148 
150  $metadata = unserialize( $image->getMetadata() );
152 
153  if ( !$metadata || $metadata['frameCount'] <= 0 ) {
154  return $original;
155  }
156 
157  $info = array();
158  $info[] = $original;
159 
160  if ( $metadata['loopCount'] == 0 ) {
161  $info[] = wfMessage( 'file-info-png-looped' )->parse();
162  } elseif ( $metadata['loopCount'] > 1 ) {
163  $info[] = wfMessage( 'file-info-png-repeat' )->numParams( $metadata['loopCount'] )->parse();
164  }
165 
166  if ( $metadata['frameCount'] > 0 ) {
167  $info[] = wfMessage( 'file-info-png-frames' )->numParams( $metadata['frameCount'] )->parse();
168  }
169 
170  if ( $metadata['duration'] ) {
171  $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
172  }
173 
174  return $wgLang->commaList( $info );
175  }
176 }
PNGHandler\canAnimateThumbnail
canAnimateThumbnail( $image)
We do not support making APNG thumbnails, so always false.
Definition: PNG.php:105
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
PNGMetadataExtractor\VERSION
const VERSION
Definition: PNGMetadataExtractor.php:43
PNGHandler\isMetadataValid
isMetadataValid( $image, $metadata)
Check if the metadata string is valid for this handler.
Definition: PNG.php:113
File\getMetadata
getMetadata()
Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB.
Definition: File.php:555
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
PNGHandler\BROKEN_FILE
const BROKEN_FILE
Definition: PNG.php:30
PNGHandler\formatMetadata
formatMetadata( $image)
Definition: PNG.php:54
MediaHandler\METADATA_COMPATIBLE
const METADATA_COMPATIBLE
Definition: MediaHandler.php:33
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
BitmapHandler
Generic handler for bitmap images.
Definition: Bitmap.php:29
PNGHandler\getCommonMetaArray
getCommonMetaArray(File $image)
Get a file type independent array of metadata.
Definition: PNG.php:69
PNGHandler\getMetadata
getMetadata( $image, $filename)
Definition: PNG.php:37
PNGHandler\isAnimatedImage
isAnimatedImage( $image)
Definition: PNG.php:88
PNGHandler\getLongDesc
getLongDesc( $image)
Definition: PNG.php:145
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MediaHandler\formatMetadataHelper
formatMetadataHelper( $metadataArray)
sorts the visible/invisible field.
Definition: MediaHandler.php:500
PNGHandler\getMetadataType
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.
Definition: PNG.php:109
BitmapMetadataHandler\PNG
static PNG( $filename)
Entry point for png At some point in the future this might merge the png various tEXt chunks to that ...
Definition: BitmapMetadataHandler.php:195
PNGHandler
Handler for PNG images.
Definition: PNG.php:29
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
MediaHandler\METADATA_BAD
const METADATA_BAD
Definition: MediaHandler.php:32
$e
if( $useReadline) $e
Definition: eval.php:66
MediaHandler\METADATA_GOOD
const METADATA_GOOD
Definition: MediaHandler.php:31