MediaWiki REL1_35
ApiQueryAuthManagerInfo.php
Go to the documentation of this file.
1<?php
26
33
34 public function __construct( ApiQuery $query, $moduleName ) {
35 parent::__construct( $query, $moduleName, 'ami' );
36 }
37
38 public function execute() {
39 $params = $this->extractRequestParams();
40 $manager = MediaWikiServices::getInstance()->getAuthManager();
41 $helper = new ApiAuthManagerHelper( $this, $manager );
42 $ret = [
43 'canauthenticatenow' => $manager->canAuthenticateNow(),
44 'cancreateaccounts' => $manager->canCreateAccounts(),
45 'canlinkaccounts' => $manager->canLinkAccounts(),
46 ];
47
48 if ( $params['securitysensitiveoperation'] !== null ) {
49 $ret['securitysensitiveoperationstatus'] = $manager->securitySensitiveOperationStatus(
50 $params['securitysensitiveoperation']
51 );
52 }
53
54 if ( $params['requestsfor'] ) {
55 $action = $params['requestsfor'];
56
57 $preservedReq = $helper->getPreservedRequest();
58 if ( $preservedReq ) {
59 $ret += [
60 'haspreservedstate' => $preservedReq->hasStateForAction( $action ),
61 'hasprimarypreservedstate' => $preservedReq->hasPrimaryStateForAction( $action ),
62 'preservedusername' => (string)$preservedReq->username,
63 ];
64 } else {
65 $ret += [
66 'haspreservedstate' => false,
67 'hasprimarypreservedstate' => false,
68 'preservedusername' => '',
69 ];
70 }
71
72 $reqs = $manager->getAuthenticationRequests( $action, $this->getUser() );
73
74 // Filter out blacklisted requests, depending on the action
75 switch ( $action ) {
76 case AuthManager::ACTION_CHANGE:
78 $reqs, $this->getConfig()->get( 'ChangeCredentialsBlacklist' )
79 );
80 break;
81 case AuthManager::ACTION_REMOVE:
83 $reqs, $this->getConfig()->get( 'RemoveCredentialsBlacklist' )
84 );
85 break;
86 }
87
88 $ret += $helper->formatRequests( $reqs );
89 }
90
91 $this->getResult()->addValue( [ 'query' ], $this->getModuleName(), $ret );
92 }
93
94 public function isReadMode() {
95 return false;
96 }
97
98 public function getAllowedParams() {
99 return [
100 'securitysensitiveoperation' => null,
101 'requestsfor' => [
103 AuthManager::ACTION_LOGIN,
104 AuthManager::ACTION_LOGIN_CONTINUE,
105 AuthManager::ACTION_CREATE,
106 AuthManager::ACTION_CREATE_CONTINUE,
107 AuthManager::ACTION_LINK,
108 AuthManager::ACTION_LINK_CONTINUE,
109 AuthManager::ACTION_CHANGE,
110 AuthManager::ACTION_REMOVE,
111 AuthManager::ACTION_UNLINK,
112 ],
113 ],
114 ] + ApiAuthManagerHelper::getStandardParams( '', 'mergerequestfields', 'messageformat' );
115 }
116
117 protected function getExamplesMessages() {
118 return [
119 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN )
120 => 'apihelp-query+authmanagerinfo-example-login',
121 'action=query&meta=authmanagerinfo&amirequestsfor=' . urlencode( AuthManager::ACTION_LOGIN ) .
122 '&amimergerequestfields=1'
123 => 'apihelp-query+authmanagerinfo-example-login-merged',
124 'action=query&meta=authmanagerinfo&amisecuritysensitiveoperation=foo'
125 => 'apihelp-query+authmanagerinfo-example-securitysensitiveoperation',
126 ];
127 }
128
129 public function getHelpUrls() {
130 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Authmanagerinfo';
131 }
132}
Helper class for AuthManager-using API modules.
static getStandardParams( $action,... $wantedParams)
Fetch the standard parameters this helper recognizes.
static blacklistAuthenticationRequests(array $reqs, array $blacklist)
Filter out authentication requests by class name.
const PARAM_TYPE
Definition ApiBase.php:78
getResult()
Get the result object.
Definition ApiBase.php:620
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:772
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:499
A query action to return meta information about AuthManager state.
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...
__construct(ApiQuery $query, $moduleName)
isReadMode()
Indicates whether this module requires read rights Stable to override.
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:37
getUser()
Stable to override.
This serves as the entry point to the authentication system.
MediaWikiServices is the service locator for the application scope of MediaWiki.