Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 66 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryAuthManagerInfo | |
0.00% |
0 / 65 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
42 | |||
| isReadMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAllowedParams | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2016 Wikimedia Foundation and contributors |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @since 1.27 |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\Api; |
| 11 | |
| 12 | use MediaWiki\Auth\AuthManager; |
| 13 | use MediaWiki\MainConfigNames; |
| 14 | use Wikimedia\ParamValidator\ParamValidator; |
| 15 | |
| 16 | /** |
| 17 | * A query action to return meta information about AuthManager state. |
| 18 | * |
| 19 | * @ingroup API |
| 20 | */ |
| 21 | class ApiQueryAuthManagerInfo extends ApiQueryBase { |
| 22 | |
| 23 | private AuthManager $authManager; |
| 24 | |
| 25 | public function __construct( |
| 26 | ApiQuery $query, |
| 27 | string $moduleName, |
| 28 | AuthManager $authManager |
| 29 | ) { |
| 30 | parent::__construct( $query, $moduleName, 'ami' ); |
| 31 | $this->authManager = $authManager; |
| 32 | } |
| 33 | |
| 34 | public function execute() { |
| 35 | $params = $this->extractRequestParams(); |
| 36 | $helper = new ApiAuthManagerHelper( $this, $this->authManager ); |
| 37 | $ret = [ |
| 38 | 'canauthenticatenow' => $this->authManager->canAuthenticateNow(), |
| 39 | 'cancreateaccounts' => $this->authManager->canCreateAccounts(), |
| 40 | 'canlinkaccounts' => $this->authManager->canLinkAccounts(), |
| 41 | ]; |
| 42 | |
| 43 | if ( $params['securitysensitiveoperation'] !== null ) { |
| 44 | $ret['securitysensitiveoperationstatus'] = $this->authManager->securitySensitiveOperationStatus( |
| 45 | $params['securitysensitiveoperation'] |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | if ( $params['requestsfor'] ) { |
| 50 | $action = $params['requestsfor']; |
| 51 | |
| 52 | $preservedReq = $helper->getPreservedRequest(); |
| 53 | if ( $preservedReq ) { |
| 54 | $ret += [ |
| 55 | 'haspreservedstate' => $preservedReq->hasStateForAction( $action ), |
| 56 | 'hasprimarypreservedstate' => $preservedReq->hasPrimaryStateForAction( $action ), |
| 57 | 'preservedusername' => (string)$preservedReq->username, |
| 58 | ]; |
| 59 | } else { |
| 60 | $ret += [ |
| 61 | 'haspreservedstate' => false, |
| 62 | 'hasprimarypreservedstate' => false, |
| 63 | 'preservedusername' => '', |
| 64 | ]; |
| 65 | } |
| 66 | |
| 67 | $reqs = $this->authManager->getAuthenticationRequests( $action, $this->getUser() ); |
| 68 | |
| 69 | // Filter out blacklisted requests, depending on the action |
| 70 | switch ( $action ) { |
| 71 | case AuthManager::ACTION_CHANGE: |
| 72 | $reqs = ApiAuthManagerHelper::blacklistAuthenticationRequests( $reqs, |
| 73 | $this->getConfig()->get( MainConfigNames::ChangeCredentialsBlacklist ) |
| 74 | ); |
| 75 | break; |
| 76 | case AuthManager::ACTION_REMOVE: |
| 77 | $reqs = ApiAuthManagerHelper::blacklistAuthenticationRequests( $reqs, |
| 78 | $this->getConfig()->get( MainConfigNames::RemoveCredentialsBlacklist ) |
| 79 | ); |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | $ret += $helper->formatRequests( $reqs ); |
| 84 | } |
| 85 | |
| 86 | $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $ret ); |
| 87 | } |
| 88 | |
| 89 | /** @inheritDoc */ |
| 90 | public function isReadMode() { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | /** @inheritDoc */ |
| 95 | public function getAllowedParams() { |
| 96 | return [ |
| 97 | 'securitysensitiveoperation' => null, |
| 98 | 'requestsfor' => [ |
| 99 | ParamValidator::PARAM_TYPE => [ |
| 100 | AuthManager::ACTION_LOGIN, |
| 101 | AuthManager::ACTION_LOGIN_CONTINUE, |
| 102 | AuthManager::ACTION_CREATE, |
| 103 | AuthManager::ACTION_CREATE_CONTINUE, |
| 104 | AuthManager::ACTION_LINK, |
| 105 | AuthManager::ACTION_LINK_CONTINUE, |
| 106 | AuthManager::ACTION_CHANGE, |
| 107 | AuthManager::ACTION_REMOVE, |
| 108 | AuthManager::ACTION_UNLINK, |
| 109 | ], |
| 110 | ], |
| 111 | ] + ApiAuthManagerHelper::getStandardParams( '', 'mergerequestfields', 'messageformat' ); |
| 112 | } |
| 113 | |
| 114 | /** @inheritDoc */ |
| 115 | protected function getExamplesMessages() { |
| 116 | return [ |
| 117 | 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN ) |
| 118 | => 'apihelp-query+authmanagerinfo-example-login', |
| 119 | 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN ) . |
| 120 | '&amimergerequestfields=1' |
| 121 | => 'apihelp-query+authmanagerinfo-example-login-merged', |
| 122 | 'action=query&meta=authmanagerinfo&amisecuritysensitiveoperation=foo' |
| 123 | => 'apihelp-query+authmanagerinfo-example-securitysensitiveoperation', |
| 124 | ]; |
| 125 | } |
| 126 | |
| 127 | /** @inheritDoc */ |
| 128 | public function getHelpUrls() { |
| 129 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Authmanagerinfo'; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** @deprecated class alias since 1.43 */ |
| 134 | class_alias( ApiQueryAuthManagerInfo::class, 'ApiQueryAuthManagerInfo' ); |