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