MediaWiki  1.32.5
ApiQueryAuthManagerInfo.php
Go to the documentation of this file.
1 <?php
25 
32 
33  public function __construct( ApiQuery $query, $moduleName ) {
34  parent::__construct( $query, $moduleName, 'ami' );
35  }
36 
37  public function execute() {
38  $params = $this->extractRequestParams();
39  $helper = new ApiAuthManagerHelper( $this );
40 
41  $manager = AuthManager::singleton();
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 }
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
ApiQuery
This is the main query class.
Definition: ApiQuery.php:36
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:87
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:659
ApiQueryAuthManagerInfo\isReadMode
isReadMode()
Indicates whether this module requires read rights.
Definition: ApiQueryAuthManagerInfo.php:94
$params
$params
Definition: styleTest.css.php:44
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ApiAuthManagerHelper\getStandardParams
static getStandardParams( $action, $param)
Fetch the standard parameters this helper recognizes.
Definition: ApiAuthManagerHelper.php:351
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1627
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:33
ApiAuthManagerHelper
Helper class for AuthManager-using API modules.
Definition: ApiAuthManagerHelper.php:36
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:770
ApiQueryAuthManagerInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryAuthManagerInfo.php:117
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
ApiQueryAuthManagerInfo\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryAuthManagerInfo.php:33
ApiQueryAuthManagerInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryAuthManagerInfo.php:37
ApiAuthManagerHelper\blacklistAuthenticationRequests
static blacklistAuthenticationRequests(array $reqs, array $blacklist)
Filter out authentication requests by class name.
Definition: ApiAuthManagerHelper.php:121
ApiQueryAuthManagerInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryAuthManagerInfo.php:129
ApiQueryAuthManagerInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryAuthManagerInfo.php:98
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:2044
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:83
ApiQueryAuthManagerInfo
A query action to return meta information about AuthManager state.
Definition: ApiQueryAuthManagerInfo.php:31
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:539