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