MediaWiki REL1_40
TiffHandler.php
Go to the documentation of this file.
1<?php
26use Wikimedia\RequestTimeout\TimeoutException;
27
37 private const EXPENSIVE_SIZE_LIMIT = 10485760;
38
50 public function canRender( $file ) {
51 $tiffThumbnailType = MediaWikiServices::getInstance()->getMainConfig()
52 ->get( MainConfigNames::TiffThumbnailType );
53
54 return (bool)$tiffThumbnailType
55 || $file->getRepo() instanceof ForeignAPIRepo;
56 }
57
65 public function mustRender( $file ) {
66 return true;
67 }
68
75 public function getThumbType( $ext, $mime, $params = null ) {
76 $tiffThumbnailType = MediaWikiServices::getInstance()->getMainConfig()
77 ->get( MainConfigNames::TiffThumbnailType );
78
79 return $tiffThumbnailType;
80 }
81
82 public function getSizeAndMetadata( $state, $filename ) {
83 $showEXIF = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::ShowEXIF );
84
85 try {
86 $meta = BitmapMetadataHandler::Tiff( $filename );
87 if ( !is_array( $meta ) ) {
88 // This should never happen, but doesn't hurt to be paranoid.
89 throw new UnexpectedValueException( 'Metadata array is not an array' );
90 }
91 $info = [
92 'width' => $meta['ImageWidth'] ?? 0,
93 'height' => $meta['ImageLength'] ?? 0,
94 ];
95 $info = $this->applyExifRotation( $info, $meta );
96 if ( $showEXIF ) {
97 $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
98 $info['metadata'] = $meta;
99 }
100 return $info;
101 } catch ( TimeoutException $e ) {
102 throw $e;
103 } catch ( Exception $e ) {
104 // BitmapMetadataHandler throws an exception in certain exceptional
105 // cases like if file does not exist.
106 wfDebug( __METHOD__ . ': ' . $e->getMessage() );
107
108 return [ 'metadata' => [ '_error' => ExifBitmapHandler::BROKEN_FILE ] ];
109 }
110 }
111
112 public function isExpensiveToThumbnail( $file ) {
113 return $file->getSize() > static::EXPENSIVE_SIZE_LIMIT;
114 }
115}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static Tiff( $filename)
This doesn't do much yet, but eventually I plan to add XMP support for Tiff.
Stuff specific to JPEG and (built-in) TIFF handler.
applyExifRotation( $info, $metadata)
const BROKEN_FILE
Error extracting metadata.
static version()
#-
Definition Exif.php:714
A foreign repository for a remote MediaWiki accessible through api.php requests.
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
Handler for Tiff images.
isExpensiveToThumbnail( $file)
True if creating thumbnails from the file is large or otherwise resource-intensive.
getThumbType( $ext, $mime, $params=null)
canRender( $file)
Conversion to PNG for inline display can be disabled here... Note scaling should work with ImageMagic...
mustRender( $file)
Browsers don't support TIFF inline generally... For inline display, we need to convert to PNG.
getSizeAndMetadata( $state, $filename)
Get image size information and metadata array.
$mime
Definition router.php:60
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42
if(!is_readable( $file)) $ext
Definition router.php:48