Merge branch 'Wikidata' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata
[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 protected $mAllowedGenerators = array();
105
106 public function __construct( $main, $action ) {
107 parent::__construct( $main, $action );
108
109 // Allow custom modules to be added in LocalSettings.php
110 global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules;
111 self::appendUserModules( $this->mQueryPropModules, $wgAPIPropModules );
112 self::appendUserModules( $this->mQueryListModules, $wgAPIListModules );
113 self::appendUserModules( $this->mQueryMetaModules, $wgAPIMetaModules );
114
115 $this->mPropModuleNames = array_keys( $this->mQueryPropModules );
116 $this->mListModuleNames = array_keys( $this->mQueryListModules );
117 $this->mMetaModuleNames = array_keys( $this->mQueryMetaModules );
118
119 $this->makeHelpMsgHelper( $this->mQueryPropModules, 'prop' );
120 $this->makeHelpMsgHelper( $this->mQueryListModules, 'list' );
121 }
122
123 /**
124 * Helper function to append any add-in modules to the list
125 * @param $modules array Module array
126 * @param $newModules array Module array to add to $modules
127 */
128 private static function appendUserModules( &$modules, $newModules ) {
129 if ( is_array( $newModules ) ) {
130 foreach ( $newModules as $moduleName => $moduleClass ) {
131 $modules[$moduleName] = $moduleClass;
132 }
133 }
134 }
135
136 /**
137 * Gets a default slave database connection object
138 * @return DatabaseBase
139 */
140 public function getDB() {
141 if ( !isset( $this->mSlaveDB ) ) {
142 $this->profileDBIn();
143 $this->mSlaveDB = wfGetDB( DB_SLAVE, 'api' );
144 $this->profileDBOut();
145 }
146 return $this->mSlaveDB;
147 }
148
149 /**
150 * Get the query database connection with the given name.
151 * If no such connection has been requested before, it will be created.
152 * Subsequent calls with the same $name will return the same connection
153 * as the first, regardless of the values of $db and $groups
154 * @param $name string Name to assign to the database connection
155 * @param $db int One of the DB_* constants
156 * @param $groups array Query groups
157 * @return DatabaseBase
158 */
159 public function getNamedDB( $name, $db, $groups ) {
160 if ( !array_key_exists( $name, $this->mNamedDB ) ) {
161 $this->profileDBIn();
162 $this->mNamedDB[$name] = wfGetDB( $db, $groups );
163 $this->profileDBOut();
164 }
165 return $this->mNamedDB[$name];
166 }
167
168 /**
169 * Gets the set of pages the user has requested (or generated)
170 * @return ApiPageSet
171 */
172 public function getPageSet() {
173 return $this->mPageSet;
174 }
175
176 /**
177 * Get the array mapping module names to class names
178 * @return array array(modulename => classname)
179 */
180 function getModules() {
181 return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
182 }
183
184 /**
185 * Get whether the specified module is a prop, list or a meta query module
186 * @param $moduleName string Name of the module to find type for
187 * @return mixed string or null
188 */
189 function getModuleType( $moduleName ) {
190 if ( isset( $this->mQueryPropModules[$moduleName] ) ) {
191 return 'prop';
192 }
193
194 if ( isset( $this->mQueryListModules[$moduleName] ) ) {
195 return 'list';
196 }
197
198 if ( isset( $this->mQueryMetaModules[$moduleName] ) ) {
199 return 'meta';
200 }
201
202 return null;
203 }
204
205 public function getCustomPrinter() {
206 // If &exportnowrap is set, use the raw formatter
207 if ( $this->getParameter( 'export' ) &&
208 $this->getParameter( 'exportnowrap' ) )
209 {
210 return new ApiFormatRaw( $this->getMain(),
211 $this->getMain()->createPrinterByName( 'xml' ) );
212 } else {
213 return null;
214 }
215 }
216
217 /**
218 * Query execution happens in the following steps:
219 * #1 Create a PageSet object with any pages requested by the user
220 * #2 If using a generator, execute it to get a new ApiPageSet object
221 * #3 Instantiate all requested modules.
222 * This way the PageSet object will know what shared data is required,
223 * and minimize DB calls.
224 * #4 Output all normalization and redirect resolution information
225 * #5 Execute all requested modules
226 */
227 public function execute() {
228 $this->params = $this->extractRequestParams();
229 $this->redirects = $this->params['redirects'];
230 $this->convertTitles = $this->params['converttitles'];
231 $this->iwUrl = $this->params['iwurl'];
232
233 // Create PageSet
234 $this->mPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
235
236 // Instantiate requested modules
237 $modules = array();
238 $this->instantiateModules( $modules, 'prop', $this->mQueryPropModules );
239 $this->instantiateModules( $modules, 'list', $this->mQueryListModules );
240 $this->instantiateModules( $modules, 'meta', $this->mQueryMetaModules );
241
242 $cacheMode = 'public';
243
244 // If given, execute generator to substitute user supplied data with generated data.
245 if ( isset( $this->params['generator'] ) ) {
246 $generator = $this->newGenerator( $this->params['generator'] );
247 $params = $generator->extractRequestParams();
248 $cacheMode = $this->mergeCacheMode( $cacheMode,
249 $generator->getCacheMode( $params ) );
250 $this->executeGeneratorModule( $generator, $modules );
251 } else {
252 // Append custom fields and populate page/revision information
253 $this->addCustomFldsToPageSet( $modules, $this->mPageSet );
254 $this->mPageSet->execute();
255 }
256
257 // Record page information (title, namespace, if exists, etc)
258 $this->outputGeneralPageInfo();
259
260 // Execute all requested modules.
261 foreach ( $modules as $module ) {
262 $params = $module->extractRequestParams();
263 $cacheMode = $this->mergeCacheMode(
264 $cacheMode, $module->getCacheMode( $params ) );
265 $module->profileIn();
266 $module->execute();
267 wfRunHooks( 'APIQueryAfterExecute', array( &$module ) );
268 $module->profileOut();
269 }
270
271 // Set the cache mode
272 $this->getMain()->setCacheMode( $cacheMode );
273 }
274
275 /**
276 * Update a cache mode string, applying the cache mode of a new module to it.
277 * The cache mode may increase in the level of privacy, but public modules
278 * added to private data do not decrease the level of privacy.
279 *
280 * @param $cacheMode string
281 * @param $modCacheMode string
282 * @return string
283 */
284 protected function mergeCacheMode( $cacheMode, $modCacheMode ) {
285 if ( $modCacheMode === 'anon-public-user-private' ) {
286 if ( $cacheMode !== 'private' ) {
287 $cacheMode = 'anon-public-user-private';
288 }
289 } elseif ( $modCacheMode === 'public' ) {
290 // do nothing, if it's public already it will stay public
291 } else { // private
292 $cacheMode = 'private';
293 }
294 return $cacheMode;
295 }
296
297 /**
298 * Query modules may optimize data requests through the $this->getPageSet() object
299 * by adding extra fields from the page table.
300 * This function will gather all the extra request fields from the modules.
301 * @param $modules array of module objects
302 * @param $pageSet ApiPageSet
303 */
304 private function addCustomFldsToPageSet( $modules, $pageSet ) {
305 // Query all requested modules.
306 foreach ( $modules as $module ) {
307 $module->requestExtraData( $pageSet );
308 }
309 }
310
311 /**
312 * Create instances of all modules requested by the client
313 * @param $modules Array to append instantiated modules to
314 * @param $param string Parameter name to read modules from
315 * @param $moduleList Array array(modulename => classname)
316 */
317 private function instantiateModules( &$modules, $param, $moduleList ) {
318 if ( isset( $this->params[$param] ) ) {
319 foreach ( $this->params[$param] as $moduleName ) {
320 $modules[] = new $moduleList[$moduleName] ( $this, $moduleName );
321 }
322 }
323 }
324
325 /**
326 * Appends an element for each page in the current pageSet with the
327 * most general information (id, title), plus any title normalizations
328 * and missing or invalid title/pageids/revids.
329 */
330 private function outputGeneralPageInfo() {
331 $pageSet = $this->getPageSet();
332 $result = $this->getResult();
333
334 // We don't check for a full result set here because we can't be adding
335 // more than 380K. The maximum revision size is in the megabyte range,
336 // and the maximum result size must be even higher than that.
337
338 // Title normalizations
339 $normValues = array();
340 foreach ( $pageSet->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
341 $normValues[] = array(
342 'from' => $rawTitleStr,
343 'to' => $titleStr
344 );
345 }
346
347 if ( count( $normValues ) ) {
348 $result->setIndexedTagName( $normValues, 'n' );
349 $result->addValue( 'query', 'normalized', $normValues );
350 }
351
352 // Title conversions
353 $convValues = array();
354 foreach ( $pageSet->getConvertedTitles() as $rawTitleStr => $titleStr ) {
355 $convValues[] = array(
356 'from' => $rawTitleStr,
357 'to' => $titleStr
358 );
359 }
360
361 if ( count( $convValues ) ) {
362 $result->setIndexedTagName( $convValues, 'c' );
363 $result->addValue( 'query', 'converted', $convValues );
364 }
365
366 // Interwiki titles
367 $intrwValues = array();
368 foreach ( $pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) {
369 $item = array(
370 'title' => $rawTitleStr,
371 'iw' => $interwikiStr,
372 );
373 if ( $this->iwUrl ) {
374 $title = Title::newFromText( $rawTitleStr );
375 $item['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
376 }
377 $intrwValues[] = $item;
378 }
379
380 if ( count( $intrwValues ) ) {
381 $result->setIndexedTagName( $intrwValues, 'i' );
382 $result->addValue( 'query', 'interwiki', $intrwValues );
383 }
384
385 // Show redirect information
386 $redirValues = array();
387 foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleTo ) {
388 $r = array(
389 'from' => strval( $titleStrFrom ),
390 'to' => $titleTo->getPrefixedText(),
391 );
392 if ( $titleTo->getFragment() !== '' ) {
393 $r['tofragment'] = $titleTo->getFragment();
394 }
395 $redirValues[] = $r;
396 }
397
398 if ( count( $redirValues ) ) {
399 $result->setIndexedTagName( $redirValues, 'r' );
400 $result->addValue( 'query', 'redirects', $redirValues );
401 }
402
403 // Missing revision elements
404 $missingRevIDs = $pageSet->getMissingRevisionIDs();
405 if ( count( $missingRevIDs ) ) {
406 $revids = array();
407 foreach ( $missingRevIDs as $revid ) {
408 $revids[$revid] = array(
409 'revid' => $revid
410 );
411 }
412 $result->setIndexedTagName( $revids, 'rev' );
413 $result->addValue( 'query', 'badrevids', $revids );
414 }
415
416 // Page elements
417 $pages = array();
418
419 // Report any missing titles
420 foreach ( $pageSet->getMissingTitles() as $fakeId => $title ) {
421 $vals = array();
422 ApiQueryBase::addTitleInfo( $vals, $title );
423 $vals['missing'] = '';
424 $pages[$fakeId] = $vals;
425 }
426 // Report any invalid titles
427 foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) {
428 $pages[$fakeId] = array( 'title' => $title, 'invalid' => '' );
429 }
430 // Report any missing page ids
431 foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
432 $pages[$pageid] = array(
433 'pageid' => $pageid,
434 'missing' => ''
435 );
436 }
437 // Report special pages
438 foreach ( $pageSet->getSpecialTitles() as $fakeId => $title ) {
439 $vals = array();
440 ApiQueryBase::addTitleInfo( $vals, $title );
441 $vals['special'] = '';
442 if ( $title->isSpecialPage() &&
443 !SpecialPageFactory::exists( $title->getDbKey() ) ) {
444 $vals['missing'] = '';
445 } elseif ( $title->getNamespace() == NS_MEDIA &&
446 !wfFindFile( $title ) ) {
447 $vals['missing'] = '';
448 }
449 $pages[$fakeId] = $vals;
450 }
451
452 // Output general page information for found titles
453 foreach ( $pageSet->getGoodTitles() as $pageid => $title ) {
454 $vals = array();
455 $vals['pageid'] = $pageid;
456 ApiQueryBase::addTitleInfo( $vals, $title );
457 $pages[$pageid] = $vals;
458 }
459
460 if ( count( $pages ) ) {
461 if ( $this->params['indexpageids'] ) {
462 $pageIDs = array_keys( $pages );
463 // json treats all map keys as strings - converting to match
464 $pageIDs = array_map( 'strval', $pageIDs );
465 $result->setIndexedTagName( $pageIDs, 'id' );
466 $result->addValue( 'query', 'pageids', $pageIDs );
467 }
468
469 $result->setIndexedTagName( $pages, 'page' );
470 $result->addValue( 'query', 'pages', $pages );
471 }
472 if ( $this->params['export'] ) {
473 $this->doExport( $pageSet, $result );
474 }
475 }
476
477 /**
478 * @param $pageSet ApiPageSet Pages to be exported
479 * @param $result ApiResult Result to output to
480 */
481 private function doExport( $pageSet, $result ) {
482 $exportTitles = array();
483 $titles = $pageSet->getGoodTitles();
484 if ( count( $titles ) ) {
485 foreach ( $titles as $title ) {
486 if ( $title->userCan( 'read' ) ) {
487 $exportTitles[] = $title;
488 }
489 }
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 'iwurl' => false,
594 );
595 }
596
597 /**
598 * Override the parent to generate help messages for all available query modules.
599 * @return string
600 */
601 public function makeHelpMsg() {
602 // Make sure the internal object is empty
603 // (just in case a sub-module decides to optimize during instantiation)
604 $this->mPageSet = null;
605 $this->mAllowedGenerators = array(); // Will be repopulated
606
607 $querySeparator = str_repeat( '--- ', 12 );
608 $moduleSeparator = str_repeat( '*** ', 14 );
609 $msg = "\n$querySeparator Query: Prop $querySeparator\n\n";
610 $msg .= $this->makeHelpMsgHelper( $this->mQueryPropModules, 'prop' );
611 $msg .= "\n$querySeparator Query: List $querySeparator\n\n";
612 $msg .= $this->makeHelpMsgHelper( $this->mQueryListModules, 'list' );
613 $msg .= "\n$querySeparator Query: Meta $querySeparator\n\n";
614 $msg .= $this->makeHelpMsgHelper( $this->mQueryMetaModules, 'meta' );
615 $msg .= "\n\n$moduleSeparator Modules: continuation $moduleSeparator\n\n";
616
617 // Perform the base call last because the $this->mAllowedGenerators
618 // will be updated inside makeHelpMsgHelper()
619 // Use parent to make default message for the query module
620 $msg = parent::makeHelpMsg() . $msg;
621
622 return $msg;
623 }
624
625 /**
626 * For all modules in $moduleList, generate help messages and join them together
627 * @param $moduleList Array array(modulename => classname)
628 * @param $paramName string Parameter name
629 * @return string
630 */
631 private function makeHelpMsgHelper( $moduleList, $paramName ) {
632 $moduleDescriptions = array();
633
634 foreach ( $moduleList as $moduleName => $moduleClass ) {
635 /**
636 * @var $module ApiQueryBase
637 */
638 $module = new $moduleClass( $this, $moduleName, null );
639
640 $msg = ApiMain::makeHelpMsgHeader( $module, $paramName );
641 $msg2 = $module->makeHelpMsg();
642 if ( $msg2 !== false ) {
643 $msg .= $msg2;
644 }
645 if ( $module instanceof ApiQueryGeneratorBase ) {
646 $this->mAllowedGenerators[] = $moduleName;
647 $msg .= "Generator:\n This module may be used as a generator\n";
648 }
649 $moduleDescriptions[] = $msg;
650 }
651
652 return implode( "\n", $moduleDescriptions );
653 }
654
655 /**
656 * Override to add extra parameters from PageSet
657 * @return string
658 */
659 public function makeHelpMsgParameters() {
660 $psModule = new ApiPageSet( $this );
661 return $psModule->makeHelpMsgParameters() . parent::makeHelpMsgParameters();
662 }
663
664 public function shouldCheckMaxlag() {
665 return true;
666 }
667
668 public function getParamDescription() {
669 return array(
670 'prop' => 'Which properties to get for the titles/revisions/pageids. Module help is available below',
671 'list' => 'Which lists to get. Module help is available below',
672 'meta' => 'Which metadata to get about the site. Module help is available below',
673 'generator' => array( 'Use the output of a list as the input for other prop/list/meta items',
674 'NOTE: generator parameter names must be prefixed with a \'g\', see examples' ),
675 'redirects' => 'Automatically resolve redirects',
676 'converttitles' => array( "Convert titles to other variants if necessary. Only works if the wiki's content language supports variant conversion.",
677 'Languages that support variant conversion include gan, iu, kk, ku, shi, sr, tg, zh' ),
678 'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
679 'export' => 'Export the current revisions of all given or generated pages',
680 'exportnowrap' => 'Return the export XML without wrapping it in an XML result (same format as Special:Export). Can only be used with export',
681 'iwurl' => 'Whether to get the full URL if the title is an interwiki link',
682 );
683 }
684
685 public function getDescription() {
686 return array(
687 'Query API module allows applications to get needed pieces of data from the MediaWiki databases,',
688 'and is loosely based on the old query.php interface.',
689 'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites'
690 );
691 }
692
693 public function getPossibleErrors() {
694 return array_merge( parent::getPossibleErrors(), array(
695 array( 'code' => 'badgenerator', 'info' => 'Module $generatorName cannot be used as a generator' ),
696 ) );
697 }
698
699 public function getExamples() {
700 return array(
701 'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment',
702 'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions',
703 );
704 }
705
706 public function getHelpUrls() {
707 return array(
708 'https://www.mediawiki.org/wiki/API:Meta',
709 'https://www.mediawiki.org/wiki/API:Properties',
710 'https://www.mediawiki.org/wiki/API:Lists',
711 );
712 }
713
714 public function getVersion() {
715 $psModule = new ApiPageSet( $this );
716 $vers = array();
717 $vers[] = __CLASS__ . ': $Id$';
718 $vers[] = $psModule->getVersion();
719 return $vers;
720 }
721 }