Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/202056

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
(cherry picked from commit c4837a8eaf2fbb3ed7d00cde6a70ebfe721e2ac4)
---
M ApiQueryPageImages.php
1 file changed, 24 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages 
refs/changes/56/202056/1

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/202056
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3bb8fb39385d8d6aec2504f121c684205ea82067
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: wmf/1.25wmf23
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Yuvipanda <yuvipa...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to