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