API: Adding thumbnailing support to prop=imageinfo
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 18 Jan 2008 20:17:26 +0000 (20:17 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 18 Jan 2008 20:17:26 +0000 (20:17 +0000)
RELEASE-NOTES
includes/api/ApiQueryImageInfo.php

index a3593b9..e560cab 100644 (file)
@@ -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 ===
 
index 778c5c6..b52062d 100644 (file)
@@ -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',
                );
        }