summaryrefslogtreecommitdiff
path: root/includes/media/GIF.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/media/GIF.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/media/GIF.php')
-rw-r--r--includes/media/GIF.php48
1 files changed, 34 insertions, 14 deletions
diff --git a/includes/media/GIF.php b/includes/media/GIF.php
index 608fb257..5992be11 100644
--- a/includes/media/GIF.php
+++ b/includes/media/GIF.php
@@ -27,7 +27,6 @@
* @ingroup Media
*/
class GIFHandler extends BitmapHandler {
-
const BROKEN_FILE = '0'; // value to store in img_metadata if error extracting metadata.
function getMetadata( $image, $filename ) {
@@ -36,6 +35,7 @@ class GIFHandler extends BitmapHandler {
} catch ( Exception $e ) {
// Broken file?
wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
+
return self::BROKEN_FILE;
}
@@ -43,35 +43,49 @@ class GIFHandler extends BitmapHandler {
}
/**
- * @param $image File
+ * @param File $image
* @return array|bool
*/
function formatMetadata( $image ) {
+ $meta = $this->getCommonMetaArray( $image );
+ if ( count( $meta ) === 0 ) {
+ return false;
+ }
+
+ return $this->formatMetadataHelper( $meta );
+ }
+
+ /**
+ * Return the standard metadata elements for #filemetadata parser func.
+ * @param File $image
+ * @return array|bool
+ */
+ public function getCommonMetaArray( File $image ) {
$meta = $image->getMetadata();
if ( !$meta ) {
- return false;
+ return array();
}
$meta = unserialize( $meta );
- if ( !isset( $meta['metadata'] ) || count( $meta['metadata'] ) <= 1 ) {
- return false;
+ if ( !isset( $meta['metadata'] ) ) {
+ return array();
}
+ unset( $meta['metadata']['_MW_GIF_VERSION'] );
- if ( isset( $meta['metadata']['_MW_GIF_VERSION'] ) ) {
- unset( $meta['metadata']['_MW_GIF_VERSION'] );
- }
- return $this->formatMetadataHelper( $meta['metadata'] );
+ return $meta['metadata'];
}
/**
- * @param $image File
- * @todo unittests
+ * @todo Add unit tests
+ *
+ * @param File $image
* @return bool
*/
function getImageArea( $image ) {
$ser = $image->getMetadata();
if ( $ser ) {
$metadata = unserialize( $ser );
+
return $image->getWidth() * $image->getHeight() * $metadata['frameCount'];
} else {
return $image->getWidth() * $image->getHeight();
@@ -79,7 +93,7 @@ class GIFHandler extends BitmapHandler {
}
/**
- * @param $image File
+ * @param File $image
* @return bool
*/
function isAnimatedImage( $image ) {
@@ -90,6 +104,7 @@ class GIFHandler extends BitmapHandler {
return true;
}
}
+
return false;
}
@@ -101,6 +116,7 @@ class GIFHandler extends BitmapHandler {
function canAnimateThumbnail( $file ) {
global $wgMaxAnimatedGifArea;
$answer = $this->getImageArea( $file ) <= $wgMaxAnimatedGifArea;
+
return $answer;
}
@@ -120,19 +136,23 @@ class GIFHandler extends BitmapHandler {
if ( !$data || !is_array( $data ) ) {
wfDebug( __METHOD__ . " invalid GIF metadata\n" );
+
return self::METADATA_BAD;
}
if ( !isset( $data['metadata']['_MW_GIF_VERSION'] )
- || $data['metadata']['_MW_GIF_VERSION'] != GIFMetadataExtractor::VERSION ) {
+ || $data['metadata']['_MW_GIF_VERSION'] != GIFMetadataExtractor::VERSION
+ ) {
wfDebug( __METHOD__ . " old but compatible GIF metadata\n" );
+
return self::METADATA_COMPATIBLE;
}
+
return self::METADATA_GOOD;
}
/**
- * @param $image File
+ * @param File $image
* @return string
*/
function getLongDesc( $image ) {