MediaWiki  master
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 }
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:72
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
ApiAuthManagerHelper\blacklistAuthenticationRequests
static blacklistAuthenticationRequests(array $reqs, array $remove)
Filter out authentication requests by class name.
Definition: ApiAuthManagerHelper.php:131
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:72
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:571
ApiQueryAuthManagerInfo\isReadMode
isReadMode()
Indicates whether this module requires read rights.
Definition: ApiQueryAuthManagerInfo.php:105
ApiAuthManagerHelper\getStandardParams
static getStandardParams( $action,... $wantedParams)
Fetch the standard parameters this helper recognizes.
Definition: ApiAuthManagerHelper.php:363
ContextSource\getUser
getUser()
Definition: ContextSource.php:136
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:37
ApiAuthManagerHelper
Helper class for AuthManager-using API modules.
Definition: ApiAuthManagerHelper.php:37
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:707
ApiQueryAuthManagerInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryAuthManagerInfo.php:128
ApiQueryAuthManagerInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryAuthManagerInfo.php:50
ApiQueryAuthManagerInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryAuthManagerInfo.php:140
ApiQueryAuthManagerInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryAuthManagerInfo.php:109
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:102
ApiQueryAuthManagerInfo
A query action to return meta information about AuthManager state.
Definition: ApiQueryAuthManagerInfo.php:31
ApiQueryAuthManagerInfo\__construct
__construct(ApiQuery $query, $moduleName, AuthManager $authManager)
Definition: ApiQueryAuthManagerInfo.php:41
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:440
ApiQueryAuthManagerInfo\$authManager
AuthManager $authManager
Definition: ApiQueryAuthManagerInfo.php:34