X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fmedia%2FGIF.php;h=8ec72980369aa0729022a7ec594ea7d8e016754e;hb=58cb1f824ac75c3b58ba19d1e88c1b38f9dc1fab;hp=5992be11ede7e436db5e732f5290759999a5492e;hpb=05b8af8b91dac965c67571668187d1dc2511ae03;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/GIF.php b/includes/media/GIF.php index 5992be11ed..8ec7298036 100644 --- a/includes/media/GIF.php +++ b/includes/media/GIF.php @@ -44,15 +44,16 @@ class GIFHandler extends BitmapHandler { /** * @param File $image + * @param bool|IContextSource $context Context to use (optional) * @return array|bool */ - function formatMetadata( $image ) { + function formatMetadata( $image, $context = false ) { $meta = $this->getCommonMetaArray( $image ); if ( count( $meta ) === 0 ) { return false; } - return $this->formatMetadataHelper( $meta ); + return $this->formatMetadataHelper( $meta, $context ); } /** @@ -64,11 +65,11 @@ class GIFHandler extends BitmapHandler { $meta = $image->getMetadata(); if ( !$meta ) { - return array(); + return []; } $meta = unserialize( $meta ); if ( !isset( $meta['metadata'] ) ) { - return array(); + return []; } unset( $meta['metadata']['_MW_GIF_VERSION'] ); @@ -130,9 +131,9 @@ class GIFHandler extends BitmapHandler { return self::METADATA_GOOD; } - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $data = unserialize( $metadata ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$data || !is_array( $data ) ) { wfDebug( __METHOD__ . " invalid GIF metadata\n" ); @@ -160,16 +161,16 @@ class GIFHandler extends BitmapHandler { $original = parent::getLongDesc( $image ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $metadata = unserialize( $image->getMetadata() ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$metadata || $metadata['frameCount'] <= 1 ) { return $original; } /* Preserve original image info string, but strip the last char ')' so we can add even more */ - $info = array(); + $info = []; $info[] = $original; if ( $metadata['looped'] ) { @@ -186,4 +187,25 @@ class GIFHandler extends BitmapHandler { return $wgLang->commaList( $info ); } + + /** + * Return the duration of the GIF file. + * + * Shown in the &query=imageinfo&iiprop=size api query. + * + * @param $file File + * @return float The duration of the file. + */ + public function getLength( $file ) { + $serMeta = $file->getMetadata(); + MediaWiki\suppressWarnings(); + $metadata = unserialize( $serMeta ); + MediaWiki\restoreWarnings(); + + if ( !$metadata || !isset( $metadata['duration'] ) || !$metadata['duration'] ) { + return 0.0; + } else { + return (float)$metadata['duration']; + } + } }