6027818193e5bbd2b570ad3d51e29ca2029a831a
[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 instatiated modules to
305 * @param $param string Parameter name to read modules from
306 * @param $moduleList 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 $exporter = new WikiExporter( $this->getDB() );
461 // WikiExporter writes to stdout, so catch its
462 // output with an ob
463 ob_start();
464 $exporter->openStream();
465 foreach ( @$pageSet->getGoodTitles() as $title ) {
466 if ( $title->userCanRead() ) {
467 $exporter->pageByTitle( $title );
468 }
469 }
470 $exporter->closeStream();
471 $exportxml = ob_get_contents();
472 ob_end_clean();
473
474 // Don't check the size of exported stuff
475 // It's not continuable, so it would cause more
476 // problems than it'd solve
477 $result->disableSizeCheck();
478 if ( $this->params['exportnowrap'] ) {
479 $result->reset();
480 // Raw formatter will handle this
481 $result->addValue( null, 'text', $exportxml );
482 $result->addValue( null, 'mime', 'text/xml' );
483 } else {
484 $r = array();
485 ApiResult::setContent( $r, $exportxml );
486 $result->addValue( 'query', 'export', $r );
487 }
488 $result->enableSizeCheck();
489 }
490 }
491
492 /**
493 * Create a generator object of the given type and return it
494 * @param $generatorName string Module name
495 * @return ApiQueryGeneratorBase
496 */
497 public function newGenerator( $generatorName ) {
498 // Find class that implements requested generator
499 if ( isset( $this->mQueryListModules[$generatorName] ) ) {
500 $className = $this->mQueryListModules[$generatorName];
501 } elseif ( isset( $this->mQueryPropModules[$generatorName] ) ) {
502 $className = $this->mQueryPropModules[$generatorName];
503 } else {
504 ApiBase::dieDebug( __METHOD__, "Unknown generator=$generatorName" );
505 }
506 $generator = new $className ( $this, $generatorName );
507 if ( !$generator instanceof ApiQueryGeneratorBase ) {
508 $this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' );
509 }
510 $generator->setGeneratorMode();
511 return $generator;
512 }
513
514 /**
515 * For generator mode, execute generator, and use its output as new
516 * ApiPageSet
517 * @param $generator ApiQueryGeneratorBase Generator Module
518 * @param $modules array of module objects
519 */
520 protected function executeGeneratorModule( $generator, $modules ) {
521 // Generator results
522 $resultPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
523
524 // Add any additional fields modules may need
525 $generator->requestExtraData( $this->mPageSet );
526 $this->addCustomFldsToPageSet( $modules, $resultPageSet );
527
528 // Populate page information with the original user input
529 $this->mPageSet->execute();
530
531 // populate resultPageSet with the generator output
532 $generator->profileIn();
533 $generator->executeGenerator( $resultPageSet );
534 wfRunHooks( 'APIQueryGeneratorAfterExecute', array( &$generator, &$resultPageSet ) );
535 $resultPageSet->finishPageSetGeneration();
536 $generator->profileOut();
537
538 // Swap the resulting pageset back in
539 $this->mPageSet = $resultPageSet;
540 }
541
542 public function getAllowedParams() {
543 return array(
544 'prop' => array(
545 ApiBase::PARAM_ISMULTI => true,
546 ApiBase::PARAM_TYPE => $this->mPropModuleNames
547 ),
548 'list' => array(
549 ApiBase::PARAM_ISMULTI => true,
550 ApiBase::PARAM_TYPE => $this->mListModuleNames
551 ),
552 'meta' => array(
553 ApiBase::PARAM_ISMULTI => true,
554 ApiBase::PARAM_TYPE => $this->mMetaModuleNames
555 ),
556 'generator' => array(
557 ApiBase::PARAM_TYPE => $this->mAllowedGenerators
558 ),
559 'redirects' => false,
560 'converttitles' => false,
561 'indexpageids' => false,
562 'export' => false,
563 'exportnowrap' => false,
564 );
565 }
566
567 /**
568 * Override the parent to generate help messages for all available query modules.
569 * @return string
570 */
571 public function makeHelpMsg() {
572 $msg = '';
573
574 // Make sure the internal object is empty
575 // (just in case a sub-module decides to optimize during instantiation)
576 $this->mPageSet = null;
577 $this->mAllowedGenerators = array(); // Will be repopulated
578
579 $astriks = str_repeat( '--- ', 8 );
580 $astriks2 = str_repeat( '*** ', 10 );
581 $msg .= "\n$astriks Query: Prop $astriks\n\n";
582 $msg .= $this->makeHelpMsgHelper( $this->mQueryPropModules, 'prop' );
583 $msg .= "\n$astriks Query: List $astriks\n\n";
584 $msg .= $this->makeHelpMsgHelper( $this->mQueryListModules, 'list' );
585 $msg .= "\n$astriks Query: Meta $astriks\n\n";
586 $msg .= $this->makeHelpMsgHelper( $this->mQueryMetaModules, 'meta' );
587 $msg .= "\n\n$astriks2 Modules: continuation $astriks2\n\n";
588
589 // Perform the base call last because the $this->mAllowedGenerators
590 // will be updated inside makeHelpMsgHelper()
591 // Use parent to make default message for the query module
592 $msg = parent::makeHelpMsg() . $msg;
593
594 return $msg;
595 }
596
597 /**
598 * For all modules in $moduleList, generate help messages and join them together
599 * @param $moduleList array(modulename => classname)
600 * @param $paramName string Parameter name
601 * @return string
602 */
603 private function makeHelpMsgHelper( $moduleList, $paramName ) {
604 $moduleDescriptions = array();
605
606 foreach ( $moduleList as $moduleName => $moduleClass ) {
607 $module = new $moduleClass ( $this, $moduleName, null );
608
609 $msg = ApiMain::makeHelpMsgHeader( $module, $paramName );
610 $msg2 = $module->makeHelpMsg();
611 if ( $msg2 !== false ) {
612 $msg .= $msg2;
613 }
614 if ( $module instanceof ApiQueryGeneratorBase ) {
615 $this->mAllowedGenerators[] = $moduleName;
616 $msg .= "Generator:\n This module may be used as a generator\n";
617 }
618 $moduleDescriptions[] = $msg;
619 }
620
621 return implode( "\n", $moduleDescriptions );
622 }
623
624 /**
625 * Override to add extra parameters from PageSet
626 * @return string
627 */
628 public function makeHelpMsgParameters() {
629 $psModule = new ApiPageSet( $this );
630 return $psModule->makeHelpMsgParameters() . parent::makeHelpMsgParameters();
631 }
632
633 public function shouldCheckMaxlag() {
634 return true;
635 }
636
637 public function getParamDescription() {
638 return array(
639 'prop' => 'Which properties to get for the titles/revisions/pageids. Module help is available below',
640 'list' => 'Which lists to get. Module help is available below',
641 'meta' => 'Which metadata to get about the site. Module help is available below',
642 'generator' => array( 'Use the output of a list as the input for other prop/list/meta items',
643 'NOTE: generator parameter names must be prefixed with a \'g\', see examples' ),
644 'redirects' => 'Automatically resolve redirects',
645 'converttitles' => array( "Convert titles to other variants if necessary. Only works if the wiki's content language supports variant conversion.",
646 'Languages that support variant conversion include kk, ku, gan, tg, sr, zh' ),
647 'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
648 'export' => 'Export the current revisions of all given or generated pages',
649 'exportnowrap' => 'Return the export XML without wrapping it in an XML result (same format as Special:Export). Can only be used with export',
650 );
651 }
652
653 public function getDescription() {
654 return array(
655 'Query API module allows applications to get needed pieces of data from the MediaWiki databases,',
656 'and is loosely based on the old query.php interface.',
657 'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites'
658 );
659 }
660
661 public function getPossibleErrors() {
662 return array_merge( parent::getPossibleErrors(), array(
663 array( 'code' => 'badgenerator', 'info' => 'Module $generatorName cannot be used as a generator' ),
664 ) );
665 }
666
667 protected function getExamples() {
668 return array(
669 'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment',
670 'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions',
671 );
672 }
673
674 public function getVersion() {
675 $psModule = new ApiPageSet( $this );
676 $vers = array();
677 $vers[] = __CLASS__ . ': $Id$';
678 $vers[] = $psModule->getVersion();
679 return $vers;
680 }
681 }