27use Wikimedia\RequestTimeout\TimeoutException;
38 private const BROKEN_FILE =
'0';
43 }
catch ( TimeoutException $e ) {
45 }
catch ( Exception $e ) {
47 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
49 return [
'metadata' => [
'_error' => self::BROKEN_FILE ] ];
53 'width' => $parsedGIFMetadata[
'width'],
54 'height' => $parsedGIFMetadata[
'height'],
55 'bits' => $parsedGIFMetadata[
'bits'],
56 'metadata' => array_diff_key(
58 [
'width' =>
true,
'height' =>
true,
'bits' =>
true ]
84 if ( !isset( $meta[
'metadata'] ) ) {
87 unset( $meta[
'metadata'][
'_MW_GIF_VERSION'] );
89 return $meta[
'metadata'];
99 $metadata = $image->getMetadataArray();
100 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 0 ) {
101 return $image->getWidth() * $image->getHeight() * $metadata[
'frameCount'];
103 return $image->getWidth() * $image->getHeight();
111 $metadata = $image->getMetadataArray();
112 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 1 ) {
125 $maxAnimatedGifArea = MediaWikiServices::getInstance()->getMainConfig()
126 ->get( MainConfigNames::MaxAnimatedGifArea );
128 return $this->
getImageArea( $file ) <= $maxAnimatedGifArea;
136 $data = $image->getMetadataArray();
137 if ( $data === [
'_error' => self::BROKEN_FILE ] ) {
142 if ( !$data || isset( $data[
'_error'] ) ) {
143 wfDebug( __METHOD__ .
" invalid GIF metadata" );
148 if ( !isset( $data[
'metadata'][
'_MW_GIF_VERSION'] )
151 wfDebug( __METHOD__ .
" old but compatible GIF metadata" );
166 $original = parent::getLongDesc( $image );
168 $metadata = $image->getMetadataArray();
170 if ( !$metadata || isset( $metadata[
'_error'] ) || $metadata[
'frameCount'] <= 0 ) {
178 if ( $metadata[
'looped'] ) {
179 $info[] =
wfMessage(
'file-info-gif-looped' )->parse();
182 if ( $metadata[
'frameCount'] > 1 ) {
183 $info[] =
wfMessage(
'file-info-gif-frames' )->numParams( $metadata[
'frameCount'] )->parse();
186 if ( $metadata[
'duration'] ) {
187 $info[] =
$wgLang->formatTimePeriod( $metadata[
'duration'] );
190 return $wgLang->commaList( $info );
202 $metadata = $file->getMetadataArray();
204 if ( !$metadata || !isset( $metadata[
'duration'] ) || !$metadata[
'duration'] ) {
207 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.
Implements some public methods and some protected utility functions which are required by multiple ch...
getMetadataArray()
Get the unserialized handler-specific metadata STUB.
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.