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