r32071 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32070‎ | r32071 | r32072 >
Date:18:51, 17 March 2008
Author:catrope
Status:old
Tags:
Comment:
API: Adding aiprop parameter to list=allimages, some cleanup
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllimages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllimages.php
@@ -46,7 +46,7 @@
4747
4848 public function executeGenerator($resultPageSet) {
4949 if ($resultPageSet->isResolvingRedirects())
50 - $this->dieUsage('Use "gaifilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params');
 50+ $this->dieUsage('Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator', 'params');
5151
5252 $this->run($resultPageSet);
5353 }
@@ -83,16 +83,12 @@
8484
8585 $this->addTables('image');
8686
87 - $this->addFields(array (
88 - 'img_name',
89 - 'img_size',
90 - 'img_width',
91 - 'img_height',
92 - 'img_major_mime',
93 - 'img_minor_mime',
94 - 'img_timestamp',
95 - 'img_sha1',
96 - ));
 87+ $prop = array_flip($params['prop']);
 88+ $this->addFields('img_name');
 89+ $this->addFieldsIf('img_size', isset($prop['size']));
 90+ $this->addFieldsIf(array('img_width', 'img_height'), isset($prop['dimensions']));
 91+ $this->addFieldsIf(array('img_major_mime', 'img_minor_mime'), isset($prop['mime']));
 92+ $this->addFieldsIf('img_timestamp', isset($prop['timestamp']));
9793
9894 $limit = $params['limit'];
9995 $this->addOption('LIMIT', $limit+1);
@@ -113,16 +109,22 @@
114110
115111 if (is_null($resultPageSet)) {
116112 $file = wfLocalFile( $row->img_name );
117 - $item = array(
118 - 'name' => $row->img_name,
119 - 'size' => $file->getSize(),
120 - 'width' => $file->getWidth(),
121 - 'height' => $file->getHeight(),
122 - 'mime' => $row->img_major_mime . '/' . $row->img_minor_mime,
123 - 'sha1' => wfBaseConvert( $file->getSha1(), 36, 16, 31 ),
124 - 'timestamp' => wfTimestamp(TS_ISO_8601, $file->getTimestamp()),
125 - 'url' => $file->getFullUrl()
126 - );
 113+ $item['name'] = $row->img_name;
 114+ if(isset($prop['size']))
 115+ $item['size'] = $file->getSize();
 116+ if(isset($prop['dimensions']))
 117+ {
 118+ $item['width'] = $file->getWidth();
 119+ $item['height'] = $file->getHeight();
 120+ }
 121+ if(isset($prop['mime']))
 122+ $item['mime'] = $row->img_major_mime . '/' . $row->img_minor_mime;
 123+ if(isset($prop['sha1']))
 124+ $item['sha1'] = wfBaseConvert($file->getSha1(), 36, 16, 31);
 125+ if(isset($prop['timestamp']))
 126+ $item['timestamp'] = wfTimestamp(TS_ISO_8601, $file->getTimestamp());
 127+ if(isset($prop['url']))
 128+ $item['url'] = $file->getUrl();
127129 $data[] = $item;
128130 } else {
129131 $data[] = Title::makeTitle( NS_IMAGE, $row->img_name );
@@ -140,8 +142,6 @@
141143 }
142144
143145 public function getAllowedParams() {
144 - global $wgRestrictionTypes, $wgRestrictionLevels;
145 -
146146 return array (
147147 'from' => null,
148148 'prefix' => null,
@@ -150,7 +150,7 @@
151151 ),
152152 'maxsize' => array (
153153 ApiBase :: PARAM_TYPE => 'integer',
154 - ),
 154+ ),
155155 'limit' => array (
156156 ApiBase :: PARAM_DFLT => 10,
157157 ApiBase :: PARAM_TYPE => 'limit',
@@ -167,6 +167,18 @@
168168 ),
169169 'sha1' => null,
170170 'sha1base36' => null,
 171+ 'prop' => array (
 172+ ApiBase :: PARAM_TYPE => array(
 173+ 'timestamp',
 174+ 'url',
 175+ 'size',
 176+ 'dimensions',
 177+ 'mime',
 178+ 'sha1'
 179+ ),
 180+ ApiBase :: PARAM_DFLT => 'timestamp|url',
 181+ ApiBase :: PARAM_ISMULTI => true
 182+ )
171183 );
172184 }
173185
@@ -179,7 +191,8 @@
180192 'maxsize' => 'Limit to images with at most this many bytes',
181193 'limit' => 'How many total pages to return.',
182194 'sha1' => 'SHA1 hash of image',
183 - 'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki)'
 195+ 'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki)',
 196+ 'prop' => 'Which properties to get',
184197 );
185198 }
186199

Status & tagging log