diff options
author | Aaron Schulz <aschulz@wikimedia.org> | 2014-04-29 14:39:05 -0700 |
---|---|---|
committer | Aaron Schulz <aschulz@wikimedia.org> | 2014-04-29 14:39:05 -0700 |
commit | b0de7c7c60eb2f8464d6b6eb653331bdf80e34b0 (patch) | |
tree | e0984f3f83d047d0b9ac185729eb4f4f06d78e72 /thumb.php | |
parent | 00c13cb4d5f978a57275e74752a4be734675be81 (diff) | |
download | mediawikicore-b0de7c7c60eb2f8464d6b6eb653331bdf80e34b0.tar.gz mediawikicore-b0de7c7c60eb2f8464d6b6eb653331bdf80e34b0.zip |
Tweaked wfThumbIsStandard() to recognize handler-specific default parameters
* Now thumbnails with default lossy/lossless values will still count as "standard",
for example. This makes use of the file media handler.
Change-Id: Ia69301dfbf85bb26a17f8eee0939d690021343ec
Diffstat (limited to 'thumb.php')
-rw-r--r-- | thumb.php | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/thumb.php b/thumb.php index a5bdc5bb25cc..c5da918e0864 100644 --- a/thumb.php +++ b/thumb.php @@ -429,16 +429,13 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName ) { * of possible files with standard parameters is far less than that of all * possible combinations; rate-limiting for them can thus be more generious. * - * @param File $img + * @param File $file * @param array $params * @return bool */ -function wfThumbIsStandard( File $img, array $params ) { +function wfThumbIsStandard( File $file, array $params ) { global $wgThumbLimits, $wgImageLimits; - // @TODO: use polymorphism with media handler here - if ( array_diff( array_keys( $params ), array( 'width', 'page' ) ) ) { - return false; // extra parameters present - } + if ( isset( $params['width'] ) ) { $widths = $wgThumbLimits; foreach ( $wgImageLimits as $pair ) { @@ -448,6 +445,24 @@ function wfThumbIsStandard( File $img, array $params ) { return false; } } + + $handler = $file->getHandler(); + if ( $handler ) { + // Standard thumbnails use a standard width and any page number + $normalParams = array( 'width' => $params['width'] ); + if ( isset( $params['page'] ) ) { + $normalParams['page'] = $params['page']; + } + // Append any default values to the map (e.g. "lossy", "lossless", "seek"...) + $handler->normaliseParams( $file, $normalParams ); + // Check that the given values for non-page, non-width, params are just defaults + foreach ( $params as $key => $value ) { + if ( !isset( $normalParams[$key] ) || $normalParams[$key] !== $value ) { + return false; + } + } + } + return true; } |