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