$meta = $image->getMetadata();
if ( !$meta ) {
- return array();
+ return [];
}
$meta = unserialize( $meta );
if ( !isset( $meta['metadata'] ) ) {
- return array();
+ return [];
}
unset( $meta['metadata']['_MW_GIF_VERSION'] );
}
/* Preserve original image info string, but strip the last char ')' so we can add even more */
- $info = array();
+ $info = [];
$info[] = $original;
if ( $metadata['looped'] ) {
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'];
+ }
+ }
}