Allow media handlers to mark files as expensive
authorGergő Tisza <tgr.huwiki@gmail.com>
Tue, 27 May 2014 20:09:49 +0000 (20:09 +0000)
committerGergő Tisza <tgr.huwiki@gmail.com>
Wed, 28 May 2014 20:24:31 +0000 (20:24 +0000)
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
includes/media/MediaHandler.php
includes/media/Tiff.php

index a45cd72..1103e38 100644 (file)
@@ -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;
+       }
 }
index f131af4..b9a8ab7 100644 (file)
@@ -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;
+       }
 }
index 6964170..bea6cab 100644 (file)
@@ -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;
+       }
 }