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