MediaWiki REL1_37
ApiQueryAuthManagerInfo.php
Go to the documentation of this file.
1<?php
25
32
34 private $authManager;
35
41 public function __construct(
42 ApiQuery $query,
43 $moduleName,
45 ) {
46 parent::__construct( $query, $moduleName, 'ami' );
47 $this->authManager = $authManager;
48 }
49
50 public function execute() {
51 $params = $this->extractRequestParams();
52 $helper = new ApiAuthManagerHelper( $this, $this->authManager );
53 $ret = [
54 'canauthenticatenow' => $this->authManager->canAuthenticateNow(),
55 'cancreateaccounts' => $this->authManager->canCreateAccounts(),
56 'canlinkaccounts' => $this->authManager->canLinkAccounts(),
57 ];
58
59 if ( $params['securitysensitiveoperation'] !== null ) {
60 $ret['securitysensitiveoperationstatus'] = $this->authManager->securitySensitiveOperationStatus(
61 $params['securitysensitiveoperation']
62 );
63 }
64
65 if ( $params['requestsfor'] ) {
66 $action = $params['requestsfor'];
67
68 $preservedReq = $helper->getPreservedRequest();
69 if ( $preservedReq ) {
70 $ret += [
71 'haspreservedstate' => $preservedReq->hasStateForAction( $action ),
72 'hasprimarypreservedstate' => $preservedReq->hasPrimaryStateForAction( $action ),
73 'preservedusername' => (string)$preservedReq->username,
74 ];
75 } else {
76 $ret += [
77 'haspreservedstate' => false,
78 'hasprimarypreservedstate' => false,
79 'preservedusername' => '',
80 ];
81 }
82
83 $reqs = $this->authManager->getAuthenticationRequests( $action, $this->getUser() );
84
85 // Filter out blacklisted requests, depending on the action
86 switch ( $action ) {
87 case AuthManager::ACTION_CHANGE:
89 $reqs, $this->getConfig()->get( 'ChangeCredentialsBlacklist' )
90 );
91 break;
92 case AuthManager::ACTION_REMOVE:
94 $reqs, $this->getConfig()->get( 'RemoveCredentialsBlacklist' )
95 );
96 break;
97 }
98
99 $ret += $helper->formatRequests( $reqs );
100 }
101
102 $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $ret );
103 }
104
105 public function isReadMode() {
106 return false;
107 }
108
109 public function getAllowedParams() {
110 return [
111 'securitysensitiveoperation' => null,
112 'requestsfor' => [
114 AuthManager::ACTION_LOGIN,
115 AuthManager::ACTION_LOGIN_CONTINUE,
116 AuthManager::ACTION_CREATE,
117 AuthManager::ACTION_CREATE_CONTINUE,
118 AuthManager::ACTION_LINK,
119 AuthManager::ACTION_LINK_CONTINUE,
120 AuthManager::ACTION_CHANGE,
121 AuthManager::ACTION_REMOVE,
122 AuthManager::ACTION_UNLINK,
123 ],
124 ],
125 ] + ApiAuthManagerHelper::getStandardParams( '', 'mergerequestfields', 'messageformat' );
126 }
127
128 protected function getExamplesMessages() {
129 return [
130 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN )
131 => 'apihelp-query+authmanagerinfo-example-login',
132 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN ) .
133 '&amimergerequestfields=1'
134 => 'apihelp-query+authmanagerinfo-example-login-merged',
135 'action=query&meta=authmanagerinfo&amisecuritysensitiveoperation=foo'
136 => 'apihelp-query+authmanagerinfo-example-securitysensitiveoperation',
137 ];
138 }
139
140 public function getHelpUrls() {
141 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Authmanagerinfo';
142 }
143}
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.
const PARAM_TYPE
Definition ApiBase.php:81
getResult()
Get the result object.
Definition ApiBase.php:628
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:764
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:497
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:37
This serves as the entry point to the authentication system.