wiki.techinc.nl/includes/media/GIF.php
Brion Vibber 2807a6df29 * (bug 20364) Fixed regression in GIF metadata loading
There was a missing parameter in GIFMetadataExtractor's skipBlock() call for 'netscape 2.0' data blocks, which threw a monkey in the works.
Now also checking for exceptions thrown by the metadata load and stubbing out null metadata for files which can't be read, rather than letting the exception bubble up and kill MediaWiki. :)
2009-08-23 23:27:32 +00:00

72 lines
1.5 KiB
PHP

<?php
/**
* @file
* @ingroup Media
*/
/**
* Handler for GIF images.
*
* @ingroup Media
*/
class GIFHandler extends BitmapHandler {
function getMetadata( $image, $filename ) {
if ( !isset($image->parsedGIFMetadata) ) {
try {
$image->parsedGIFMetadata = GIFMetadataExtractor::getMetadata( $filename );
} catch( Exception $e ) {
// Broken file?
wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
return '0';
}
}
return serialize($image->parsedGIFMetadata);
}
function formatMetadata( $image ) {
return false;
}
function getImageArea( $image, $width, $height ) {
$ser = $image->getMetadata();
if ($ser) {
$metadata = unserialize($ser);
return $width * $height * $metadata['frameCount'];
} else {
return $width * $height;
}
}
function getMetadataType( $image ) {
return 'parsed-gif';
}
function getLongDesc( $image ) {
global $wgUser, $wgLang;
$sk = $wgUser->getSkin();
$metadata = @unserialize($image->getMetadata());
if (!$metadata) return parent::getLongDesc( $image );
$info = array();
$info[] = $image->getMimeType();
$info[] = $sk->formatSize( $image->getSize() );
if ($metadata['looped'])
$info[] = wfMsgExt( 'file-info-gif-looped', 'parseinline' );
if ($metadata['frameCount'] > 1)
$info[] = wfMsgExt( 'file-info-gif-frames', 'parseinline', $metadata['frameCount'] );
if ($metadata['duration'])
$info[] = $wgLang->formatTimePeriod( $metadata['duration'] );
$infoString = $wgLang->commaList( $info );
return "($infoString)";
}
}