From f0f08ff3f286cf0ecd6833d422533655bb535a55 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 18 Jan 2008 20:17:26 +0000 Subject: [PATCH] API: Adding thumbnailing support to prop=imageinfo --- RELEASE-NOTES | 1 + includes/api/ApiQueryImageInfo.php | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a3593b92bf..e560cab4c5 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -440,6 +440,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * Added action=logout * Added cascade flag to prop=info&inprop=protections * Added wlshow parameter to list=watchlist, similar to rcshow (list=recentchanges) +* Added support for image thumbnailing to prop=imageinfo === Languages updated in 1.12 === diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 778c5c694a..b52062d0f1 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -52,6 +52,10 @@ class ApiQueryImageInfo extends ApiQueryBase { $fld_size = isset($prop['size']); $fld_sha1 = isset($prop['sha1']); $fld_metadata = isset($prop['metadata']); + + if($params['urlheight'] != -1 && $params['urlwidth'] == -1) + $this->dieUsage("iiurlheight cannot be used without iiurlwidth", 'iiurlwidth'); + $scale = $params['urlwidth'] != -1; $pageIds = $this->getPageSet()->getAllTitlesByNamespace(); if (!empty($pageIds[NS_IMAGE])) { @@ -91,8 +95,13 @@ class ApiQueryImageInfo extends ApiQueryBase { $vals['width'] = intval($row["{$prefix}_width"]); $vals['height'] = intval($row["{$prefix}_height"]); } - if ($fld_url) - $vals['url'] = $isCur ? $img->getURL() : $img->getArchiveUrl($row["oi_archive_name"]); + if ($fld_url) { + if($scale && $isCur) { + $vals['url'] = $img->createThumb($params['urlwidth'], $params['urlheight']); + } else { + $vals['url'] = $isCur ? $img->getURL() : $img->getArchiveUrl($row["oi_archive_name"]); + } + } if ($fld_comment) $vals['comment'] = $row["{$prefix}_description"]; @@ -142,6 +151,14 @@ class ApiQueryImageInfo extends ApiQueryBase { ) ), 'history' => false, + 'urlwidth' => array( + ApiBase :: PARAM_TYPE => 'integer', + ApiBase :: PARAM_DFLT => -1 + ), + 'urlheight' => array( + ApiBase :: PARAM_TYPE => 'integer', + ApiBase :: PARAM_DFLT => -1 + ) ); } @@ -149,6 +166,8 @@ class ApiQueryImageInfo extends ApiQueryBase { return array ( 'prop' => 'What image information to get.', 'history' => 'Include upload history', + 'urlwidth' => 'If iiprop=url is set, a URL to an image scaled to this width will be returned. Only the current version of the image can be scaled.', + 'urlheight' => 'Similar to iiurlwidth. Cannot be used without iiurlwidth', ); } -- 2.20.1