From: Catrope Date: Tue, 23 Apr 2013 03:46:15 +0000 (-0700) Subject: Allow iiurlheight to be used without iiurlwidth X-Git-Tag: 1.31.0-rc.0~19784^2 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=8457ee85910af1ca508bb3ca53e2b0cc94442142;p=lhc%2Fweb%2Fwiklou.git Allow iiurlheight to be used without iiurlwidth Wanting to get a thumbnail with only the height constrained is a reasonable use case, the only reason we don't support it in the API is because the backend doesn't support it directly. This is easy enough to emulate by setting the width to the full width of the image if only the height is specified. This makes the transform function use a bounding box of size w x h, and if w is the width of the original image that's equivalent to just bounding the height. Change-Id: I28c7c22ee91669469cbd9e7d25f09100933582de --- diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 850b43d158..7f0e8b2c59 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -98,6 +98,7 @@ production. apply the new LanguageLinks hook, and thus only consider language links stored in the database. * (bug 47219) Allow specifying change type of Wikipedia feed items +* prop=imageinfo now allows setting iiurlheight without setting iiurlwidth === Languages updated in 1.22=== diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index c36821b481..5ed9d38b5c 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -202,21 +202,20 @@ class ApiQueryImageInfo extends ApiQueryBase { public function getScale( $params ) { $p = $this->getModulePrefix(); - // Height and width. - if ( $params['urlheight'] != -1 && $params['urlwidth'] == -1 ) { - $this->dieUsage( "{$p}urlheight cannot be used without {$p}urlwidth", "{$p}urlwidth" ); - } - if ( $params['urlwidth'] != -1 ) { $scale = array(); $scale['width'] = $params['urlwidth']; $scale['height'] = $params['urlheight']; + } elseif ( $params['urlheight'] != -1 ) { + // Height is specified but width isn't + // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width + $scale = array(); + $scale['height'] = $params['urlheight']; } else { $scale = null; if ( $params['urlparam'] ) { $this->dieUsage( "{$p}urlparam requires {$p}urlwidth", "urlparam_no_width" ); } - return $scale; } return $scale; @@ -232,6 +231,12 @@ class ApiQueryImageInfo extends ApiQueryBase { * @return Array of parameters for transform. */ protected function mergeThumbParams( $image, $thumbParams, $otherParams ) { + + if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) { + // Populate the width with the image's width, so only the height restriction applies + $thumbParams['width'] = $image->getWidth(); + } + if ( !$otherParams ) { return $thumbParams; } @@ -257,8 +262,8 @@ class ApiQueryImageInfo extends ApiQueryBase { if ( isset( $paramList['width'] ) ) { if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) { - $this->dieUsage( "{$p}urlparam had width of {$paramList['width']} but " - . "{$p}urlwidth was {$thumbParams['width']}", "urlparam_urlwidth_mismatch" ); + $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) " + . "in favor of width value derived from {$p}urlwidth/{$p}urlheight ({$thumbParams['width']})" ); } } @@ -571,7 +576,7 @@ class ApiQueryImageInfo extends ApiQueryBase { 'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", 'For performance reasons if this option is used, ' . 'no more than ' . self::TRANSFORM_LIMIT . ' scaled images will be returned.' ), - 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth", + 'urlheight' => "Similar to {$p}urlwidth.", 'urlparam' => array( "A handler specific parameter string. For example, pdf's ", "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ), 'limit' => 'How many image revisions to return per image', @@ -718,8 +723,6 @@ class ApiQueryImageInfo extends ApiQueryBase { array( 'code' => "{$p}urlwidth", 'info' => "{$p}urlheight cannot be used without {$p}urlwidth" ), array( 'code' => 'urlparam', 'info' => "Invalid value for {$p}urlparam" ), array( 'code' => 'urlparam_no_width', 'info' => "{$p}urlparam requires {$p}urlwidth" ), - array( 'code' => 'urlparam_urlwidth_mismatch', 'info' => "The width set in {$p}urlparm doesn't " . - "match the one in {$p}urlwidth" ), ) ); }