Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -164,22 +164,16 @@ |
165 | 165 | $this->InstantiateModules($modules, 'list', $this->mQueryListModules); |
166 | 166 | $this->InstantiateModules($modules, 'meta', $this->mQueryMetaModules); |
167 | 167 | |
168 | | - // Modules may optimize data requests through the $this->getPageSet() object |
169 | | - // Execute all requested modules. |
170 | | - foreach ($modules as $module) { |
171 | | - $module->requestExtraData(); |
172 | | - } |
173 | | - |
174 | 168 | // |
175 | | - // Populate page information for the given pageSet |
176 | | - // |
177 | | - $this->mPageSet->execute(); |
178 | | - |
179 | | - // |
180 | 169 | // If given, execute generator to substitute user supplied data with generated data. |
181 | 170 | // |
182 | | - if (isset ($this->params['generator'])) |
183 | | - $this->executeGeneratorModule($this->params['generator']); |
| 171 | + if (isset ($this->params['generator'])) { |
| 172 | + $this->executeGeneratorModule($this->params['generator'], $modules); |
| 173 | + } else { |
| 174 | + // Append custom fields and populate page/revision information |
| 175 | + $this->addCustomFldsToPageSet($modules, $this->mPageSet); |
| 176 | + $this->mPageSet->execute(); |
| 177 | + } |
184 | 178 | |
185 | 179 | // |
186 | 180 | // Record page information (title, namespace, if exists, etc) |
— | — | @@ -195,6 +189,18 @@ |
196 | 190 | $module->profileOut(); |
197 | 191 | } |
198 | 192 | } |
| 193 | + |
| 194 | + /** |
| 195 | + * Query modules may optimize data requests through the $this->getPageSet() object |
| 196 | + * by adding extra fields from the page table. |
| 197 | + * This function will gather all the extra request fields from the modules. |
| 198 | + */ |
| 199 | + private function addCustomFldsToPageSet($modules, $pageSet) { |
| 200 | + // Query all requested modules. |
| 201 | + foreach ($modules as $module) { |
| 202 | + $module->requestExtraData($pageSet); |
| 203 | + } |
| 204 | + } |
199 | 205 | |
200 | 206 | /** |
201 | 207 | * Create instances of all modules requested by the client |
— | — | @@ -206,6 +212,10 @@ |
207 | 213 | $modules[] = new $moduleList[$moduleName] ($this, $moduleName); |
208 | 214 | } |
209 | 215 | |
| 216 | + /** |
| 217 | + * Appends an element for each page in the current pageSet with the most general |
| 218 | + * information (id, title), plus any title normalizations and missing title/pageids/revids. |
| 219 | + */ |
210 | 220 | private function outputGeneralPageInfo() { |
211 | 221 | |
212 | 222 | $pageSet = $this->getPageSet(); |
— | — | @@ -299,7 +309,10 @@ |
300 | 310 | } |
301 | 311 | } |
302 | 312 | |
303 | | - protected function executeGeneratorModule($generatorName) { |
| 313 | + /** |
| 314 | + * For generator mode, execute generator, and use its output as new pageSet |
| 315 | + */ |
| 316 | + protected function executeGeneratorModule($generatorName, $modules) { |
304 | 317 | |
305 | 318 | // Find class that implements requested generator |
306 | 319 | if (isset ($this->mQueryListModules[$generatorName])) { |
— | — | @@ -319,8 +332,14 @@ |
320 | 333 | $this->dieUsage("Module $generatorName cannot be used as a generator", "badgenerator"); |
321 | 334 | |
322 | 335 | $generator->setGeneratorMode(); |
323 | | - $generator->requestExtraData(); |
324 | 336 | |
| 337 | + // Add any additional fields modules may need |
| 338 | + $generator->requestExtraData($this->mPageSet); |
| 339 | + $this->addCustomFldsToPageSet($modules, $resultPageSet); |
| 340 | + |
| 341 | + // Populate page information with the original user input |
| 342 | + $this->mPageSet->execute(); |
| 343 | + |
325 | 344 | // populate resultPageSet with the generator output |
326 | 345 | $generator->profileIn(); |
327 | 346 | $generator->executeGenerator($resultPageSet); |
— | — | @@ -380,6 +399,9 @@ |
381 | 400 | return $msg; |
382 | 401 | } |
383 | 402 | |
| 403 | + /** |
| 404 | + * For all modules in $moduleList, generate help messages and join them together |
| 405 | + */ |
384 | 406 | private function makeHelpMsgHelper($moduleList, $paramName) { |
385 | 407 | |
386 | 408 | $moduleDscriptions = array (); |
Index: trunk/phase3/includes/api/ApiQueryBase.php |
— | — | @@ -139,9 +139,9 @@ |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * Override this method to request extra fields from the pageSet |
143 | | - * using $this->getPageSet()->requestField('fieldName') |
| 143 | + * using $pageSet->requestField('fieldName') |
144 | 144 | */ |
145 | | - public function requestExtraData() { |
| 145 | + public function requestExtraData($pageSet) { |
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
Index: trunk/phase3/includes/api/ApiQueryInfo.php |
— | — | @@ -39,8 +39,7 @@ |
40 | 40 | parent :: __construct($query, $moduleName); |
41 | 41 | } |
42 | 42 | |
43 | | - public function requestExtraData() { |
44 | | - $pageSet = $this->getPageSet(); |
| 43 | + public function requestExtraData($pageSet) { |
45 | 44 | $pageSet->requestField('page_is_redirect'); |
46 | 45 | $pageSet->requestField('page_is_new'); |
47 | 46 | $pageSet->requestField('page_counter'); |