jenkins-bot has submitted this change and it was merged. Change subject: Add 'source' parameter to API for getting original url ......................................................................
Add 'source' parameter to API for getting original url Bug: T94928 Change-Id: I3bb8fb39385d8d6aec2504f121c684205ea82067 --- M ApiQueryPageImages.php 1 file changed, 24 insertions(+), 14 deletions(-) Approvals: Ori.livneh: Looks good to me, approved jenkins-bot: Verified diff --git a/ApiQueryPageImages.php b/ApiQueryPageImages.php index 08146a0..e451346 100644 --- a/ApiQueryPageImages.php +++ b/ApiQueryPageImages.php @@ -89,25 +89,34 @@ */ protected function setResultValues( $prop, $pageId, $fileName, $size ) { $vals = array(); - if ( isset( $prop['thumbnail'] ) ) { + if ( isset( $prop['thumbnail'] ) || isset( $prop['source'] ) ) { $file = wfFindFile( $fileName ); - if ( $file ) { - $thumb = $file->transform( array( 'width' => $size, 'height' => $size ) ); - if ( $thumb && $thumb->getUrl() ) { - $vals['thumbnail'] = array( - 'source' => wfExpandUrl( $thumb->getUrl(), PROTO_CURRENT ), - // You can request a thumb 1000x larger than the original which will return a Thumb - // object that will lie about its size but have the original as an image. - // Therefore, sanitize image size. - 'width' => min( $thumb->getWidth(), $file->getWidth() ), - 'height' => min( $thumb->getHeight(), $file->getHeight() ), - ); + + if ( isset( $prop['thumbnail'] ) ) { + if ( $file ) { + $thumb = $file->transform( array( 'width' => $size, 'height' => $size ) ); + if ( $thumb && $thumb->getUrl() ) { + $vals['thumbnail'] = array( + 'source' => wfExpandUrl( $thumb->getUrl(), PROTO_CURRENT ), + // You can request a thumb 1000x larger than the original which will return a Thumb + // object that will lie about its size but have the original as an image. + // Therefore, sanitize image size. + 'width' => min( $thumb->getWidth(), $file->getWidth() ), + 'height' => min( $thumb->getHeight(), $file->getHeight() ), + ); + } } } + + if ( isset( $prop['source'] ) ) { + $vals['source'] = wfExpandUrl( $file->getUrl(), PROTO_CURRENT ); + } } + if ( isset( $prop['name'] ) ) { $vals['pageimage'] = $fileName; } + $this->getResult()->addValue( array( 'query', 'pages' ), $pageId, $vals ); } @@ -121,7 +130,7 @@ public function getAllowedParams() { return array( 'prop' => array( - ApiBase::PARAM_TYPE => array( 'thumbnail', 'name' ), + ApiBase::PARAM_TYPE => array( 'thumbnail', 'name', 'source' ), ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_DFLT => 'thumbnail|name', ), @@ -151,7 +160,8 @@ return array( 'prop' => array( 'What information to return', ' thumbnail - URL and dimensions of image associated with page, if any', - ' name - image title' + ' name - image title', + ' source - URL to the image original', ), 'thumbsize' => 'Maximum thumbnail dimension', 'limit' => 'Properties of how many pages to return', -- To view, visit https://gerrit.wikimedia.org/r/201613 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3bb8fb39385d8d6aec2504f121c684205ea82067 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/PageImages Gerrit-Branch: master Gerrit-Owner: Yuvipanda <yuvipa...@gmail.com> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: Prtksxna <psax...@wikimedia.org> Gerrit-Reviewer: Slaporte <stephen.lapo...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits