25 use Wikimedia\ObjectFactory\ObjectFactory;
48 'class' => ApiQueryCategories::class,
51 'class' => ApiQueryCategoryInfo::class,
54 'class' => ApiQueryContributors::class,
59 'GroupPermissionsLookup',
62 'deletedrevisions' => [
63 'class' => ApiQueryDeletedRevisions::class,
66 'ContentHandlerFactory',
76 'class' => ApiQueryDuplicateFiles::class,
82 'class' => ApiQueryExternalLinks::class,
85 'class' => ApiQueryBacklinksprop::class,
92 'class' => ApiQueryImages::class,
95 'class' => ApiQueryImageInfo::class,
104 'class' => ApiQueryInfo::class,
112 'LanguageConverterFactory',
118 'class' => ApiQueryLinks::class,
126 'class' => ApiQueryBacklinksprop::class,
133 'class' => ApiQueryIWLinks::class,
136 'class' => ApiQueryLangLinks::class,
143 'class' => ApiQueryPageProps::class,
149 'class' => ApiQueryBacklinksprop::class,
156 'class' => ApiQueryRevisions::class,
159 'ContentHandlerFactory',
165 'ContentTransformer',
168 'stashimageinfo' => [
169 'class' => ApiQueryStashImageInfo::class,
178 'class' => ApiQueryLinks::class,
186 'class' => ApiQueryBacklinksprop::class,
199 'class' => ApiQueryAllCategories::class,
201 'alldeletedrevisions' => [
202 'class' => ApiQueryAllDeletedRevisions::class,
205 'ContentHandlerFactory',
211 'ContentTransformer',
215 'class' => ApiQueryAllLinks::class,
224 'class' => ApiQueryAllImages::class,
227 'GroupPermissionsLookup',
231 'class' => ApiQueryAllLinks::class,
240 'class' => ApiQueryAllPages::class,
248 'class' => ApiQueryAllLinks::class,
257 'class' => ApiQueryAllRevisions::class,
260 'ContentHandlerFactory',
266 'ContentTransformer',
269 'mystashedfiles' => [
270 'class' => ApiQueryMyStashedFiles::class,
272 'alltransclusions' => [
273 'class' => ApiQueryAllLinks::class,
282 'class' => ApiQueryAllUsers::class,
286 'GroupPermissionsLookup',
291 'class' => ApiQueryBacklinks::class,
294 'class' => ApiQueryBlocks::class,
297 'BlockRestrictionStore',
301 'categorymembers' => [
302 'class' => ApiQueryCategoryMembers::class,
308 'class' => ApiQueryDeletedrevs::class,
311 'RowCommentFormatter',
318 'class' => ApiQueryBacklinks::class,
321 'class' => ApiQueryExtLinksUsage::class,
324 'class' => ApiQueryFilearchive::class,
331 'class' => ApiQueryBacklinks::class,
334 'class' => ApiQueryIWBacklinks::class,
337 'class' => ApiQueryLangBacklinks::class,
340 'class' => ApiQueryLogEvents::class,
343 'RowCommentFormatter',
348 'class' => ApiQueryPagesWithProp::class,
351 'class' => ApiQueryPagePropNames::class,
354 'class' => ApiQueryPrefixSearch::class,
356 'SearchEngineConfig',
357 'SearchEngineFactory',
360 'protectedtitles' => [
361 'class' => ApiQueryProtectedTitles::class,
364 'RowCommentFormatter'
368 'class' => ApiQueryQueryPage::class,
370 'SpecialPageFactory',
374 'class' => ApiQueryRandom::class,
377 'class' => ApiQueryRecentChanges::class,
380 'RowCommentFormatter',
387 'class' => ApiQuerySearch::class,
389 'SearchEngineConfig',
390 'SearchEngineFactory',
394 'class' => ApiQueryTags::class,
397 'class' => ApiQueryUserContribs::class,
400 'UserIdentityLookup',
408 'class' => ApiQueryUsers::class,
418 'class' => ApiQueryWatchlist::class,
421 'WatchedItemQueryService',
428 'class' => ApiQueryWatchlistRaw::class,
430 'WatchedItemQueryService',
443 'class' => ApiQueryAllMessages::class,
452 'authmanagerinfo' => [
453 'class' => ApiQueryAuthManagerInfo::class,
459 'class' => ApiQuerySiteinfo::class,
463 'LanguageConverterFactory',
471 'SpecialPageFactory',
478 'class' => ApiQueryUserInfo::class,
480 'TalkPageNotificationManager',
488 'class' => ApiQueryFileRepoInfo::class,
494 'class' => ApiQueryTokens::class,
497 'class' => ApiQueryLanguageinfo::class,
502 'LanguageConverterFactory',
532 ObjectFactory $objectFactory,
536 parent::__construct( $main, $action );
545 $this->mModuleMgr->addModules( self::QUERY_PROP_MODULES,
'prop' );
546 $this->mModuleMgr->addModules( $config->get( MainConfigNames::APIPropModules ),
'prop' );
547 $this->mModuleMgr->addModules( self::QUERY_LIST_MODULES,
'list' );
548 $this->mModuleMgr->addModules( $config->get( MainConfigNames::APIListModules ),
'list' );
549 $this->mModuleMgr->addModules( self::QUERY_META_MODULES,
'meta' );
550 $this->mModuleMgr->addModules( $config->get( MainConfigNames::APIMetaModules ),
'meta' );
552 $this->
getHookRunner()->onApiQuery__moduleManager( $this->mModuleMgr );
579 if ( !array_key_exists( $name, $this->mNamedDB ) ) {
580 $this->mNamedDB[$name] = $this->loadBalancer->getConnectionRef( $db, $groups );
583 return $this->mNamedDB[$name];
603 $this->
getMain()->createPrinterByName(
'xml' ) );
625 $propModules = array_keys( $allModules );
633 $modules = $continuationManager->getRunModules();
634 '@phan-var ApiQueryBase[] $modules';
636 if ( !$continuationManager->isGeneratorDone() ) {
640 $module->requestExtraData( $this->mPageSet );
643 $this->mPageSet->execute();
647 $this->mPageSet->executeDryRun();
650 $cacheMode = $this->mPageSet->getCacheMode();
654 $params = $module->extractRequestParams();
656 $cacheMode, $module->getCacheMode( $params ) );
662 $this->
getMain()->setCacheMode( $cacheMode );
666 if ( $this->mParams[
'rawcontinue'] ) {
667 $data = $continuationManager->getRawNonContinuation();
669 $this->
getResult()->addValue(
null,
'query-noncontinue', $data,
672 $data = $continuationManager->getRawContinuation();
674 $this->
getResult()->addValue(
null,
'query-continue', $data,
678 $continuationManager->setContinuationIntoResult( $this->
getResult() );
692 if ( $modCacheMode ===
'anon-public-user-private' ) {
693 if ( $cacheMode !==
'private' ) {
694 $cacheMode =
'anon-public-user-private';
696 } elseif ( $modCacheMode ===
'public' ) {
699 $cacheMode =
'private';
711 $wasPosted = $this->
getRequest()->wasPosted();
712 if ( isset( $this->mParams[$param] ) ) {
713 foreach ( $this->mParams[$param] as $moduleName ) {
714 $instance = $this->mModuleMgr->getModule( $moduleName, $param );
715 if ( $instance ===
null ) {
718 if ( !$wasPosted && $instance->mustBePosted() ) {
722 if ( !array_key_exists( $moduleName,
$modules ) ) {
742 $values = $pageSet->getNormalizedTitlesAsResult( $result );
745 $fit = $fit && $result->addValue(
'query',
'normalized', $values );
747 $values = $pageSet->getConvertedTitlesAsResult( $result );
749 $fit = $fit && $result->addValue(
'query',
'converted', $values );
751 $values = $pageSet->getInterwikiTitlesAsResult( $result, $this->mParams[
'iwurl'] );
753 $fit = $fit && $result->addValue(
'query',
'interwiki', $values );
755 $values = $pageSet->getRedirectTitlesAsResult( $result );
757 $fit = $fit && $result->addValue(
'query',
'redirects', $values );
759 $values = $pageSet->getMissingRevisionIDsAsResult( $result );
761 $fit = $fit && $result->addValue(
'query',
'badrevids', $values );
768 foreach ( $pageSet->getMissingTitles() as $fakeId =>
$title ) {
771 $vals[
'missing'] =
true;
772 if (
$title->isKnown() ) {
773 $vals[
'known'] =
true;
775 $pages[$fakeId] = $vals;
778 foreach ( $pageSet->getInvalidTitlesAndReasons() as $fakeId => $data ) {
779 $pages[$fakeId] = $data + [
'invalid' =>
true ];
782 foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
790 foreach ( $pageSet->getSpecialTitles() as $fakeId =>
$title ) {
793 $vals[
'special'] =
true;
794 if ( !
$title->isKnown() ) {
795 $vals[
'missing'] =
true;
797 $pages[$fakeId] = $vals;
801 foreach ( $pageSet->getGoodTitles() as $pageid =>
$title ) {
803 $vals[
'pageid'] = $pageid;
805 $pages[$pageid] = $vals;
808 if ( count( $pages ) ) {
809 $pageSet->populateGeneratorData( $pages );
812 if ( $this->mParams[
'indexpageids'] ) {
815 $pageIDs = array_map(
'strval', $pageIDs );
817 $fit = $fit && $result->addValue(
'query',
'pageids', $pageIDs );
821 $fit = $fit && $result->addValue(
'query',
'pages', $pages );
825 $this->
dieWithError(
'apierror-badconfig-resulttoosmall',
'badconfig' );
828 if ( $this->mParams[
'export'] ) {
829 $this->
doExport( $pageSet, $result );
839 $titles = $pageSet->getGoodPages();
840 if ( count( $titles ) ) {
842 foreach ( $titles as
$title ) {
849 $exporter = $this->wikiExporterFactory->getWikiExporter( $this->
getDB() );
851 $exporter->setOutputSink( $sink );
852 $exporter->setSchemaVersion( $this->mParams[
'exportschema'] );
853 $exporter->openStream();
854 foreach ( $exportTitles as
$title ) {
855 $exporter->pageByTitle(
$title );
857 $exporter->closeStream();
862 if ( $this->mParams[
'exportnowrap'] ) {
877 ParamValidator::PARAM_ISMULTI =>
true,
878 ParamValidator::PARAM_TYPE =>
'submodule',
881 ParamValidator::PARAM_ISMULTI =>
true,
882 ParamValidator::PARAM_TYPE =>
'submodule',
885 ParamValidator::PARAM_ISMULTI =>
true,
886 ParamValidator::PARAM_TYPE =>
'submodule',
888 'indexpageids' =>
false,
890 'exportnowrap' =>
false,
899 'rawcontinue' =>
false,
902 $result += $this->
getPageSet()->getFinalParams( $flags );
915 $allowedParams = [
'rawcontinue' => 1,
'indexpageids' => 1 ];
919 $needed = $param ===
'meta';
920 if ( !isset( $allowedParams[$param] ) && $request->getCheck( $param ) !== $needed ) {
930 if ( $module->isReadMode() ) {
940 'action=query&prop=revisions&meta=siteinfo&' .
941 'titles=Main%20Page&rvprop=user|comment&continue='
942 =>
'apihelp-query-example-revisions',
943 'action=query&generator=allpages&gapprefix=API/&prop=revisions&continue='
944 =>
'apihelp-query-example-allpages',
950 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Query',
951 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Meta',
952 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Properties',
953 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Lists',
This abstract class implements many basic API functions, and is the base of all API classes.
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
getDB()
Gets a default replica DB connection object.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
dieWithErrorOrDebug( $msg, $code=null, $data=null, $httpCode=null)
Will only set a warning instead of failing if the global $wgDebugAPI is set to true.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
getMain()
Get the main module.
setContinuationManager(ApiContinuationManager $manager=null)
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
This manages continuation state.
This is the main API class, used for both external and internal processing.
This class holds a list of modules and handles instantiation.
This class contains a list of pages that the client has requested.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
This is the main query class.
isReadMode()
Indicates whether this module requires read rights.
const QUERY_PROP_MODULES
List of Api Query prop modules.
instantiateModules(&$modules, $param)
Create instances of all modules requested by the client.
mergeCacheMode( $cacheMode, $modCacheMode)
Update a cache mode string, applying the cache mode of a new module to it.
getAllowedParams( $flags=0)
getModuleManager()
Overrides to return this instance's module manager.
const QUERY_META_MODULES
List of Api Query meta modules.
outputGeneralPageInfo()
Appends an element for each page in the current pageSet with the most general information (id,...
getExamplesMessages()
Returns usage examples for this module.
__construct(ApiMain $main, $action, ObjectFactory $objectFactory, ILoadBalancer $loadBalancer, WikiExporterFactory $wikiExporterFactory)
doExport( $pageSet, $result)
const QUERY_LIST_MODULES
List of Api Query list modules.
ILoadBalancer $loadBalancer
getHelpUrls()
Return links to more detailed help pages about the module.
getPageSet()
Gets the set of pages the user has requested (or generated)
execute()
Query execution happens in the following steps: #1 Create a PageSet object with any pages requested b...
WikiExporterFactory $wikiExporterFactory
getNamedDB( $name, $db, $groups)
Get the query database connection with the given name.
static stripMetadataNonRecursive( $data, &$metadata=null)
Remove metadata keys from a data array or object, non-recursive.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
const ADD_ON_TOP
For addValue(), setValue() and similar functions, if the value does not exist, add it as the first el...
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
A class containing constants representing the names of configuration variables.
static schemaVersion()
Returns the default export schema version, as defined by the XmlDumpSchemaVersion setting.
static string[] $supportedSchemas
the schema versions supported for output @final