Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / api / ApiQueryAuthManagerInfo.php
blobdff753d0785a4b5f7d8059d146c73f79ad84da44
1 <?php
2 /**
3 * Copyright © 2016 Wikimedia Foundation and contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @since 1.27
24 namespace MediaWiki\Api;
26 use MediaWiki\Auth\AuthManager;
27 use MediaWiki\MainConfigNames;
28 use Wikimedia\ParamValidator\ParamValidator;
30 /**
31 * A query action to return meta information about AuthManager state.
33 * @ingroup API
35 class ApiQueryAuthManagerInfo extends ApiQueryBase {
37 private AuthManager $authManager;
39 public function __construct(
40 ApiQuery $query,
41 string $moduleName,
42 AuthManager $authManager
43 ) {
44 parent::__construct( $query, $moduleName, 'ami' );
45 $this->authManager = $authManager;
48 public function execute() {
49 $params = $this->extractRequestParams();
50 $helper = new ApiAuthManagerHelper( $this, $this->authManager );
51 $ret = [
52 'canauthenticatenow' => $this->authManager->canAuthenticateNow(),
53 'cancreateaccounts' => $this->authManager->canCreateAccounts(),
54 'canlinkaccounts' => $this->authManager->canLinkAccounts(),
57 if ( $params['securitysensitiveoperation'] !== null ) {
58 $ret['securitysensitiveoperationstatus'] = $this->authManager->securitySensitiveOperationStatus(
59 $params['securitysensitiveoperation']
63 if ( $params['requestsfor'] ) {
64 $action = $params['requestsfor'];
66 $preservedReq = $helper->getPreservedRequest();
67 if ( $preservedReq ) {
68 $ret += [
69 'haspreservedstate' => $preservedReq->hasStateForAction( $action ),
70 'hasprimarypreservedstate' => $preservedReq->hasPrimaryStateForAction( $action ),
71 'preservedusername' => (string)$preservedReq->username,
73 } else {
74 $ret += [
75 'haspreservedstate' => false,
76 'hasprimarypreservedstate' => false,
77 'preservedusername' => '',
81 $reqs = $this->authManager->getAuthenticationRequests( $action, $this->getUser() );
83 // Filter out blacklisted requests, depending on the action
84 switch ( $action ) {
85 case AuthManager::ACTION_CHANGE:
86 $reqs = ApiAuthManagerHelper::blacklistAuthenticationRequests( $reqs,
87 $this->getConfig()->get( MainConfigNames::ChangeCredentialsBlacklist )
89 break;
90 case AuthManager::ACTION_REMOVE:
91 $reqs = ApiAuthManagerHelper::blacklistAuthenticationRequests( $reqs,
92 $this->getConfig()->get( MainConfigNames::RemoveCredentialsBlacklist )
94 break;
97 $ret += $helper->formatRequests( $reqs );
100 $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $ret );
103 public function isReadMode() {
104 return false;
107 public function getAllowedParams() {
108 return [
109 'securitysensitiveoperation' => null,
110 'requestsfor' => [
111 ParamValidator::PARAM_TYPE => [
112 AuthManager::ACTION_LOGIN,
113 AuthManager::ACTION_LOGIN_CONTINUE,
114 AuthManager::ACTION_CREATE,
115 AuthManager::ACTION_CREATE_CONTINUE,
116 AuthManager::ACTION_LINK,
117 AuthManager::ACTION_LINK_CONTINUE,
118 AuthManager::ACTION_CHANGE,
119 AuthManager::ACTION_REMOVE,
120 AuthManager::ACTION_UNLINK,
123 ] + ApiAuthManagerHelper::getStandardParams( '', 'mergerequestfields', 'messageformat' );
126 protected function getExamplesMessages() {
127 return [
128 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN )
129 => 'apihelp-query+authmanagerinfo-example-login',
130 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN ) .
131 '&amimergerequestfields=1'
132 => 'apihelp-query+authmanagerinfo-example-login-merged',
133 'action=query&meta=authmanagerinfo&amisecuritysensitiveoperation=foo'
134 => 'apihelp-query+authmanagerinfo-example-securitysensitiveoperation',
138 public function getHelpUrls() {
139 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Authmanagerinfo';
143 /** @deprecated class alias since 1.43 */
144 class_alias( ApiQueryAuthManagerInfo::class, 'ApiQueryAuthManagerInfo' );