Add release note for Ieec65c90
[mediawiki.git] / includes / media / Tiff.php
blob55dff77b071fdf6224457a9f574226ab0774a12c
1 <?php
2 /**
3 * Handler for Tiff images.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Media
24 /**
25 * Handler for Tiff images.
27 * @ingroup Media
29 class TiffHandler extends ExifBitmapHandler {
31 /**
32 * Conversion to PNG for inline display can be disabled here...
33 * Note scaling should work with ImageMagick, but may not with GD scaling.
35 * Files pulled from an another MediaWiki instance via ForeignAPIRepo /
36 * InstantCommons will have thumbnails managed from the remote instance,
37 * so we can skip this check.
39 * @param $file
41 * @return bool
43 function canRender( $file ) {
44 global $wgTiffThumbnailType;
45 return (bool)$wgTiffThumbnailType
46 || ($file->getRepo() instanceof ForeignAPIRepo);
49 /**
50 * Browsers don't support TIFF inline generally...
51 * For inline display, we need to convert to PNG.
53 * @param $file
55 * @return bool
57 function mustRender( $file ) {
58 return true;
61 /**
62 * @param $ext
63 * @param $mime
64 * @param $params
65 * @return bool
67 function getThumbType( $ext, $mime, $params = null ) {
68 global $wgTiffThumbnailType;
69 return $wgTiffThumbnailType;
72 /**
73 * @param File $image
74 * @param string $filename
75 * @throws MWException
76 * @return string
78 function getMetadata( $image, $filename ) {
79 global $wgShowEXIF;
80 if ( $wgShowEXIF ) {
81 try {
82 $meta = BitmapMetadataHandler::Tiff( $filename );
83 if ( !is_array( $meta ) ) {
84 // This should never happen, but doesn't hurt to be paranoid.
85 throw new MWException('Metadata array is not an array');
87 $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
88 return serialize( $meta );
90 catch ( MWException $e ) {
91 // BitmapMetadataHandler throws an exception in certain exceptional
92 // cases like if file does not exist.
93 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
94 return ExifBitmapHandler::BROKEN_FILE;
96 } else {
97 return '';