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