17use Wikimedia\RequestTimeout\TimeoutException;
28 private const BROKEN_FILE =
'0';
34 }
catch ( TimeoutException $e ) {
36 }
catch ( Exception $e ) {
38 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
40 return [
'metadata' => [
'_error' => self::BROKEN_FILE ] ];
44 'width' => $parsedGIFMetadata[
'width'],
45 'height' => $parsedGIFMetadata[
'height'],
46 'bits' => $parsedGIFMetadata[
'bits'],
47 'metadata' => array_diff_key(
49 [
'width' =>
true,
'height' =>
true,
'bits' =>
true ]
75 if ( !isset( $meta[
'metadata'] ) || !is_array( $meta[
'metadata'] ) ) {
78 unset( $meta[
'metadata'][
'_MW_GIF_VERSION'] );
80 return $meta[
'metadata'];
90 $metadata = $image->getMetadataArray();
91 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 0 ) {
92 return $image->getWidth() * $image->getHeight() * $metadata[
'frameCount'];
94 return $image->getWidth() * $image->getHeight();
102 $metadata = $image->getMetadataArray();
103 if ( isset( $metadata[
'frameCount'] ) && $metadata[
'frameCount'] > 1 ) {
119 return $this->
getImageArea( $file ) <= $maxAnimatedGifArea;
129 $data = $image->getMetadataArray();
130 if ( $data === [
'_error' => self::BROKEN_FILE ] ) {
135 if ( !$data || isset( $data[
'_error'] ) ) {
136 wfDebug( __METHOD__ .
" invalid GIF metadata" );
141 if ( !isset( $data[
'metadata'][
'_MW_GIF_VERSION'] )
144 wfDebug( __METHOD__ .
" old but compatible GIF metadata" );
158 $original = parent::getLongDesc( $image );
160 $metadata = $image->getMetadataArray();
162 if ( !$metadata || isset( $metadata[
'_error'] ) || $metadata[
'frameCount'] <= 0 ) {
170 if ( $metadata[
'looped'] ) {
171 $info[] =
wfMessage(
'file-info-gif-looped' )->inLanguage( $lang )->parse();
174 if ( $metadata[
'frameCount'] > 1 ) {
175 $info[] =
wfMessage(
'file-info-gif-frames' )->numParams( $metadata[
'frameCount'] )
176 ->inLanguage( $lang )->parse();
179 if ( $metadata[
'duration'] ) {
180 $info[] = htmlspecialchars( $lang->formatTimePeriod( $metadata[
'duration'] ), ENT_QUOTES );
183 return $lang->commaList( $info );
195 $metadata = $file->getMetadataArray();
197 if ( !$metadata || !isset( $metadata[
'duration'] ) || !$metadata[
'duration'] ) {
200 return (
float)$metadata[
'duration'];
205class_alias( GIFHandler::class,
'GIFHandler' );
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.
A class containing constants representing the names of configuration variables.
const MaxAnimatedGifArea
Name constant for the MaxAnimatedGifArea setting, for use with Config::get()
Interface for objects which can provide a MediaWiki context on request.