14use Wikimedia\RequestTimeout\TimeoutException;
25 private const BROKEN_FILE =
'0';
31 }
catch ( TimeoutException $e ) {
33 }
catch ( Exception $e ) {
35 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
37 return [
'metadata' => [
'_error' => self::BROKEN_FILE ] ];
41 'width' => $parsedGIFMetadata[
'width'],
42 'height' => $parsedGIFMetadata[
'height'],
43 'bits' => $parsedGIFMetadata[
'bits'],
44 'metadata' => array_diff_key(
46 [
'width' =>
true,
'height' =>
true,
'bits' =>
true ]
72 if ( !isset( $meta[
'metadata'] ) ) {
75 unset( $meta[
'metadata'][
'_MW_GIF_VERSION'] );
77 return $meta[
'metadata'];
87 $metadata = $image->getMetadataArray();
88 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 0 ) {
89 return $image->getWidth() * $image->getHeight() * $metadata[
'frameCount'];
91 return $image->getWidth() * $image->getHeight();
99 $metadata = $image->getMetadataArray();
100 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 1 ) {
113 $maxAnimatedGifArea = MediaWikiServices::getInstance()->getMainConfig()
114 ->get( MainConfigNames::MaxAnimatedGifArea );
116 return $this->
getImageArea( $file ) <= $maxAnimatedGifArea;
126 $data = $image->getMetadataArray();
127 if ( $data === [
'_error' => self::BROKEN_FILE ] ) {
132 if ( !$data || isset( $data[
'_error'] ) ) {
133 wfDebug( __METHOD__ .
" invalid GIF metadata" );
138 if ( !isset( $data[
'metadata'][
'_MW_GIF_VERSION'] )
141 wfDebug( __METHOD__ .
" old but compatible GIF metadata" );
156 $original = parent::getLongDesc( $image );
158 $metadata = $image->getMetadataArray();
160 if ( !$metadata || isset( $metadata[
'_error'] ) || $metadata[
'frameCount'] <= 0 ) {
168 if ( $metadata[
'looped'] ) {
169 $info[] =
wfMessage(
'file-info-gif-looped' )->parse();
172 if ( $metadata[
'frameCount'] > 1 ) {
173 $info[] =
wfMessage(
'file-info-gif-frames' )->numParams( $metadata[
'frameCount'] )->parse();
176 if ( $metadata[
'duration'] ) {
177 $info[] = htmlspecialchars(
$wgLang->formatTimePeriod( $metadata[
'duration'] ), ENT_QUOTES );
180 return $wgLang->commaList( $info );
192 $metadata = $file->getMetadataArray();
194 if ( !$metadata || !isset( $metadata[
'duration'] ) || !$metadata[
'duration'] ) {
197 return (
float)$metadata[
'duration'];
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
Generic handler for bitmap images.
isFileMetadataValid( $image)
Check if the metadata is valid for this handler.If it returns MediaHandler::METADATA_BAD (or false),...
getLength( $file)
Return the duration of the GIF file.
canAnimateThumbnail( $file)
We cannot animate thumbnails that are bigger than a particular size.
formatMetadata( $image, $context=false)
getSizeAndMetadata( $state, $filename)
Get image size information and metadata array.If this returns null, the caller will fall back to getI...
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.to overrideThis method is currentl...
getCommonMetaArray(File $image)
Return the standard metadata elements for #filemetadata parser func.
A class containing constants representing the names of configuration variables.
Interface for objects which can provide a MediaWiki context on request.