18 AuthManager::ACTION_LOGIN, AuthManager::ACTION_LOGIN_CONTINUE,
19 AuthManager::ACTION_CREATE, AuthManager::ACTION_CREATE_CONTINUE,
20 AuthManager::ACTION_LINK, AuthManager::ACTION_LINK_CONTINUE,
21 AuthManager::ACTION_CHANGE, AuthManager::ACTION_REMOVE, AuthManager::ACTION_UNLINK,
64 return $this->savedRequest ?: $this->
getContext()->getRequest();
77 if ( $wasPosted === null ) {
108 $authManager = AuthManager::singleton();
109 $key =
'AuthManagerSpecialPage:return:' . $this->
getName();
116 $authData = array_diff_key( $this->
getRequest()->getValues(),
117 $preservedParams, [
'title' => 1 ] );
118 $authManager->setAuthenticationSessionData( $key, $authData );
125 $authData = $authManager->getAuthenticationSessionData( $key );
127 $authManager->removeAuthenticationSessionData( $key );
128 $this->isReturn =
true;
146 $authManager = AuthManager::singleton();
148 $key =
'AuthManagerSpecialPage:reauth:' . $this->
getName();
151 if ( $securityLevel ) {
152 $securityStatus = AuthManager::singleton()
153 ->securitySensitiveOperationStatus( $securityLevel );
154 if ( $securityStatus === AuthManager::SEC_REAUTH ) {
155 $queryParams = array_diff_key(
$request->getQueryValues(), [
'title' =>
true ] );
160 $key = $key .
':' . $uniqueId;
162 $queryParams = [
'authUniqueId' => $uniqueId ] + $queryParams;
163 $authData = array_diff_key(
$request->getValues(),
165 $authManager->setAuthenticationSessionData( $key, $authData );
169 $url =
$title->getFullURL( [
170 'returnto' => $this->
getFullTitle()->getPrefixedDBkey(),
172 'force' => $securityLevel,
177 } elseif ( $securityStatus !== AuthManager::SEC_OK ) {
178 throw new ErrorPageError(
'cannotauth-not-allowed-title',
'cannotauth-not-allowed' );
182 $uniqueId =
$request->getVal(
'authUniqueId' );
184 $key = $key .
':' . $uniqueId;
185 $authData = $authManager->getAuthenticationSessionData( $key );
187 $authManager->removeAuthenticationSessionData( $key );
202 throw new BadMethodCallException(
'Subclass did not implement getDefaultAction' );
237 !$reset && $this->subPage ===
$subPage && $this->authAction
246 if ( !in_array( $this->authAction, static::$allowedActions,
true ) ) {
250 if ( in_array( $continueAction, static::$allowedActions,
true ) ) {
251 $this->authAction = $continueAction;
256 $allReqs = AuthManager::singleton()->getAuthenticationRequests(
257 $this->authAction, $this->
getUser() );
258 $this->authRequests = array_filter( $allReqs,
function (
$req )
use (
$subPage ) {
268 return in_array( $this->authAction, [
269 AuthManager::ACTION_LOGIN_CONTINUE,
270 AuthManager::ACTION_CREATE_CONTINUE,
271 AuthManager::ACTION_LINK_CONTINUE,
282 case AuthManager::ACTION_LOGIN:
283 $action = AuthManager::ACTION_LOGIN_CONTINUE;
285 case AuthManager::ACTION_CREATE:
286 $action = AuthManager::ACTION_CREATE_CONTINUE;
288 case AuthManager::ACTION_LINK:
289 $action = AuthManager::ACTION_LINK_CONTINUE;
304 $authManager = AuthManager::singleton();
305 if ( !in_array( $action, static::$allowedActions,
true ) ) {
306 throw new InvalidArgumentException(
'invalid action: ' . $action );
311 : $authManager->getAuthenticationRequests( $action );
318 case AuthManager::ACTION_LOGIN:
319 case AuthManager::ACTION_LOGIN_CONTINUE:
320 return $authManager->canAuthenticateNow();
321 case AuthManager::ACTION_CREATE:
322 case AuthManager::ACTION_CREATE_CONTINUE:
323 return $authManager->canCreateAccounts();
324 case AuthManager::ACTION_LINK:
325 case AuthManager::ACTION_LINK_CONTINUE:
326 return $authManager->canLinkAccounts();
327 case AuthManager::ACTION_CHANGE:
328 case AuthManager::ACTION_REMOVE:
329 case AuthManager::ACTION_UNLINK:
333 throw new InvalidArgumentException(
'invalid action: ' . $action );
344 if ( !in_array( $action, static::$allowedActions,
true ) ) {
345 throw new InvalidArgumentException(
'invalid action: ' . $action );
348 $authManager = AuthManager::singleton();
353 case AuthManager::ACTION_LOGIN:
354 return $authManager->beginAuthentication( $requests, $returnToUrl );
355 case AuthManager::ACTION_LOGIN_CONTINUE:
356 return $authManager->continueAuthentication( $requests );
357 case AuthManager::ACTION_CREATE:
358 return $authManager->beginAccountCreation( $this->
getUser(), $requests,
360 case AuthManager::ACTION_CREATE_CONTINUE:
361 return $authManager->continueAccountCreation( $requests );
362 case AuthManager::ACTION_LINK:
363 return $authManager->beginAccountLink( $this->
getUser(), $requests, $returnToUrl );
364 case AuthManager::ACTION_LINK_CONTINUE:
365 return $authManager->continueAccountLink( $requests );
366 case AuthManager::ACTION_CHANGE:
367 case AuthManager::ACTION_REMOVE:
368 case AuthManager::ACTION_UNLINK:
369 if ( count( $requests ) > 1 ) {
370 throw new InvalidArgumentException(
'only one auth request can be changed at a time' );
371 } elseif ( !$requests ) {
372 throw new InvalidArgumentException(
'no auth request' );
374 $req = reset( $requests );
375 $status = $authManager->allowsAuthenticationDataChange(
$req );
378 return AuthenticationResponse::newFail(
$status->getMessage() );
380 $authManager->changeAuthenticationData(
$req );
381 return AuthenticationResponse::newPass();
384 throw new InvalidArgumentException(
'invalid action: ' . $action );
401 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
402 $form->setSubmitCallback( [ $this,
'handleFormSubmit' ] );
408 if ( $sessionToken->wasNew() ) {
410 } elseif ( !$requestTokenValue ) {
412 } elseif ( !$sessionToken->match( $requestTokenValue ) ) {
416 $form->prepareForm();
423 throw new UnexpectedValueException(
'HTMLForm::trySubmit() returned true' );
424 } elseif (
$status ===
false ) {
432 } elseif ( is_string(
$status ) ) {
434 } elseif ( is_array(
$status ) ) {
435 if ( is_string( reset(
$status ) ) ) {
437 } elseif ( is_array( reset(
$status ) ) ) {
440 call_user_func_array( [
$status,
'fatal' ], $message );
443 throw new UnexpectedValueException(
'invalid HTMLForm::trySubmit() return value: '
444 .
'first element of array is ' . gettype( reset(
$status ) ) );
449 throw new UnexpectedValueException(
'invalid HTMLForm::trySubmit() return type: '
458 LoggerFactory::getInstance(
'authmanager' )
459 ->warning(
'Validation error on return', [
'data' => $form->mFieldData,
460 'status' =>
$status->getWikiText() ] );
466 AuthManager::ACTION_CHANGE, AuthManager::ACTION_REMOVE, AuthManager::ACTION_UNLINK
468 if ( in_array( $this->authAction, $changeActions,
true ) &&
$status && !
$status->isOK() ) {
469 Hooks::run(
'ChangeAuthenticationDataAudit', [ reset( $this->authRequests ),
$status ] );
482 $requests = AuthenticationRequest::loadRequestsFromSubmission( $this->authRequests, $data );
514 $fieldInfo = AuthenticationRequest::mergeFieldInfo(
$requests );
519 return $formDescriptor;
538 $form->addHiddenField(
'authAction', $this->authAction );
552 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
553 $form->prepareForm()->displayForm(
$status );
565 return (
bool)array_filter( $formDescriptor,
function ( $item ) {
567 if ( array_key_exists(
'class', $item ) ) {
568 $class = $item[
'class'];
569 } elseif ( array_key_exists(
'type', $item ) ) {
584 foreach ( $formDescriptor
as $field => &$definition ) {
586 if ( array_key_exists(
'class', $definition ) ) {
587 $class = $definition[
'class'];
588 } elseif ( array_key_exists(
'type', $definition ) ) {
591 if ( $class !==
'HTMLInfoField' ) {
592 $definition[
'tabindex'] = $i;
603 return $this->
getRequest()->getSession()->getToken(
'AuthManagerSpecialPage:'
612 return 'wpAuthToken';
625 $formDescriptor = [];
626 foreach ( $fieldInfo
as $fieldName => $singleFieldInfo ) {
627 $formDescriptor[$fieldName] = self::mapSingleFieldInfo( $singleFieldInfo, $fieldName );
630 $requestSnapshot =
serialize( $requests );
632 \Hooks::run(
'AuthChangeFormFields', [ $requests, $fieldInfo, &$formDescriptor, $action ] );
633 if ( $requestSnapshot !==
serialize( $requests ) ) {
634 LoggerFactory::getInstance(
'authentication' )->warning(
635 'AuthChangeFormFields hook changed auth requests' );
640 self::sortFormDescriptorFields( $formDescriptor );
642 return $formDescriptor;
652 $type = self::mapFieldInfoTypeToFormDescriptorType( $singleFieldInfo[
'type'] );
656 'name' => $fieldName,
659 if (
$type ===
'submit' && isset( $singleFieldInfo[
'label'] ) ) {
660 $descriptor[
'default'] =
wfMessage( $singleFieldInfo[
'label'] )->plain();
661 } elseif (
$type !==
'submit' ) {
662 $descriptor += array_filter( [
664 'label-message' => self::getField( $singleFieldInfo,
'label' ),
667 if ( isset( $singleFieldInfo[
'options'] ) ) {
668 $descriptor[
'options'] = array_flip( array_map(
function ( $message ) {
670 return $message->parse();
671 }, $singleFieldInfo[
'options'] ) );
674 if ( isset( $singleFieldInfo[
'value'] ) ) {
675 $descriptor[
'default'] = $singleFieldInfo[
'value'];
678 if ( empty( $singleFieldInfo[
'optional'] ) ) {
679 $descriptor[
'required'] =
true;
695 foreach ( $formDescriptor
as &$field ) {
696 $field[
'__index'] = $i++;
698 uasort( $formDescriptor,
function ( $first, $second ) {
699 return self::getField( $first,
'weight', 0 ) - self::getField( $second,
'weight', 0 )
700 ?: $first[
'__index'] - $second[
'__index'];
702 foreach ( $formDescriptor
as &$field ) {
703 unset( $field[
'__index'] );
714 protected static function getField(
array $array, $fieldName, $default = null ) {
715 if ( array_key_exists( $fieldName, $array ) ) {
716 return $array[$fieldName];
731 'password' =>
'password',
732 'select' =>
'select',
733 'checkbox' =>
'check',
734 'multiselect' =>
'multiselect',
735 'button' =>
'submit',
736 'hidden' =>
'hidden',
739 if ( !array_key_exists(
$type, $map ) ) {
740 throw new \LogicException(
'invalid field type: ' .
$type );
static array $messages
Customized messages.
the array() calling protocol came about after MediaWiki 1.4rc1.
static wrap($sv)
Succinct helper method to wrap a StatusValue.
A special page subclass for authentication-related special pages.
getContext()
Gets the context this SpecialPage is executed in.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
needsSubmitButton($formDescriptor)
Returns true if the form has fields which take values.
messageKey($defaultKey)
Return custom message key.
static string[] $allowedActions
The list of actions this special page deals with.
An IContextSource implementation which will inherit context from another source but allow individual ...
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Generic operation result class Has warning/error list, boolean status and arbitrary value...
static mapFieldInfoTypeToFormDescriptorType($type)
Maps AuthenticationRequest::getFieldInfo() types to HTMLForm types.
getToken()
Returns the CSRF token.
getOutput()
Get the OutputPage being used for this instance.
this hook is for auditing only $response
static newFatal($message)
Factory function for fatal errors.
displayForm($status)
Display the form.
getRequestBlacklist()
Allows blacklisting certain request types.
setRequest(array $data, $wasPosted=null)
Override the POST data, GET data from the real request is preserved.
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
isActionAllowed($action)
Checks whether AuthManager is ready to perform the action.
bool $isReturn
True if the current request is a result of returning from a redirect flow.
Parent class for all special pages.
isContinued()
Returns true if this is not the first step of the authentication.
getContinueAction($action)
Gets the _CONTINUE version of an action.
addTabIndex(&$formDescriptor)
Adds a sequential tabindex starting from 1 to all form elements.
handleReturnBeforeExecute($subPage)
Handle redirection from the /return subpage.
An error page which can definitely be safely rendered using the OutputPage.
getPreservedParams($withToken=false)
Returns URL query parameters which can be used to reload the page (or leave and return) while preserv...
performAuthenticationStep($action, array $requests)
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 just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $title
Generic operation result class Has warning/error list, boolean status and arbitrary value...
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
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
loadAuth($subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
WebRequest null $savedRequest
If set, will be used instead of the real request.
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
Change the form descriptor that determines how a field will look in the authentication form...
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object the(raw HTML) error message to display(added in 1.13) &$status hooks can tweak the array to change how login etc forms should look $requests
AuthenticationRequest[] $authRequests
static getField(array $array, $fieldName, $default=null)
Get an array value, or a default if it does not exist.
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
handleReauthBeforeExecute($subPage)
Handle redirection when the user needs to (re)authenticate.
static mapSingleFieldInfo($singleFieldInfo, $fieldName)
Maps an authentication field configuration for a single field (as returned by AuthenticationRequest::...
getTokenName()
Returns the name of the CSRF token (under which it should be found in the POST or GET data)...
error also a ContextSource you ll probably need to make sure the header is varied on $request
getName()
Get the name of this Special Page.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
getDefaultAction($subPage)
Get the default action for this special page, if none is given via URL/POST data. ...
Variant of the Message class.
getUser()
Shortcut to get the User executing this instance.
wfArrayToCgi($array1, $array2=null, $prefix= '')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.
static generateHex($chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format...
static sortFormDescriptorFields(array &$formDescriptor)
Sort the fields of a form descriptor by their 'weight' property.
fieldInfoToFormDescriptor(array $requests, array $fieldInfo, $action)
Turns a field info array into a form descriptor.
getAuthForm(array $requests, $action)
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
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
getFullTitle()
Return the full title, including $par.
handleFormSubmit($data)
Submit handler callback for HTMLForm.
string $subPage
Subpage of the special page.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
static newGood($value=null)
Factory function for good results.
getAuthFormDescriptor($requests, $action)
Generates a HTMLForm descriptor array from a set of authentication requests.
string $authAction
one of the AuthManager::ACTION_* constants.
getPageTitle($subpage=false)
Get a self-referential title object.
trySubmit()
Attempts to do an authentication step with the submitted data.