* (bug 31282) Fix use of ForeignAPIRepo/InstantCommons TIFF images when $wgTiffThumbn...
[lhc/web/wiklou.git] / includes / media / Tiff.php
1 <?php
2 /**
3 * Handler for Tiff images.
4 *
5 * @file
6 * @ingroup Media
7 */
8
9 /**
10 * Handler for Tiff images.
11 *
12 * @ingroup Media
13 */
14 class TiffHandler extends ExifBitmapHandler {
15
16 /**
17 * Conversion to PNG for inline display can be disabled here...
18 * Note scaling should work with ImageMagick, but may not with GD scaling.
19 *
20 * Files pulled from an another MediaWiki instance via ForeignAPIRepo /
21 * InstantCommons will have thumbnails managed from the remote instance,
22 * so we can skip this check.
23 *
24 * @param $file
25 *
26 * @return bool
27 */
28 function canRender( $file ) {
29 global $wgTiffThumbnailType;
30 return (bool)$wgTiffThumbnailType
31 || ($file->getRepo() instanceof ForeignAPIRepo);
32 }
33
34 /**
35 * Browsers don't support TIFF inline generally...
36 * For inline display, we need to convert to PNG.
37 *
38 * @param $file
39 *
40 * @return bool
41 */
42 function mustRender( $file ) {
43 return true;
44 }
45
46 /**
47 * @param $ext
48 * @param $mime
49 * @param $params
50 * @return bool
51 */
52 function getThumbType( $ext, $mime, $params = null ) {
53 global $wgTiffThumbnailType;
54 return $wgTiffThumbnailType;
55 }
56
57 /**
58 * @param $image
59 * @param $filename
60 * @return string
61 */
62 function getMetadata( $image, $filename ) {
63 global $wgShowEXIF;
64 if ( $wgShowEXIF ) {
65 try {
66 $meta = BitmapMetadataHandler::Tiff( $filename );
67 if ( !is_array( $meta ) ) {
68 // This should never happen, but doesn't hurt to be paranoid.
69 throw new MWException('Metadata array is not an array');
70 }
71 $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
72 return serialize( $meta );
73 }
74 catch ( MWException $e ) {
75 // BitmapMetadataHandler throws an exception in certain exceptional
76 // cases like if file does not exist.
77 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
78 return ExifBitmapHandler::BROKEN_FILE;
79 }
80 } else {
81 return '';
82 }
83 }
84 }