Mholloway has uploaded a new change for review. https://gerrit.wikimedia.org/r/325066
Change subject: API: Add thumbwidth property parameter to restrict size by width only ...................................................................... API: Add thumbwidth property parameter to restrict size by width only This will make the width of the resulting thumbnail much more predictable, with at least two benefits: (1) it will likely look better on mobile devices, where we're much more concerned about width than height; (2) it will more likely fall within a pregenerated thumb width bucket, for WMF wiki API consumers. Bug: T152254 Change-Id: If011dd06bba7ac605e25f937589af6673878aa23 --- M includes/ApiQueryPageImages.php 1 file changed, 13 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages refs/changes/66/325066/1 diff --git a/includes/ApiQueryPageImages.php b/includes/ApiQueryPageImages.php index 7c8ae52..525b885 100644 --- a/includes/ApiQueryPageImages.php +++ b/includes/ApiQueryPageImages.php @@ -119,7 +119,12 @@ } } - $size = $params['thumbsize']; + if ( isset ( $params['thumbwidth'] ) ) { + $size = $params['thumbwidth']; + } else { + $size = $params['thumbsize']; + } + // Extract page images from the page_props table if ( count( $titles ) > 0 ) { $this->addTables( 'page_props' ); @@ -140,7 +145,7 @@ foreach ( $buffer as $pageId => $row ) { $fileName = $row->pp_value; - $this->setResultValues( $prop, $pageId, $fileName, $size ); + $this->setResultValues( $prop, $pageId, $fileName, $size, isset( $params['thumbwidth'] ) ); } } // End page props image extraction @@ -182,13 +187,13 @@ * @param string $fileName The name of the file to transform * @param int $size The thumbsize value from the API request */ - protected function setResultValues( array $prop, $pageId, $fileName, $size ) { + protected function setResultValues( array $prop, $pageId, $fileName, $size, $restrictByWidthOnly = false ) { $vals = []; if ( isset( $prop['thumbnail'] ) || isset( $prop['original'] ) ) { $file = wfFindFile( $fileName ); if ( $file ) { if ( isset( $prop['thumbnail'] ) ) { - $thumb = $file->transform( [ 'width' => $size, 'height' => $size ] ); + $thumb = $file->transform( $restrictByWidthOnly ? [ 'width' => $size ] : [ 'width' => $size, 'height' => $size ] ); if ( $thumb && $thumb->getUrl() ) { // You can request a thumb 1000x larger than the original // which (in case of bitmap original) will return a Thumb object @@ -240,6 +245,9 @@ ApiBase::PARAM_TYPE => 'integer', ApiBase::PARAM_DFLT => 50, ], + 'thumbwidth' => [ + ApiBase::PARAM_TYPE => 'integer' + ], 'limit' => [ ApiBase::PARAM_DFLT => 1, ApiBase::PARAM_TYPE => 'limit', @@ -276,6 +284,7 @@ ' original - URL to the image original', ], 'thumbsize' => 'Maximum thumbnail dimension', + 'thumbwidth' => 'Maximum thumbnail width (overrides thumbsize, if both are set)', 'limit' => 'Properties of how many pages to return', 'continue' => 'When more results are available, use this to continue', ]; -- To view, visit https://gerrit.wikimedia.org/r/325066 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If011dd06bba7ac605e25f937589af6673878aa23 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PageImages Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits