* @since 1.24 Moved from thumb.php to GlobalFunctions in 1.25
*/
function wfThumbIsStandard( File $file, array $params ) {
- global $wgThumbLimits, $wgImageLimits;
+ global $wgThumbLimits, $wgImageLimits, $wgResponsiveImages;
+
+ $multipliers = array( 1 );
+ if ( $wgResponsiveImages ) {
+ // These available sizes are hardcoded currently elsewhere in MediaWiki.
+ // @see Linker::processResponsiveImages
+ $multipliers[] = 1.5;
+ $multipliers[] = 2;
+ }
$handler = $file->getHandler();
if ( !$handler || !isset( $params['width'] ) ) {
$basicParams['page'] = $params['page'];
}
+ $thumbLimits = array();
+ $imageLimits = array();
+ // Expand limits to account for multipliers
+ foreach ( $multipliers as $multiplier ) {
+ $thumbLimits = array_merge( $thumbLimits, array_map(
+ function ( $width ) use ( $multiplier ) {
+ return round( $width * $multiplier );
+ }, $wgThumbLimits )
+ );
+ $imageLimits = array_merge( $imageLimits, array_map(
+ function ( $pair ) use ( $multiplier ) {
+ return array(
+ round( $pair[0] * $multiplier ),
+ round( $pair[1] * $multiplier ),
+ );
+ }, $wgImageLimits )
+ );
+ }
+
// Check if the width matches one of $wgThumbLimits
- if ( in_array( $params['width'], $wgThumbLimits ) ) {
+ if ( in_array( $params['width'], $thumbLimits ) ) {
$normalParams = $basicParams + array( 'width' => $params['width'] );
// Append any default values to the map (e.g. "lossy", "lossless", ...)
$handler->normaliseParams( $file, $normalParams );
} else {
// If not, then check if the width matchs one of $wgImageLimits
$match = false;
- foreach ( $wgImageLimits as $pair ) {
+ foreach ( $imageLimits as $pair ) {
$normalParams = $basicParams + array( 'width' => $pair[0], 'height' => $pair[1] );
// Decide whether the thumbnail should be scaled on width or height.
// Also append any default values to the map (e.g. "lossy", "lossless", ...)
$this->setMwGlobals( array(
'wgThumbLimits' => array(
100,
- 400
+ 401
),
'wgImageLimits' => array(
array( 300, 225 ),
array(
'Standard thumb width',
true,
- array( 'width' => 400 ),
+ array( 'width' => 401 ),
+ ),
+ // wfThumbIsStandard should match Linker::processResponsiveImages
+ // in its rounding behaviour.
+ array(
+ 'Standard thumb width (HiDPI 1.5x) - incorrect rounding',
+ false,
+ array( 'width' => 601 ),
+ ),
+ array(
+ 'Standard thumb width (HiDPI 1.5x)',
+ true,
+ array( 'width' => 602 ),
+ ),
+ array(
+ 'Standard thumb width (HiDPI 2x)',
+ true,
+ array( 'width' => 802 ),
),
array(
'Non-standard thumb width',