2009-03-16 22:03:20 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2010-08-15 17:27:41 +00:00
|
|
|
* Handler for Tiff images.
|
|
|
|
|
*
|
2012-05-03 20:13:10 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2009-03-16 22:03:20 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Media
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-08-15 17:27:41 +00:00
|
|
|
* Handler for Tiff images.
|
|
|
|
|
*
|
2009-03-16 22:03:20 +00:00
|
|
|
* @ingroup Media
|
|
|
|
|
*/
|
2011-06-17 03:37:59 +00:00
|
|
|
class TiffHandler extends ExifBitmapHandler {
|
2014-05-27 20:09:49 +00:00
|
|
|
const EXPENSIVE_SIZE_LIMIT = 10485760; // TIFF files over 10M are considered expensive to thumbnail
|
|
|
|
|
|
2009-03-16 22:03:20 +00:00
|
|
|
/**
|
|
|
|
|
* Conversion to PNG for inline display can be disabled here...
|
|
|
|
|
* Note scaling should work with ImageMagick, but may not with GD scaling.
|
2011-05-28 17:18:50 +00:00
|
|
|
*
|
2011-10-03 22:04:04 +00:00
|
|
|
* Files pulled from an another MediaWiki instance via ForeignAPIRepo /
|
|
|
|
|
* InstantCommons will have thumbnails managed from the remote instance,
|
|
|
|
|
* so we can skip this check.
|
|
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2011-05-28 17:18:50 +00:00
|
|
|
* @return bool
|
2009-03-16 22:03:20 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
public function canRender( $file ) {
|
2009-03-16 22:03:20 +00:00
|
|
|
global $wgTiffThumbnailType;
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2011-10-03 22:04:04 +00:00
|
|
|
return (bool)$wgTiffThumbnailType
|
2013-05-17 14:47:00 +00:00
|
|
|
|| $file->getRepo() instanceof ForeignAPIRepo;
|
2009-03-16 22:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Browsers don't support TIFF inline generally...
|
|
|
|
|
* For inline display, we need to convert to PNG.
|
2011-05-28 17:18:50 +00:00
|
|
|
*
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param File $file
|
2011-05-28 17:18:50 +00:00
|
|
|
* @return bool
|
2009-03-16 22:03:20 +00:00
|
|
|
*/
|
2016-02-23 23:47:02 +00:00
|
|
|
public function mustRender( $file ) {
|
2009-03-16 22:03:20 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-28 17:18:50 +00:00
|
|
|
/**
|
2013-12-05 19:27:27 +00:00
|
|
|
* @param string $ext
|
|
|
|
|
* @param string $mime
|
|
|
|
|
* @param array $params
|
2011-05-28 17:18:50 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2010-06-23 18:18:14 +00:00
|
|
|
function getThumbType( $ext, $mime, $params = null ) {
|
2009-03-16 22:03:20 +00:00
|
|
|
global $wgTiffThumbnailType;
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2009-03-16 22:03:20 +00:00
|
|
|
return $wgTiffThumbnailType;
|
|
|
|
|
}
|
2011-04-20 23:15:13 +00:00
|
|
|
|
2011-05-28 17:18:50 +00:00
|
|
|
/**
|
2016-09-19 01:39:59 +00:00
|
|
|
* @param File|FSFile $image
|
2012-10-07 23:35:26 +00:00
|
|
|
* @param string $filename
|
|
|
|
|
* @throws MWException
|
2011-05-28 17:18:50 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getMetadata( $image, $filename ) {
|
|
|
|
|
global $wgShowEXIF;
|
2016-09-19 01:39:59 +00:00
|
|
|
|
2011-08-21 17:16:57 +00:00
|
|
|
if ( $wgShowEXIF ) {
|
|
|
|
|
try {
|
|
|
|
|
$meta = BitmapMetadataHandler::Tiff( $filename );
|
|
|
|
|
if ( !is_array( $meta ) ) {
|
|
|
|
|
// This should never happen, but doesn't hurt to be paranoid.
|
2013-02-03 19:42:08 +00:00
|
|
|
throw new MWException( 'Metadata array is not an array' );
|
2011-08-21 17:16:57 +00:00
|
|
|
}
|
|
|
|
|
$meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2011-08-21 17:16:57 +00:00
|
|
|
return serialize( $meta );
|
2015-01-09 23:44:47 +00:00
|
|
|
} catch ( Exception $e ) {
|
2011-08-21 17:16:57 +00:00
|
|
|
// BitmapMetadataHandler throws an exception in certain exceptional
|
|
|
|
|
// cases like if file does not exist.
|
|
|
|
|
wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
|
2013-12-05 10:05:05 +00:00
|
|
|
|
2011-06-17 03:37:59 +00:00
|
|
|
return ExifBitmapHandler::BROKEN_FILE;
|
2011-05-28 17:18:50 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-27 20:09:49 +00:00
|
|
|
|
|
|
|
|
public function isExpensiveToThumbnail( $file ) {
|
|
|
|
|
return $file->getSize() > static::EXPENSIVE_SIZE_LIMIT;
|
|
|
|
|
}
|
2009-03-16 22:03:20 +00:00
|
|
|
}
|