28use Wikimedia\RequestTimeout\TimeoutException;
39 private const BROKEN_FILE =
'0';
44 }
catch ( TimeoutException $e ) {
46 }
catch ( Exception $e ) {
48 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
50 return [
'metadata' => [
'_error' => self::BROKEN_FILE ] ];
54 'width' => $parsedGIFMetadata[
'width'],
55 'height' => $parsedGIFMetadata[
'height'],
56 'bits' => $parsedGIFMetadata[
'bits'],
57 'metadata' => array_diff_key(
59 [
'width' =>
true,
'height' =>
true,
'bits' =>
true ]
85 if ( !isset( $meta[
'metadata'] ) ) {
88 unset( $meta[
'metadata'][
'_MW_GIF_VERSION'] );
90 return $meta[
'metadata'];
100 $metadata = $image->getMetadataArray();
101 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 0 ) {
102 return $image->getWidth() * $image->getHeight() * $metadata[
'frameCount'];
104 return $image->getWidth() * $image->getHeight();
112 $metadata = $image->getMetadataArray();
113 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 1 ) {
126 $maxAnimatedGifArea = MediaWikiServices::getInstance()->getMainConfig()
127 ->get( MainConfigNames::MaxAnimatedGifArea );
129 return $this->
getImageArea( $file ) <= $maxAnimatedGifArea;
137 $data = $image->getMetadataArray();
138 if ( $data === [
'_error' => self::BROKEN_FILE ] ) {
143 if ( !$data || isset( $data[
'_error'] ) ) {
144 wfDebug( __METHOD__ .
" invalid GIF metadata" );
149 if ( !isset( $data[
'metadata'][
'_MW_GIF_VERSION'] )
152 wfDebug( __METHOD__ .
" old but compatible GIF metadata" );
167 $original = parent::getLongDesc( $image );
169 $metadata = $image->getMetadataArray();
171 if ( !$metadata || isset( $metadata[
'_error'] ) || $metadata[
'frameCount'] <= 0 ) {
179 if ( $metadata[
'looped'] ) {
180 $info[] =
wfMessage(
'file-info-gif-looped' )->parse();
183 if ( $metadata[
'frameCount'] > 1 ) {
184 $info[] =
wfMessage(
'file-info-gif-frames' )->numParams( $metadata[
'frameCount'] )->parse();
187 if ( $metadata[
'duration'] ) {
188 $info[] =
$wgLang->formatTimePeriod( $metadata[
'duration'] );
191 return $wgLang->commaList( $info );
203 $metadata = $file->getMetadataArray();
205 if ( !$metadata || !isset( $metadata[
'duration'] ) || !$metadata[
'duration'] ) {
208 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(!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.
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.
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.
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.