50 $this->messageFormat = isset(
$params[
'messageformat'] ) ?
$params[
'messageformat'] :
'wikitext';
69 switch ( $this->messageFormat ) {
74 $res[$key] = $message->
setContext( $this->module )->text();
78 $res[$key] = $message->
setContext( $this->module )->parseAsBlock();
84 'key' => $message->
getKey(),
97 $status = AuthManager::singleton()->securitySensitiveOperationStatus( $operation );
99 case AuthManager::SEC_OK:
102 case AuthManager::SEC_REAUTH:
103 $this->module->dieUsage(
104 'You have not authenticated recently in this session, please reauthenticate.',
'reauthenticate'
107 case AuthManager::SEC_FAIL:
108 $this->module->dieUsage(
109 'This action is not available as your identify cannot be verified.',
'cannotreauthenticate'
113 throw new UnexpectedValueException(
"Unknown status \"$status\"" );
125 $blacklist = array_flip( $blacklist );
126 $reqs = array_filter( $reqs,
function (
$req )
use ( $blacklist ) {
127 return !isset( $blacklist[get_class(
$req )] );
139 $params = $this->module->extractRequestParams();
141 $manager = AuthManager::singleton();
142 $reqs = $manager->getAuthenticationRequests( $action, $this->module->getUser() );
145 $wantedRequests = null;
146 if ( isset(
$params[
'requests'] ) ) {
147 $wantedRequests = array_flip(
$params[
'requests'] );
148 } elseif ( isset(
$params[
'request'] ) ) {
151 if ( $wantedRequests !== null ) {
152 $reqs = array_filter( $reqs,
function (
$req )
use ( $wantedRequests ) {
153 return isset( $wantedRequests[
$req->getUniqueId()] );
159 foreach ( $reqs
as $req ) {
160 $fields += (
array)$req->getFieldInfo();
165 $data = array_intersect_key( $this->module->getRequest()->getValues(), $fields );
166 $this->module->getMain()->markParamsUsed( array_keys( $data ) );
168 return AuthenticationRequest::loadRequestsFromSubmission( $reqs, $data );
177 $params = $this->module->extractRequestParams();
180 'status' => $res->status,
183 if ( $res->status === AuthenticationResponse::PASS && $res->username !== null ) {
184 $ret[
'username'] = $res->username;
187 if ( $res->status === AuthenticationResponse::REDIRECT ) {
188 $ret[
'redirecttarget'] = $res->redirectTarget;
189 if ( $res->redirectApiData !== null ) {
190 $ret[
'redirectdata'] = $res->redirectApiData;
194 if ( $res->status === AuthenticationResponse::REDIRECT ||
195 $res->status === AuthenticationResponse::UI ||
196 $res->status === AuthenticationResponse::RESTART
201 if ( $res->status === AuthenticationResponse::FAIL ||
202 $res->status === AuthenticationResponse::UI ||
203 $res->status === AuthenticationResponse::RESTART
208 if ( $res->status === AuthenticationResponse::FAIL ||
209 $res->status === AuthenticationResponse::RESTART
211 $this->module->getRequest()->getSession()->set(
212 'ApiAuthManagerHelper::createRequest',
215 $ret[
'canpreservestate'] = $res->createRequest !== null;
217 $this->module->getRequest()->getSession()->remove(
'ApiAuthManagerHelper::createRequest' );
228 $ret = $this->module->getRequest()->getSession()->get(
'ApiAuthManagerHelper::createRequest' );
239 $params = $this->module->extractRequestParams();
240 $mergeFields = !empty(
$params[
'mergerequestfields'] );
242 $ret = [
'requests' => [] ];
243 foreach ( $reqs
as $req ) {
244 $describe = $req->describeCredentials();
246 'id' => $req->getUniqueId(),
249 switch ( $req->required ) {
250 case AuthenticationRequest::OPTIONAL:
251 $reqInfo[
'required'] =
'optional';
253 case AuthenticationRequest::REQUIRED:
254 $reqInfo[
'required'] =
'required';
256 case AuthenticationRequest::PRIMARY_REQUIRED:
257 $reqInfo[
'required'] =
'primary-required';
260 $this->
formatMessage( $reqInfo,
'provider', $describe[
'provider'] );
261 $this->
formatMessage( $reqInfo,
'account', $describe[
'account'] );
262 if ( !$mergeFields ) {
265 $ret[
'requests'][] = $reqInfo;
268 if ( $mergeFields ) {
269 $fields = AuthenticationRequest::mergeFieldInfo( $reqs );
292 foreach ( $fields
as $name => $field ) {
293 $ret = array_intersect_key( $field, $copy );
295 if ( isset( $field[
'options'] ) ) {
297 return $msg->setContext(
$module )->plain();
298 }, $field[
'options'] );
303 $ret[
'optional'] = !empty( $field[
'optional'] );
336 'mergerequestfields' => [
355 $wantedParams = func_get_args();
356 array_shift( $wantedParams );
357 foreach ( $wantedParams
as $name ) {
358 if ( isset(
$params[$name] ) ) {
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
getKey()
Returns the message key.
static getStandardParams($action, $param)
Fetch the standard parameters this helper recognizes.
the array() calling protocol came about after MediaWiki 1.4rc1.
static newForModule(ApiBase $module)
Static version of the constructor, for chaining.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
The Message class provides methods which fulfil two basic services:
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_REQUIRED
(boolean) Is the parameter required?
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
const META_TYPE
Key for the 'type' metadata item.
formatRequests(array $reqs)
Format an array of AuthenticationRequests for return.
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 just before the function returns a value If you return true
getParams()
Returns the message parameters.
static stripOuterParagraph($html)
Strip outer.
ApiBase $module
API module, for context and parameters.
formatMessage(array &$res, $key, Message $message)
Format a message for output.
setContext(IContextSource $context)
Set the language and the title from a context object.
getPreservedRequest()
Fetch the preserved CreateFromLoginAuthenticationRequest, if any.
__construct(ApiBase $module)
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
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
this hook is for auditing only $req
formatFields(array $fields)
Clean up a field array for output.
static blacklistAuthenticationRequests(array $reqs, array $blacklist)
Filter out authentication requests by class name.
securitySensitiveOperation($operation)
Call $manager->securitySensitiveOperationStatus()
formatAuthenticationResponse(AuthenticationResponse $res)
Format an AuthenticationResponse for return.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
This abstract class implements many basic API functions, and is the base of all API classes...
string $messageFormat
Message output format.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Helper class for AuthManager-using API modules.
Allows to change the fields on the form that will be generated $name
loadAuthenticationRequests($action)
Fetch and load the AuthenticationRequests for an action.