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