From 93c095475049c1ed41b1578412951de39446ca0c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Tue, 27 May 2014 20:09:49 +0000 Subject: [PATCH] Allow media handlers to mark files as expensive Allows media handlers to signal that thumbnail generation for this file is expensive and should be throttled more agressively. For now this is only done for large TIFF files. Bug: 65691 Change-Id: I01b34a1d46745649f179fdee435a8cfb19c5474e --- includes/filerepo/file/File.php | 9 +++++++++ includes/media/MediaHandler.php | 9 +++++++++ includes/media/Tiff.php | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index a45cd72395..1103e38273 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -2018,4 +2018,13 @@ abstract class File { throw new MWException( "A Title object is not set for this File.\n" ); } } + + /** + * True if creating thumbnails from the file is large or otherwise resource-intensive. + * @return bool + */ + public function isExpensiveToThumbnail() { + $handler = $this->getHandler(); + return $handler ? $handler->isExpensiveToThumbnail( $this ) : false; + } } diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php index f131af4d67..b9a8ab7e3a 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -812,4 +812,13 @@ abstract class MediaHandler { public function getLength( $file ) { return 0.0; } + + /** + * True if creating thumbnails from the file is large or otherwise resource-intensive. + * @param File $file + * @return bool + */ + public function isExpensiveToThumbnail( $file ) { + return false; + } } diff --git a/includes/media/Tiff.php b/includes/media/Tiff.php index 6964170198..bea6cab365 100644 --- a/includes/media/Tiff.php +++ b/includes/media/Tiff.php @@ -27,6 +27,8 @@ * @ingroup Media */ class TiffHandler extends ExifBitmapHandler { + const EXPENSIVE_SIZE_LIMIT = 10485760; // TIFF files over 10M are considered expensive to thumbnail + /** * Conversion to PNG for inline display can be disabled here... * Note scaling should work with ImageMagick, but may not with GD scaling. @@ -97,4 +99,8 @@ class TiffHandler extends ExifBitmapHandler { return ''; } } + + public function isExpensiveToThumbnail( $file ) { + return $file->getSize() > static::EXPENSIVE_SIZE_LIMIT; + } } -- 2.20.1