Index: trunk/phase3/includes/api/ApiQueryAllimages.php |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | |
48 | 48 | public function executeGenerator($resultPageSet) { |
49 | 49 | 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'); |
51 | 51 | |
52 | 52 | $this->run($resultPageSet); |
53 | 53 | } |
— | — | @@ -83,16 +83,12 @@ |
84 | 84 | |
85 | 85 | $this->addTables('image'); |
86 | 86 | |
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'])); |
97 | 93 | |
98 | 94 | $limit = $params['limit']; |
99 | 95 | $this->addOption('LIMIT', $limit+1); |
— | — | @@ -113,16 +109,22 @@ |
114 | 110 | |
115 | 111 | if (is_null($resultPageSet)) { |
116 | 112 | $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(); |
127 | 129 | $data[] = $item; |
128 | 130 | } else { |
129 | 131 | $data[] = Title::makeTitle( NS_IMAGE, $row->img_name ); |
— | — | @@ -140,8 +142,6 @@ |
141 | 143 | } |
142 | 144 | |
143 | 145 | public function getAllowedParams() { |
144 | | - global $wgRestrictionTypes, $wgRestrictionLevels; |
145 | | - |
146 | 146 | return array ( |
147 | 147 | 'from' => null, |
148 | 148 | 'prefix' => null, |
— | — | @@ -150,7 +150,7 @@ |
151 | 151 | ), |
152 | 152 | 'maxsize' => array ( |
153 | 153 | ApiBase :: PARAM_TYPE => 'integer', |
154 | | - ), |
| 154 | + ), |
155 | 155 | 'limit' => array ( |
156 | 156 | ApiBase :: PARAM_DFLT => 10, |
157 | 157 | ApiBase :: PARAM_TYPE => 'limit', |
— | — | @@ -167,6 +167,18 @@ |
168 | 168 | ), |
169 | 169 | 'sha1' => null, |
170 | 170 | '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 | + ) |
171 | 183 | ); |
172 | 184 | } |
173 | 185 | |
— | — | @@ -179,7 +191,8 @@ |
180 | 192 | 'maxsize' => 'Limit to images with at most this many bytes', |
181 | 193 | 'limit' => 'How many total pages to return.', |
182 | 194 | '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', |
184 | 197 | ); |
185 | 198 | } |
186 | 199 | |