Merge "User: Migrate from foreign cache to global cache for UserRightsProxy"
[lhc/web/wiklou.git] / includes / media / PNG.php
index 5f1aca5..e297fe1 100644 (file)
@@ -118,9 +118,9 @@ class PNGHandler extends BitmapHandler {
                        return self::METADATA_GOOD;
                }
 
-               wfSuppressWarnings();
+               MediaWiki\suppressWarnings();
                $data = unserialize( $metadata );
-               wfRestoreWarnings();
+               MediaWiki\restoreWarnings();
 
                if ( !$data || !is_array( $data ) ) {
                        wfDebug( __METHOD__ . " invalid png metadata\n" );
@@ -147,9 +147,9 @@ class PNGHandler extends BitmapHandler {
                global $wgLang;
                $original = parent::getLongDesc( $image );
 
-               wfSuppressWarnings();
+               MediaWiki\suppressWarnings();
                $metadata = unserialize( $image->getMetadata() );
-               wfRestoreWarnings();
+               MediaWiki\restoreWarnings();
 
                if ( !$metadata || $metadata['frameCount'] <= 0 ) {
                        return $original;
@@ -175,9 +175,29 @@ class PNGHandler extends BitmapHandler {
                return $wgLang->commaList( $info );
        }
 
+       /**
+        * Return the duration of an APNG 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'];
+               }
+       }
+
        // PNGs should be easy to support, but it will need some sharpening applied
        // and another user test to check if the perceived quality change is noticeable
-
        public function supportsBucketing() {
                return false;
        }