MediaWiki master
ApiQueryAuthManagerInfo.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Api;
11
15
22
23 private AuthManager $authManager;
24
25 public function __construct(
26 ApiQuery $query,
27 string $moduleName,
28 AuthManager $authManager
29 ) {
30 parent::__construct( $query, $moduleName, 'ami' );
31 $this->authManager = $authManager;
32 }
33
34 public function execute() {
35 $params = $this->extractRequestParams();
36 $helper = new ApiAuthManagerHelper( $this, $this->authManager );
37 $ret = [
38 'canauthenticatenow' => $this->authManager->canAuthenticateNow(),
39 'cancreateaccounts' => $this->authManager->canCreateAccounts(),
40 'canlinkaccounts' => $this->authManager->canLinkAccounts(),
41 ];
42
43 if ( $params['securitysensitiveoperation'] !== null ) {
44 $ret['securitysensitiveoperationstatus'] = $this->authManager->securitySensitiveOperationStatus(
45 $params['securitysensitiveoperation']
46 );
47 }
48
49 if ( $params['requestsfor'] ) {
50 $action = $params['requestsfor'];
51
52 $preservedReq = $helper->getPreservedRequest();
53 if ( $preservedReq ) {
54 $ret += [
55 'haspreservedstate' => $preservedReq->hasStateForAction( $action ),
56 'hasprimarypreservedstate' => $preservedReq->hasPrimaryStateForAction( $action ),
57 'preservedusername' => (string)$preservedReq->username,
58 ];
59 } else {
60 $ret += [
61 'haspreservedstate' => false,
62 'hasprimarypreservedstate' => false,
63 'preservedusername' => '',
64 ];
65 }
66
67 $reqs = $this->authManager->getAuthenticationRequests( $action, $this->getUser() );
68
69 // Filter out blacklisted requests, depending on the action
70 switch ( $action ) {
71 case AuthManager::ACTION_CHANGE:
74 );
75 break;
76 case AuthManager::ACTION_REMOVE:
79 );
80 break;
81 }
82
83 $ret += $helper->formatRequests( $reqs );
84 }
85
86 $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $ret );
87 }
88
90 public function isReadMode() {
91 return false;
92 }
93
95 public function getAllowedParams() {
96 return [
97 'securitysensitiveoperation' => null,
98 'requestsfor' => [
99 ParamValidator::PARAM_TYPE => [
100 AuthManager::ACTION_LOGIN,
101 AuthManager::ACTION_LOGIN_CONTINUE,
102 AuthManager::ACTION_CREATE,
103 AuthManager::ACTION_CREATE_CONTINUE,
104 AuthManager::ACTION_LINK,
105 AuthManager::ACTION_LINK_CONTINUE,
106 AuthManager::ACTION_CHANGE,
107 AuthManager::ACTION_REMOVE,
108 AuthManager::ACTION_UNLINK,
109 ],
110 ],
111 ] + ApiAuthManagerHelper::getStandardParams( '', 'mergerequestfields', 'messageformat' );
112 }
113
115 protected function getExamplesMessages() {
116 return [
117 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN )
118 => 'apihelp-query+authmanagerinfo-example-login',
119 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN ) .
120 '&amimergerequestfields=1'
121 => 'apihelp-query+authmanagerinfo-example-login-merged',
122 'action=query&meta=authmanagerinfo&amisecuritysensitiveoperation=foo'
123 => 'apihelp-query+authmanagerinfo-example-securitysensitiveoperation',
124 ];
125 }
126
128 public function getHelpUrls() {
129 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Authmanagerinfo';
130 }
131}
132
134class_alias( ApiQueryAuthManagerInfo::class, 'ApiQueryAuthManagerInfo' );
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:543
getResult()
Get the result object.
Definition ApiBase.php:682
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:823
A query action to return meta information about AuthManager state.
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
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.to override bool
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
This is a base class for all Query modules.
This is the main query class.
Definition ApiQuery.php:36
AuthManager is the authentication system in MediaWiki and serves entry point for authentication.
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.