merging latest master
[lhc/web/wiklou.git] / includes / api / ApiQuery.php
1 <?php
2 /**
3 *
4 *
5 * Created on Sep 7, 2006
6 *
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 */
26
27 /**
28 * This is the main query class. It behaves similar to ApiMain: based on the
29 * parameters given, it will create a list of titles to work on (an ApiPageSet
30 * object), instantiate and execute various property/list/meta modules, and
31 * assemble all resulting data into a single ApiResult object.
32 *
33 * In generator mode, a generator will be executed first to populate a second
34 * ApiPageSet object, and that object will be used for all subsequent modules.
35 *
36 * @ingroup API
37 */
38 class ApiQuery extends ApiBase {
39
40 private $mPropModuleNames, $mListModuleNames, $mMetaModuleNames;
41
42 /**
43 * @var ApiPageSet
44 */
45 private $mPageSet;
46
47 private $params, $redirects, $convertTitles, $iwUrl;
48
49 private $mQueryPropModules = array(
50 'info' => 'ApiQueryInfo',
51 'revisions' => 'ApiQueryRevisions',
52 'links' => 'ApiQueryLinks',
53 'iwlinks' => 'ApiQueryIWLinks',
54 'langlinks' => 'ApiQueryLangLinks',
55 'images' => 'ApiQueryImages',
56 'imageinfo' => 'ApiQueryImageInfo',
57 'stashimageinfo' => 'ApiQueryStashImageInfo',
58 'templates' => 'ApiQueryLinks',
59 'categories' => 'ApiQueryCategories',
60 'extlinks' => 'ApiQueryExternalLinks',
61 'categoryinfo' => 'ApiQueryCategoryInfo',
62 'duplicatefiles' => 'ApiQueryDuplicateFiles',
63 'pageprops' => 'ApiQueryPageProps',
64 );
65
66 private $mQueryListModules = array(
67 'allimages' => 'ApiQueryAllImages',
68 'allpages' => 'ApiQueryAllPages',
69 'alllinks' => 'ApiQueryAllLinks',
70 'allcategories' => 'ApiQueryAllCategories',
71 'allusers' => 'ApiQueryAllUsers',
72 'backlinks' => 'ApiQueryBacklinks',
73 'blocks' => 'ApiQueryBlocks',
74 'categorymembers' => 'ApiQueryCategoryMembers',
75 'deletedrevs' => 'ApiQueryDeletedrevs',
76 'embeddedin' => 'ApiQueryBacklinks',
77 'filearchive' => 'ApiQueryFilearchive',
78 'imageusage' => 'ApiQueryBacklinks',
79 'iwbacklinks' => 'ApiQueryIWBacklinks',
80 'langbacklinks' => 'ApiQueryLangBacklinks',
81 'logevents' => 'ApiQueryLogEvents',
82 'recentchanges' => 'ApiQueryRecentChanges',
83 'search' => 'ApiQuerySearch',
84 'tags' => 'ApiQueryTags',
85 'usercontribs' => 'ApiQueryContributions',
86 'watchlist' => 'ApiQueryWatchlist',
87 'watchlistraw' => 'ApiQueryWatchlistRaw',
88 'exturlusage' => 'ApiQueryExtLinksUsage',
89 'users' => 'ApiQueryUsers',
90 'random' => 'ApiQueryRandom',
91 'protectedtitles' => 'ApiQueryProtectedTitles',
92 'querypage' => 'ApiQueryQueryPage',
93 );
94
95 private $mQueryMetaModules = array(
96 'siteinfo' => 'ApiQuerySiteinfo',
97 'userinfo' => 'ApiQueryUserInfo',
98 'allmessages' => 'ApiQueryAllMessages',
99 );
100
101 private $mSlaveDB = null;
102 private $mNamedDB = array();
103
104 protected $mAllowedGenerators = array();
105
106 /**
107 * @param $main ApiMain
108 * @param $action string
109 */
110 public function __construct( $main, $action ) {
111 parent::__construct( $main, $action );
112
113 // Allow custom modules to be added in LocalSettings.php
114 global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules;
115 self::appendUserModules( $this->mQueryPropModules, $wgAPIPropModules );
116 self::appendUserModules( $this->mQueryListModules, $wgAPIListModules );
117 self::appendUserModules( $this->mQueryMetaModules, $wgAPIMetaModules );
118
119 $this->mPropModuleNames = array_keys( $this->mQueryPropModules );
120 $this->mListModuleNames = array_keys( $this->mQueryListModules );
121 $this->mMetaModuleNames = array_keys( $this->mQueryMetaModules );
122
123 $this->makeGeneratorList( $this->mQueryPropModules );
124 $this->makeGeneratorList( $this->mQueryListModules );
125 }
126
127 /**
128 * Helper function to append any add-in modules to the list
129 * @param $modules array Module array
130 * @param $newModules array Module array to add to $modules
131 */
132 private static function appendUserModules( &$modules, $newModules ) {
133 if ( is_array( $newModules ) ) {
134 foreach ( $newModules as $moduleName => $moduleClass ) {
135 $modules[$moduleName] = $moduleClass;
136 }
137 }
138 }
139
140 /**
141 * Gets a default slave database connection object
142 * @return DatabaseBase
143 */
144 public function getDB() {
145 if ( !isset( $this->mSlaveDB ) ) {
146 $this->profileDBIn();
147 $this->mSlaveDB = wfGetDB( DB_SLAVE, 'api' );
148 $this->profileDBOut();
149 }
150 return $this->mSlaveDB;
151 }
152
153 /**
154 * Get the query database connection with the given name.
155 * If no such connection has been requested before, it will be created.
156 * Subsequent calls with the same $name will return the same connection
157 * as the first, regardless of the values of $db and $groups
158 * @param $name string Name to assign to the database connection
159 * @param $db int One of the DB_* constants
160 * @param $groups array Query groups
161 * @return DatabaseBase
162 */
163 public function getNamedDB( $name, $db, $groups ) {
164 if ( !array_key_exists( $name, $this->mNamedDB ) ) {
165 $this->profileDBIn();
166 $this->mNamedDB[$name] = wfGetDB( $db, $groups );
167 $this->profileDBOut();
168 }
169 return $this->mNamedDB[$name];
170 }
171
172 /**
173 * Gets the set of pages the user has requested (or generated)
174 * @return ApiPageSet
175 */
176 public function getPageSet() {
177 return $this->mPageSet;
178 }
179
180 /**
181 * Get the array mapping module names to class names
182 * @return array array(modulename => classname)
183 */
184 function getModules() {
185 return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
186 }
187
188 /**
189 * Get whether the specified module is a prop, list or a meta query module
190 * @param $moduleName string Name of the module to find type for
191 * @return mixed string or null
192 */
193 function getModuleType( $moduleName ) {
194 if ( isset( $this->mQueryPropModules[$moduleName] ) ) {
195 return 'prop';
196 }
197
198 if ( isset( $this->mQueryListModules[$moduleName] ) ) {
199 return 'list';
200 }
201
202 if ( isset( $this->mQueryMetaModules[$moduleName] ) ) {
203 return 'meta';
204 }
205
206 return null;
207 }
208
209 /**
210 * @return ApiFormatRaw|null
211 */
212 public function getCustomPrinter() {
213 // If &exportnowrap is set, use the raw formatter
214 if ( $this->getParameter( 'export' ) &&
215 $this->getParameter( 'exportnowrap' ) )
216 {
217 return new ApiFormatRaw( $this->getMain(),
218 $this->getMain()->createPrinterByName( 'xml' ) );
219 } else {
220 return null;
221 }
222 }
223
224 /**
225 * Query execution happens in the following steps:
226 * #1 Create a PageSet object with any pages requested by the user
227 * #2 If using a generator, execute it to get a new ApiPageSet object
228 * #3 Instantiate all requested modules.
229 * This way the PageSet object will know what shared data is required,
230 * and minimize DB calls.
231 * #4 Output all normalization and redirect resolution information
232 * #5 Execute all requested modules
233 */
234 public function execute() {
235 $this->params = $this->extractRequestParams();
236 $this->redirects = $this->params['redirects'];
237 $this->convertTitles = $this->params['converttitles'];
238 $this->iwUrl = $this->params['iwurl'];
239
240 // Create PageSet
241 $this->mPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
242
243 // Instantiate requested modules
244 $modules = array();
245 $this->instantiateModules( $modules, 'prop', $this->mQueryPropModules );
246 $this->instantiateModules( $modules, 'list', $this->mQueryListModules );
247 $this->instantiateModules( $modules, 'meta', $this->mQueryMetaModules );
248
249 $cacheMode = 'public';
250
251 // If given, execute generator to substitute user supplied data with generated data.
252 if ( isset( $this->params['generator'] ) ) {
253 $generator = $this->newGenerator( $this->params['generator'] );
254 $params = $generator->extractRequestParams();
255 $cacheMode = $this->mergeCacheMode( $cacheMode,
256 $generator->getCacheMode( $params ) );
257 $this->executeGeneratorModule( $generator, $modules );
258 } else {
259 // Append custom fields and populate page/revision information
260 $this->addCustomFldsToPageSet( $modules, $this->mPageSet );
261 $this->mPageSet->execute();
262 }
263
264 // Record page information (title, namespace, if exists, etc)
265 $this->outputGeneralPageInfo();
266
267 // Execute all requested modules.
268 /**
269 * @var $module ApiQueryBase
270 */
271 foreach ( $modules as $module ) {
272 $params = $module->extractRequestParams();
273 $cacheMode = $this->mergeCacheMode(
274 $cacheMode, $module->getCacheMode( $params ) );
275 $module->profileIn();
276 $module->execute();
277 wfRunHooks( 'APIQueryAfterExecute', array( &$module ) );
278 $module->profileOut();
279 }
280
281 // Set the cache mode
282 $this->getMain()->setCacheMode( $cacheMode );
283 }
284
285 /**
286 * Update a cache mode string, applying the cache mode of a new module to it.
287 * The cache mode may increase in the level of privacy, but public modules
288 * added to private data do not decrease the level of privacy.
289 *
290 * @param $cacheMode string
291 * @param $modCacheMode string
292 * @return string
293 */
294 protected function mergeCacheMode( $cacheMode, $modCacheMode ) {
295 if ( $modCacheMode === 'anon-public-user-private' ) {
296 if ( $cacheMode !== 'private' ) {
297 $cacheMode = 'anon-public-user-private';
298 }
299 } elseif ( $modCacheMode === 'public' ) {
300 // do nothing, if it's public already it will stay public
301 } else { // private
302 $cacheMode = 'private';
303 }
304 return $cacheMode;
305 }
306
307 /**
308 * Query modules may optimize data requests through the $this->getPageSet() object
309 * by adding extra fields from the page table.
310 * This function will gather all the extra request fields from the modules.
311 * @param $modules array of module objects
312 * @param $pageSet ApiPageSet
313 */
314 private function addCustomFldsToPageSet( $modules, $pageSet ) {
315 // Query all requested modules.
316 /**
317 * @var $module ApiQueryBase
318 */
319 foreach ( $modules as $module ) {
320 $module->requestExtraData( $pageSet );
321 }
322 }
323
324 /**
325 * Create instances of all modules requested by the client
326 * @param $modules Array to append instantiated modules to
327 * @param $param string Parameter name to read modules from
328 * @param $moduleList Array array(modulename => classname)
329 */
330 private function instantiateModules( &$modules, $param, $moduleList ) {
331 if ( isset( $this->params[$param] ) ) {
332 foreach ( $this->params[$param] as $moduleName ) {
333 $modules[] = new $moduleList[$moduleName] ( $this, $moduleName );
334 }
335 }
336 }
337
338 /**
339 * Appends an element for each page in the current pageSet with the
340 * most general information (id, title), plus any title normalizations
341 * and missing or invalid title/pageids/revids.
342 */
343 private function outputGeneralPageInfo() {
344 $pageSet = $this->getPageSet();
345 $result = $this->getResult();
346
347 // We don't check for a full result set here because we can't be adding
348 // more than 380K. The maximum revision size is in the megabyte range,
349 // and the maximum result size must be even higher than that.
350
351 // Title normalizations
352 $normValues = array();
353 foreach ( $pageSet->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
354 $normValues[] = array(
355 'from' => $rawTitleStr,
356 'to' => $titleStr
357 );
358 }
359
360 if ( count( $normValues ) ) {
361 $result->setIndexedTagName( $normValues, 'n' );
362 $result->addValue( 'query', 'normalized', $normValues );
363 }
364
365 // Title conversions
366 $convValues = array();
367 foreach ( $pageSet->getConvertedTitles() as $rawTitleStr => $titleStr ) {
368 $convValues[] = array(
369 'from' => $rawTitleStr,
370 'to' => $titleStr
371 );
372 }
373
374 if ( count( $convValues ) ) {
375 $result->setIndexedTagName( $convValues, 'c' );
376 $result->addValue( 'query', 'converted', $convValues );
377 }
378
379 // Interwiki titles
380 $intrwValues = array();
381 foreach ( $pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
382 $item = array(
383 'title' => $rawTitleStr,
384 'iw' => $interwikiStr,
385 );
386 if ( $this->iwUrl ) {
387 $title = Title::newFromText( $rawTitleStr );
388 $item['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
389 }
390 $intrwValues[] = $item;
391 }
392
393 if ( count( $intrwValues ) ) {
394 $result->setIndexedTagName( $intrwValues, 'i' );
395 $result->addValue( 'query', 'interwiki', $intrwValues );
396 }
397
398 // Show redirect information
399 $redirValues = array();
400 /**
401 * @var $titleTo Title
402 */
403 foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleTo ) {
404 $r = array(
405 'from' => strval( $titleStrFrom ),
406 'to' => $titleTo->getPrefixedText(),
407 );
408 if ( $titleTo->getFragment() !== '' ) {
409 $r['tofragment'] = $titleTo->getFragment();
410 }
411 $redirValues[] = $r;
412 }
413
414 if ( count( $redirValues ) ) {
415 $result->setIndexedTagName( $redirValues, 'r' );
416 $result->addValue( 'query', 'redirects', $redirValues );
417 }
418
419 // Missing revision elements
420 $missingRevIDs = $pageSet->getMissingRevisionIDs();
421 if ( count( $missingRevIDs ) ) {
422 $revids = array();
423 foreach ( $missingRevIDs as $revid ) {
424 $revids[$revid] = array(
425 'revid' => $revid
426 );
427 }
428 $result->setIndexedTagName( $revids, 'rev' );
429 $result->addValue( 'query', 'badrevids', $revids );
430 }
431
432 // Page elements
433 $pages = array();
434
435 // Report any missing titles
436 foreach ( $pageSet->getMissingTitles() as $fakeId => $title ) {
437 $vals = array();
438 ApiQueryBase::addTitleInfo( $vals, $title );
439 $vals['missing'] = '';
440 $pages[$fakeId] = $vals;
441 }
442 // Report any invalid titles
443 foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) {
444 $pages[$fakeId] = array( 'title' => $title, 'invalid' => '' );
445 }
446 // Report any missing page ids
447 foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
448 $pages[$pageid] = array(
449 'pageid' => $pageid,
450 'missing' => ''
451 );
452 }
453 // Report special pages
454 foreach ( $pageSet->getSpecialTitles() as $fakeId => $title ) {
455 $vals = array();
456 ApiQueryBase::addTitleInfo( $vals, $title );
457 $vals['special'] = '';
458 if ( $title->isSpecialPage() &&
459 !SpecialPageFactory::exists( $title->getDbKey() ) ) {
460 $vals['missing'] = '';
461 } elseif ( $title->getNamespace() == NS_MEDIA &&
462 !wfFindFile( $title ) ) {
463 $vals['missing'] = '';
464 }
465 $pages[$fakeId] = $vals;
466 }
467
468 // Output general page information for found titles
469 foreach ( $pageSet->getGoodTitles() as $pageid => $title ) {
470 $vals = array();
471 $vals['pageid'] = $pageid;
472 ApiQueryBase::addTitleInfo( $vals, $title );
473 $pages[$pageid] = $vals;
474 }
475
476 if ( count( $pages ) ) {
477 if ( $this->params['indexpageids'] ) {
478 $pageIDs = array_keys( $pages );
479 // json treats all map keys as strings - converting to match
480 $pageIDs = array_map( 'strval', $pageIDs );
481 $result->setIndexedTagName( $pageIDs, 'id' );
482 $result->addValue( 'query', 'pageids', $pageIDs );
483 }
484
485 $result->setIndexedTagName( $pages, 'page' );
486 $result->addValue( 'query', 'pages', $pages );
487 }
488 if ( $this->params['export'] ) {
489 $this->doExport( $pageSet, $result );
490 }
491 }
492
493 /**
494 * @param $pageSet ApiPageSet Pages to be exported
495 * @param $result ApiResult Result to output to
496 */
497 private function doExport( $pageSet, $result ) {
498 $exportTitles = array();
499 $titles = $pageSet->getGoodTitles();
500 if ( count( $titles ) ) {
501 foreach ( $titles as $title ) {
502 if ( $title->userCan( 'read' ) ) {
503 $exportTitles[] = $title;
504 }
505 }
506 }
507
508 $exporter = new WikiExporter( $this->getDB() );
509 // WikiExporter writes to stdout, so catch its
510 // output with an ob
511 ob_start();
512 $exporter->openStream();
513 foreach ( $exportTitles as $title ) {
514 $exporter->pageByTitle( $title );
515 }
516 $exporter->closeStream();
517 $exportxml = ob_get_contents();
518 ob_end_clean();
519
520 // Don't check the size of exported stuff
521 // It's not continuable, so it would cause more
522 // problems than it'd solve
523 $result->disableSizeCheck();
524 if ( $this->params['exportnowrap'] ) {
525 $result->reset();
526 // Raw formatter will handle this
527 $result->addValue( null, 'text', $exportxml );
528 $result->addValue( null, 'mime', 'text/xml' );
529 } else {
530 $r = array();
531 ApiResult::setContent( $r, $exportxml );
532 $result->addValue( 'query', 'export', $r );
533 }
534 $result->enableSizeCheck();
535 }
536
537 /**
538 * Create a generator object of the given type and return it
539 * @param $generatorName string Module name
540 * @return ApiQueryGeneratorBase
541 */
542 public function newGenerator( $generatorName ) {
543 // Find class that implements requested generator
544 if ( isset( $this->mQueryListModules[$generatorName] ) ) {
545 $className = $this->mQueryListModules[$generatorName];
546 } elseif ( isset( $this->mQueryPropModules[$generatorName] ) ) {
547 $className = $this->mQueryPropModules[$generatorName];
548 } else {
549 ApiBase::dieDebug( __METHOD__, "Unknown generator=$generatorName" );
550 }
551 $generator = new $className ( $this, $generatorName );
552 if ( !$generator instanceof ApiQueryGeneratorBase ) {
553 $this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' );
554 }
555 $generator->setGeneratorMode();
556 return $generator;
557 }
558
559 /**
560 * For generator mode, execute generator, and use its output as new
561 * ApiPageSet
562 * @param $generator ApiQueryGeneratorBase Generator Module
563 * @param $modules array of module objects
564 */
565 protected function executeGeneratorModule( $generator, $modules ) {
566 // Generator results
567 $resultPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
568
569 // Add any additional fields modules may need
570 $generator->requestExtraData( $this->mPageSet );
571 $this->addCustomFldsToPageSet( $modules, $resultPageSet );
572
573 // Populate page information with the original user input
574 $this->mPageSet->execute();
575
576 // populate resultPageSet with the generator output
577 $generator->profileIn();
578 $generator->executeGenerator( $resultPageSet );
579 wfRunHooks( 'APIQueryGeneratorAfterExecute', array( &$generator, &$resultPageSet ) );
580 $resultPageSet->finishPageSetGeneration();
581 $generator->profileOut();
582
583 // Swap the resulting pageset back in
584 $this->mPageSet = $resultPageSet;
585 }
586
587 public function getAllowedParams() {
588 return array(
589 'prop' => array(
590 ApiBase::PARAM_ISMULTI => true,
591 ApiBase::PARAM_TYPE => $this->mPropModuleNames
592 ),
593 'list' => array(
594 ApiBase::PARAM_ISMULTI => true,
595 ApiBase::PARAM_TYPE => $this->mListModuleNames
596 ),
597 'meta' => array(
598 ApiBase::PARAM_ISMULTI => true,
599 ApiBase::PARAM_TYPE => $this->mMetaModuleNames
600 ),
601 'generator' => array(
602 ApiBase::PARAM_TYPE => $this->mAllowedGenerators
603 ),
604 'redirects' => false,
605 'converttitles' => false,
606 'indexpageids' => false,
607 'export' => false,
608 'exportnowrap' => false,
609 'iwurl' => false,
610 );
611 }
612
613 /**
614 * Override the parent to generate help messages for all available query modules.
615 * @return string
616 */
617 public function makeHelpMsg() {
618 // Make sure the internal object is empty
619 // (just in case a sub-module decides to optimize during instantiation)
620 $this->mPageSet = null;
621
622 $querySeparator = str_repeat( '--- ', 12 );
623 $moduleSeparator = str_repeat( '*** ', 14 );
624 $msg = "\n$querySeparator Query: Prop $querySeparator\n\n";
625 $msg .= $this->makeHelpMsgHelper( $this->mQueryPropModules, 'prop' );
626 $msg .= "\n$querySeparator Query: List $querySeparator\n\n";
627 $msg .= $this->makeHelpMsgHelper( $this->mQueryListModules, 'list' );
628 $msg .= "\n$querySeparator Query: Meta $querySeparator\n\n";
629 $msg .= $this->makeHelpMsgHelper( $this->mQueryMetaModules, 'meta' );
630 $msg .= "\n\n$moduleSeparator Modules: continuation $moduleSeparator\n\n";
631
632 // Use parent to make default message for the query module
633 $msg = parent::makeHelpMsg() . $msg;
634
635 return $msg;
636 }
637
638 /**
639 * For all modules in $moduleList, generate help messages and join them together
640 * @param $moduleList Array array(modulename => classname)
641 * @param $paramName string Parameter name
642 * @return string
643 */
644 private function makeHelpMsgHelper( $moduleList, $paramName ) {
645 $moduleDescriptions = array();
646
647 foreach ( $moduleList as $moduleName => $moduleClass ) {
648 /**
649 * @var $module ApiQueryBase
650 */
651 $module = new $moduleClass( $this, $moduleName, null );
652
653 $msg = ApiMain::makeHelpMsgHeader( $module, $paramName );
654 $msg2 = $module->makeHelpMsg();
655 if ( $msg2 !== false ) {
656 $msg .= $msg2;
657 }
658 if ( $module instanceof ApiQueryGeneratorBase ) {
659 $msg .= "Generator:\n This module may be used as a generator\n";
660 }
661 $moduleDescriptions[] = $msg;
662 }
663
664 return implode( "\n", $moduleDescriptions );
665 }
666
667 /**
668 * Adds any classes that are a subclass of ApiQueryGeneratorBase
669 * to the allowed generator list
670 * @param $moduleList array()
671 */
672 private function makeGeneratorList( $moduleList ) {
673 foreach( $moduleList as $moduleName => $moduleClass ) {
674 if ( is_subclass_of( $moduleClass, 'ApiQueryGeneratorBase' ) ) {
675 $this->mAllowedGenerators[] = $moduleName;
676 }
677 }
678 }
679
680 /**
681 * Override to add extra parameters from PageSet
682 * @return string
683 */
684 public function makeHelpMsgParameters() {
685 $psModule = new ApiPageSet( $this );
686 return $psModule->makeHelpMsgParameters() . parent::makeHelpMsgParameters();
687 }
688
689 public function shouldCheckMaxlag() {
690 return true;
691 }
692
693 public function getParamDescription() {
694 return array(
695 'prop' => 'Which properties to get for the titles/revisions/pageids. Module help is available below',
696 'list' => 'Which lists to get. Module help is available below',
697 'meta' => 'Which metadata to get about the site. Module help is available below',
698 'generator' => array( 'Use the output of a list as the input for other prop/list/meta items',
699 'NOTE: generator parameter names must be prefixed with a \'g\', see examples' ),
700 'redirects' => 'Automatically resolve redirects',
701 'converttitles' => array( "Convert titles to other variants if necessary. Only works if the wiki's content language supports variant conversion.",
702 'Languages that support variant conversion include ' . implode( ', ', LanguageConverter::$languagesWithVariants ) ),
703 'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
704 'export' => 'Export the current revisions of all given or generated pages',
705 'exportnowrap' => 'Return the export XML without wrapping it in an XML result (same format as Special:Export). Can only be used with export',
706 'iwurl' => 'Whether to get the full URL if the title is an interwiki link',
707 );
708 }
709
710 public function getDescription() {
711 return array(
712 'Query API module allows applications to get needed pieces of data from the MediaWiki databases,',
713 'and is loosely based on the old query.php interface.',
714 'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites'
715 );
716 }
717
718 public function getPossibleErrors() {
719 return array_merge( parent::getPossibleErrors(), array(
720 array( 'code' => 'badgenerator', 'info' => 'Module $generatorName cannot be used as a generator' ),
721 ) );
722 }
723
724 public function getExamples() {
725 return array(
726 'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment',
727 'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions',
728 );
729 }
730
731 public function getHelpUrls() {
732 return array(
733 'https://www.mediawiki.org/wiki/API:Meta',
734 'https://www.mediawiki.org/wiki/API:Properties',
735 'https://www.mediawiki.org/wiki/API:Lists',
736 );
737 }
738
739 public function getVersion() {
740 $psModule = new ApiPageSet( $this );
741 $vers = array();
742 $vers[] = __CLASS__ . ': $Id$';
743 $vers[] = $psModule->getVersion();
744 return $vers;
745 }
746 }