MediaWiki  1.23.0
GIF.php
Go to the documentation of this file.
1 <?php
29 class GIFHandler extends BitmapHandler {
30  const BROKEN_FILE = '0'; // value to store in img_metadata if error extracting metadata.
31 
32  function getMetadata( $image, $filename ) {
33  try {
34  $parsedGIFMetadata = BitmapMetadataHandler::GIF( $filename );
35  } catch ( Exception $e ) {
36  // Broken file?
37  wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
38 
39  return self::BROKEN_FILE;
40  }
41 
42  return serialize( $parsedGIFMetadata );
43  }
44 
49  function formatMetadata( $image ) {
50  $meta = $this->getCommonMetaArray( $image );
51  if ( count( $meta ) === 0 ) {
52  return false;
53  }
54 
55  return $this->formatMetadataHelper( $meta );
56  }
57 
63  public function getCommonMetaArray( File $image ) {
64  $meta = $image->getMetadata();
65 
66  if ( !$meta ) {
67  return array();
68  }
69  $meta = unserialize( $meta );
70  if ( !isset( $meta['metadata'] ) ) {
71  return array();
72  }
73  unset( $meta['metadata']['_MW_GIF_VERSION'] );
74 
75  return $meta['metadata'];
76  }
77 
84  function getImageArea( $image ) {
85  $ser = $image->getMetadata();
86  if ( $ser ) {
87  $metadata = unserialize( $ser );
88 
89  return $image->getWidth() * $image->getHeight() * $metadata['frameCount'];
90  } else {
91  return $image->getWidth() * $image->getHeight();
92  }
93  }
94 
99  function isAnimatedImage( $image ) {
100  $ser = $image->getMetadata();
101  if ( $ser ) {
102  $metadata = unserialize( $ser );
103  if ( $metadata['frameCount'] > 1 ) {
104  return true;
105  }
106  }
107 
108  return false;
109  }
110 
117  global $wgMaxAnimatedGifArea;
118  $answer = $this->getImageArea( $file ) <= $wgMaxAnimatedGifArea;
119 
120  return $answer;
121  }
122 
123  function getMetadataType( $image ) {
124  return 'parsed-gif';
125  }
126 
127  function isMetadataValid( $image, $metadata ) {
128  if ( $metadata === self::BROKEN_FILE ) {
129  // Do not repetitivly regenerate metadata on broken file.
130  return self::METADATA_GOOD;
131  }
132 
134  $data = unserialize( $metadata );
136 
137  if ( !$data || !is_array( $data ) ) {
138  wfDebug( __METHOD__ . " invalid GIF metadata\n" );
139 
140  return self::METADATA_BAD;
141  }
142 
143  if ( !isset( $data['metadata']['_MW_GIF_VERSION'] )
144  || $data['metadata']['_MW_GIF_VERSION'] != GIFMetadataExtractor::VERSION
145  ) {
146  wfDebug( __METHOD__ . " old but compatible GIF metadata\n" );
147 
149  }
150 
151  return self::METADATA_GOOD;
152  }
153 
158  function getLongDesc( $image ) {
159  global $wgLang;
160 
161  $original = parent::getLongDesc( $image );
162 
164  $metadata = unserialize( $image->getMetadata() );
166 
167  if ( !$metadata || $metadata['frameCount'] <= 1 ) {
168  return $original;
169  }
170 
171  /* Preserve original image info string, but strip the last char ')' so we can add even more */
172  $info = array();
173  $info[] = $original;
174 
175  if ( $metadata['looped'] ) {
176  $info[] = wfMessage( 'file-info-gif-looped' )->parse();
177  }
178 
179  if ( $metadata['frameCount'] > 1 ) {
180  $info[] = wfMessage( 'file-info-gif-frames' )->numParams( $metadata['frameCount'] )->parse();
181  }
182 
183  if ( $metadata['duration'] ) {
184  $info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
185  }
186 
187  return $wgLang->commaList( $info );
188  }
189 }
GIFHandler\canAnimateThumbnail
canAnimateThumbnail( $file)
We cannot animate thumbnails that are bigger than a particular size.
Definition: GIF.php:116
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
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
GIFHandler\getMetadata
getMetadata( $image, $filename)
Get handler-specific metadata which will be saved in the img_metadata field.
Definition: GIF.php:32
BitmapMetadataHandler\GIF
static GIF( $filename)
function for gif images.
Definition: BitmapMetadataHandler.php:227
GIFHandler
Handler for GIF images.
Definition: GIF.php:29
GIFHandler\getLongDesc
getLongDesc( $image)
Definition: GIF.php:158
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
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
GIFHandler\isAnimatedImage
isAnimatedImage( $image)
Definition: GIF.php:99
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
GIFHandler\formatMetadata
formatMetadata( $image)
Definition: GIF.php:49
GIFHandler\getCommonMetaArray
getCommonMetaArray(File $image)
Return the standard metadata elements for #filemetadata parser func.
Definition: GIF.php:63
MediaHandler\formatMetadataHelper
formatMetadataHelper( $metadataArray)
sorts the visible/invisible field.
Definition: MediaHandler.php:500
GIFHandler\getImageArea
getImageArea( $image)
Definition: GIF.php:84
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
GIFHandler\isMetadataValid
isMetadataValid( $image, $metadata)
Check if the metadata string is valid for this handler.
Definition: GIF.php:127
GIFHandler\BROKEN_FILE
const BROKEN_FILE
Definition: GIF.php:30
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
$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
GIFHandler\getMetadataType
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.
Definition: GIF.php:123
MediaHandler\METADATA_BAD
const METADATA_BAD
Definition: MediaHandler.php:32
GIFMetadataExtractor\VERSION
const VERSION
Definition: GIFMetadataExtractor.php:44
$e
if( $useReadline) $e
Definition: eval.php:66
MediaHandler\METADATA_GOOD
const METADATA_GOOD
Definition: MediaHandler.php:31