MediaWiki master
ApiQueryAuthManagerInfo.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Api;
25
29
36
37 private AuthManager $authManager;
38
39 public function __construct(
40 ApiQuery $query,
41 string $moduleName,
42 AuthManager $authManager
43 ) {
44 parent::__construct( $query, $moduleName, 'ami' );
45 $this->authManager = $authManager;
46 }
47
48 public function execute() {
50 $helper = new ApiAuthManagerHelper( $this, $this->authManager );
51 $ret = [
52 'canauthenticatenow' => $this->authManager->canAuthenticateNow(),
53 'cancreateaccounts' => $this->authManager->canCreateAccounts(),
54 'canlinkaccounts' => $this->authManager->canLinkAccounts(),
55 ];
56
57 if ( $params['securitysensitiveoperation'] !== null ) {
58 $ret['securitysensitiveoperationstatus'] = $this->authManager->securitySensitiveOperationStatus(
59 $params['securitysensitiveoperation']
60 );
61 }
62
63 if ( $params['requestsfor'] ) {
64 $action = $params['requestsfor'];
65
66 $preservedReq = $helper->getPreservedRequest();
67 if ( $preservedReq ) {
68 $ret += [
69 'haspreservedstate' => $preservedReq->hasStateForAction( $action ),
70 'hasprimarypreservedstate' => $preservedReq->hasPrimaryStateForAction( $action ),
71 'preservedusername' => (string)$preservedReq->username,
72 ];
73 } else {
74 $ret += [
75 'haspreservedstate' => false,
76 'hasprimarypreservedstate' => false,
77 'preservedusername' => '',
78 ];
79 }
80
81 $reqs = $this->authManager->getAuthenticationRequests( $action, $this->getUser() );
82
83 // Filter out blacklisted requests, depending on the action
84 switch ( $action ) {
85 case AuthManager::ACTION_CHANGE:
88 );
89 break;
90 case AuthManager::ACTION_REMOVE:
93 );
94 break;
95 }
96
97 $ret += $helper->formatRequests( $reqs );
98 }
99
100 $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $ret );
101 }
102
103 public function isReadMode() {
104 return false;
105 }
106
107 public function getAllowedParams() {
108 return [
109 'securitysensitiveoperation' => null,
110 'requestsfor' => [
111 ParamValidator::PARAM_TYPE => [
112 AuthManager::ACTION_LOGIN,
113 AuthManager::ACTION_LOGIN_CONTINUE,
114 AuthManager::ACTION_CREATE,
115 AuthManager::ACTION_CREATE_CONTINUE,
116 AuthManager::ACTION_LINK,
117 AuthManager::ACTION_LINK_CONTINUE,
118 AuthManager::ACTION_CHANGE,
119 AuthManager::ACTION_REMOVE,
120 AuthManager::ACTION_UNLINK,
121 ],
122 ],
123 ] + ApiAuthManagerHelper::getStandardParams( '', 'mergerequestfields', 'messageformat' );
124 }
125
126 protected function getExamplesMessages() {
127 return [
128 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN )
129 => 'apihelp-query+authmanagerinfo-example-login',
130 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN ) .
131 '&amimergerequestfields=1'
132 => 'apihelp-query+authmanagerinfo-example-login-merged',
133 'action=query&meta=authmanagerinfo&amisecuritysensitiveoperation=foo'
134 => 'apihelp-query+authmanagerinfo-example-securitysensitiveoperation',
135 ];
136 }
137
138 public function getHelpUrls() {
139 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Authmanagerinfo';
140 }
141}
142
144class_alias( ApiQueryAuthManagerInfo::class, 'ApiQueryAuthManagerInfo' );
array $params
The job parameters.
Helper class for AuthManager-using API modules.
static getStandardParams( $action,... $wantedParams)
Fetch the standard parameters this helper recognizes.
static blacklistAuthenticationRequests(array $reqs, array $remove)
Filter out authentication requests by class name.
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:571
getResult()
Get the result object.
Definition ApiBase.php:710
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:851
A query action to return meta information about AuthManager state.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
__construct(ApiQuery $query, string $moduleName, AuthManager $authManager)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
isReadMode()
Indicates whether this module requires read rights.
getHelpUrls()
Return links to more detailed help pages about the module.
This is a base class for all Query modules.
This is the main query class.
Definition ApiQuery.php:48
This serves as the entry point to the authentication system.
A class containing constants representing the names of configuration variables.
const RemoveCredentialsBlacklist
Name constant for the RemoveCredentialsBlacklist setting, for use with Config::get()
const ChangeCredentialsBlacklist
Name constant for the ChangeCredentialsBlacklist setting, for use with Config::get()
Service for formatting and validating API parameters.