(bug 13606) Added archivename to iiprop
[lhc/web/wiklou.git] / includes / api / ApiQueryImageInfo.php
index f0a9214..69cc3a9 100644 (file)
@@ -50,10 +50,11 @@ class ApiQueryImageInfo extends ApiQueryBase {
                $this->fld_size = isset($prop['size']);
                $this->fld_sha1 = isset($prop['sha1']);
                $this->fld_metadata = isset($prop['metadata']);
+               $this->fld_archivename = isset($prop['archivename']);
                
                if($params['urlheight'] != -1 && $params['urlwidth'] == -1)
                        $this->dieUsage("iiurlheight cannot be used without iiurlwidth", 'iiurlwidth');
-               $this->scale = $params['urlwidth'] != -1;
+               $this->scale = ($params['urlwidth'] != -1);
                $this->urlwidth = $params['urlwidth'];
                $this->urlheight = $params['urlheight'];
 
@@ -79,11 +80,18 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                        }
                                        
                                        // Now get the old revisions
-                                       if($params['limit'] > 1) {
-                                               $oldies = $img->getHistory($params['limit'] - 1, $params['start'], $params['end']);
-                                               if(!empty($oldies))
-                                                       foreach($oldies as $oldie)
-                                                               $data[] = $this->getInfo($oldie);
+                                       // Get one more to facilitate query-continue functionality
+                                       $count = count($data);
+                                       $oldies = $img->getHistory($params['limit'] - $count + 1, $params['start'], $params['end']);
+                                       foreach($oldies as $oldie) {
+                                               if(++$count > $params['limit']) {
+                                                       // We've reached the extra one which shows that there are additional pages to be had. Stop here...
+                                                       // Only set a query-continue if there was only one title
+                                                       if(count($pageIds[NS_IMAGE]) == 1)
+                                                               $this->setContinueEnumParameter('start', $oldie->getTimestamp());
+                                                       break;
+                                               }
+                                               $data[] = $this->getInfo($oldie);       
                                        }
                                }
 
@@ -112,30 +120,38 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                $vals['anon'] = '';
                }
                if($this->fld_size) {
-                       $vals['size'] = $f->getSize();
-                       $vals['width'] = $f->getWidth();
-                       $vals['height'] = $f->getHeight();
+                       $vals['size'] = intval($f->getSize());
+                       $vals['width'] = intval($f->getWidth());
+                       $vals['height'] = intval($f->getHeight());
                }
                if($this->fld_url) {
-                       if($this->scale) {
-                               $vals['url'] = $f->createThumb($this->urlwidth, $this->urlheight);
-                       } else {
-                               $vals['url'] = $f->getURL();
+                       if($this->scale && !$f->isOld()) {
+                               $thumb = $f->getThumbnail($this->urlwidth, $this->urlheight);
+                               if($thumb)
+                               {
+                                       $vals['thumburl'] = $thumb->getURL();
+                                       $vals['thumbwidth'] = $thumb->getWidth();
+                                       $vals['thumbheight'] = $thumb->getHeight();
+                               }
                        }
+                       $vals['url'] = $f->getURL();
                }
                if($this->fld_comment) 
                        $vals['comment'] = $f->getDescription();
                if($this->fld_sha1) 
-                       $vals['sha1'] = $f->getSha1();
+                       $vals['sha1'] = wfBaseConvert($f->getSha1(), 36, 16, 40);
                if($this->fld_metadata) {
                        $metadata = unserialize($f->getMetadata());
                        $vals['metadata'] = $metadata ? $metadata : null;
                        $this->getResult()->setIndexedTagName_recursive($vals['metadata'], 'meta');
                }
+               if($this->fld_archivename && $f->isOld())
+                       $vals['archivename'] = $f->getArchiveName();
+               
                return $vals;
        }
 
-       protected function getAllowedParams() {
+       public function getAllowedParams() {
                return array (
                        'prop' => array (
                                ApiBase :: PARAM_ISMULTI => true,
@@ -147,7 +163,8 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                        'url',
                                        'size',
                                        'sha1',
-                                       'metadata'
+                                       'metadata',
+                                       'archivename'
                                )
                        ),
                        'limit' => array(
@@ -174,7 +191,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                );
        }
 
-       protected function getParamDescription() {
+       public function getParamDescription() {
                return array (
                        'prop' => 'What image information to get.',
                        'limit' => 'How many image revisions to return',
@@ -185,7 +202,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                );
        }
 
-       protected function getDescription() {
+       public function getDescription() {
                return array (
                        'Returns image information and upload history'
                );