Merge "Remove $this reference in static method"
[lhc/web/wiklou.git] / includes / media / GIF.php
index e3621fb..b998d18 100644 (file)
@@ -131,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" );
@@ -161,9 +161,9 @@ 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;
@@ -187,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'];
+               }
+       }
 }