| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
use MediaWiki\MainConfigNames; |
| 25 |
use MediaWiki\MediaWikiServices; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class TiffHandler extends ExifBitmapHandler { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
private const EXPENSIVE_SIZE_LIMIT = 10_485_760; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function canRender( $file ) { |
| 50 |
$tiffThumbnailType = MediaWikiServices::getInstance()->getMainConfig() |
| 51 |
->get( MainConfigNames::TiffThumbnailType ); |
| 52 |
|
| 53 |
return (bool)$tiffThumbnailType |
| 54 |
|| $file->getRepo() instanceof ForeignAPIRepo; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function mustRender( $file ) { |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public function getThumbType( $ext, $mime, $params = null ) { |
| 75 |
$tiffThumbnailType = MediaWikiServices::getInstance()->getMainConfig() |
| 76 |
->get( MainConfigNames::TiffThumbnailType ); |
| 77 |
|
| 78 |
return $tiffThumbnailType; |
| 79 |
} |
| 80 |
|
| 81 |
public function getSizeAndMetadata( $state, $filename ) { |
| 82 |
$showEXIF = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::ShowEXIF ); |
| 83 |
|
| 84 |
try { |
| 85 |
$meta = BitmapMetadataHandler::Tiff( $filename ); |
| 86 |
if ( !is_array( $meta ) ) { |
| 87 |
|
| 88 |
throw new InvalidTiffException( 'Metadata array is not an array' ); |
| 89 |
} |
| 90 |
$info = [ |
| 91 |
'width' => $meta['ImageWidth'] ?? 0, |
| 92 |
'height' => $meta['ImageLength'] ?? 0, |
| 93 |
]; |
| 94 |
$info = $this->applyExifRotation( $info, $meta ); |
| 95 |
if ( $showEXIF ) { |
| 96 |
$meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version(); |
| 97 |
$info['metadata'] = $meta; |
| 98 |
} |
| 99 |
return $info; |
| 100 |
} catch ( InvalidTiffException $e ) { |
| 101 |
|
| 102 |
|
| 103 |
wfDebug( __METHOD__ . ': ' . $e->getMessage() ); |
| 104 |
|
| 105 |
return [ 'metadata' => [ '_error' => ExifBitmapHandler::BROKEN_FILE ] ]; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
public function isExpensiveToThumbnail( $file ) { |
| 110 |
return $file->getSize() > static::EXPENSIVE_SIZE_LIMIT; |
| 111 |
} |
| 112 |
} |