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