3 * Copyright © 2016 Brad Jorsch <bjorsch@wikimedia.org>
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
24 use MediaWiki\Auth\AuthManager
;
27 * A query action to return meta information about AuthManager state.
31 class ApiQueryAuthManagerInfo
extends ApiQueryBase
{
33 public function __construct( ApiQuery
$query, $moduleName ) {
34 parent
::__construct( $query, $moduleName, 'ami' );
37 public function execute() {
38 $params = $this->extractRequestParams();
39 $helper = new ApiAuthManagerHelper( $this );
41 $manager = AuthManager
::singleton();
43 'canauthenticatenow' => $manager->canAuthenticateNow(),
44 'cancreateaccounts' => $manager->canCreateAccounts(),
45 'canlinkaccounts' => $manager->canLinkAccounts(),
46 'haspreservedstate' => $helper->getPreservedRequest() !== null,
49 if ( $params['securitysensitiveoperation'] !== null ) {
50 $ret['securitysensitiveoperationstatus'] = $manager->securitySensitiveOperationStatus(
51 $params['securitysensitiveoperation']
55 if ( $params['requestsfor'] ) {
56 $reqs = $manager->getAuthenticationRequests( $params['requestsfor'], $this->getUser() );
58 // Filter out blacklisted requests, depending on the action
59 switch ( $params['requestsfor'] ) {
60 case AuthManager
::ACTION_CHANGE
:
61 $reqs = ApiAuthManagerHelper
::blacklistAuthenticationRequests(
62 $reqs, $this->getConfig()->get( 'ChangeCredentialsBlacklist' )
65 case AuthManager
::ACTION_REMOVE
:
66 $reqs = ApiAuthManagerHelper
::blacklistAuthenticationRequests(
67 $reqs, $this->getConfig()->get( 'RemoveCredentialsBlacklist' )
72 $ret +
= $helper->formatRequests( $reqs );
75 $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $ret );
78 public function isReadMode() {
82 public function getAllowedParams() {
84 'securitysensitiveoperation' => null,
86 ApiBase
::PARAM_TYPE
=> [
87 AuthManager
::ACTION_LOGIN
,
88 AuthManager
::ACTION_LOGIN_CONTINUE
,
89 AuthManager
::ACTION_CREATE
,
90 AuthManager
::ACTION_CREATE_CONTINUE
,
91 AuthManager
::ACTION_LINK
,
92 AuthManager
::ACTION_LINK_CONTINUE
,
93 AuthManager
::ACTION_CHANGE
,
94 AuthManager
::ACTION_REMOVE
,
95 AuthManager
::ACTION_UNLINK
,
98 ] + ApiAuthManagerHelper
::getStandardParams( '', 'mergerequestfields', 'messageformat' );
101 protected function getExamplesMessages() {
103 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager
::ACTION_LOGIN
)
104 => 'apihelp-query+filerepoinfo-example-login',
105 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager
::ACTION_LOGIN
) .
106 '&amimergerequestfields=1'
107 => 'apihelp-query+filerepoinfo-example-login-merged',
108 'action=query&meta=authmanagerinfo&amisecuritysensitiveoperation=foo'
109 => 'apihelp-query+filerepoinfo-example-securitysensitiveoperation',
113 public function getHelpUrls() {
114 return 'https://www.mediawiki.org/wiki/API:Authmanagerinfo';