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' );
238 !$reset && $this->subPage ===
$subPage && $this->authAction
247 if ( !in_array( $this->authAction, static::$allowedActions,
true ) ) {
251 if ( in_array( $continueAction, static::$allowedActions,
true ) ) {
252 $this->authAction = $continueAction;
257 $allReqs = AuthManager::singleton()->getAuthenticationRequests(
258 $this->authAction, $this->
getUser() );
259 $this->authRequests = array_filter( $allReqs,
function (
$req )
use (
$subPage ) {
269 return in_array( $this->authAction, [
270 AuthManager::ACTION_LOGIN_CONTINUE,
271 AuthManager::ACTION_CREATE_CONTINUE,
272 AuthManager::ACTION_LINK_CONTINUE,
283 case AuthManager::ACTION_LOGIN:
284 $action = AuthManager::ACTION_LOGIN_CONTINUE;
286 case AuthManager::ACTION_CREATE:
287 $action = AuthManager::ACTION_CREATE_CONTINUE;
289 case AuthManager::ACTION_LINK:
290 $action = AuthManager::ACTION_LINK_CONTINUE;
305 $authManager = AuthManager::singleton();
306 if ( !in_array( $action, static::$allowedActions,
true ) ) {
312 : $authManager->getAuthenticationRequests( $action );
319 case AuthManager::ACTION_LOGIN:
320 case AuthManager::ACTION_LOGIN_CONTINUE:
321 return $authManager->canAuthenticateNow();
322 case AuthManager::ACTION_CREATE:
323 case AuthManager::ACTION_CREATE_CONTINUE:
324 return $authManager->canCreateAccounts();
325 case AuthManager::ACTION_LINK:
326 case AuthManager::ACTION_LINK_CONTINUE:
327 return $authManager->canLinkAccounts();
328 case AuthManager::ACTION_CHANGE:
329 case AuthManager::ACTION_REMOVE:
330 case AuthManager::ACTION_UNLINK:
345 if ( !in_array( $action, static::$allowedActions,
true ) ) {
349 $authManager = AuthManager::singleton();
354 case AuthManager::ACTION_LOGIN:
355 return $authManager->beginAuthentication( $requests, $returnToUrl );
356 case AuthManager::ACTION_LOGIN_CONTINUE:
357 return $authManager->continueAuthentication( $requests );
358 case AuthManager::ACTION_CREATE:
359 return $authManager->beginAccountCreation( $this->
getUser(), $requests,
361 case AuthManager::ACTION_CREATE_CONTINUE:
362 return $authManager->continueAccountCreation( $requests );
363 case AuthManager::ACTION_LINK:
364 return $authManager->beginAccountLink( $this->
getUser(), $requests, $returnToUrl );
365 case AuthManager::ACTION_LINK_CONTINUE:
366 return $authManager->continueAccountLink( $requests );
367 case AuthManager::ACTION_CHANGE:
368 case AuthManager::ACTION_REMOVE:
369 case AuthManager::ACTION_UNLINK:
370 if ( count( $requests ) > 1 ) {
372 } elseif ( !$requests ) {
375 $req = reset( $requests );
376 $status = $authManager->allowsAuthenticationDataChange(
$req );
379 return AuthenticationResponse::newFail(
$status->getMessage() );
381 $authManager->changeAuthenticationData(
$req );
382 return AuthenticationResponse::newPass();
402 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
403 $form->setSubmitCallback( [ $this,
'handleFormSubmit' ] );
409 if ( $sessionToken->wasNew() ) {
411 } elseif ( !$requestTokenValue ) {
413 } elseif ( !$sessionToken->match( $requestTokenValue ) ) {
417 $form->prepareForm();
425 } elseif (
$status ===
false ) {
433 } elseif ( is_string(
$status ) ) {
435 } elseif ( is_array(
$status ) ) {
436 if ( is_string( reset(
$status ) ) ) {
438 } elseif ( is_array( reset(
$status ) ) ) {
441 call_user_func_array( [
$status,
'fatal' ], $message );
445 .
'first element of array is ' . gettype( reset(
$status ) ) );
459 LoggerFactory::getInstance(
'authentication' )
460 ->warning(
'Validation error on return', [
'data' => $form->mFieldData,
461 'status' =>
$status->getWikiText() ] );
467 AuthManager::ACTION_CHANGE, AuthManager::ACTION_REMOVE, AuthManager::ACTION_UNLINK
469 if ( in_array( $this->authAction, $changeActions,
true ) &&
$status && !
$status->isOK() ) {
470 Hooks::run(
'ChangeAuthenticationDataAudit', [ reset( $this->authRequests ),
$status ] );
483 $requests = AuthenticationRequest::loadRequestsFromSubmission( $this->authRequests, $data );
515 $fieldInfo = AuthenticationRequest::mergeFieldInfo(
$requests );
520 return $formDescriptor;
539 $form->addHiddenField(
'authAction', $this->authAction );
553 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
554 $form->prepareForm()->displayForm(
$status );
568 $customSubmitButtonPresent =
false;
574 foreach ( $requests
as $req ) {
575 if ( $req->required === AuthenticationRequest::PRIMARY_REQUIRED ) {
577 $customSubmitButtonPresent =
true;
583 return !$customSubmitButtonPresent;
593 if ( $info[
'type'] ===
'button' ) {
607 foreach ( $formDescriptor
as $field => &$definition ) {
609 if ( array_key_exists(
'class', $definition ) ) {
610 $class = $definition[
'class'];
611 } elseif ( array_key_exists(
'type', $definition ) ) {
614 if ( $class !==
'HTMLInfoField' ) {
615 $definition[
'tabindex'] = $i;
626 return $this->
getRequest()->getSession()->getToken(
'AuthManagerSpecialPage:'
635 return 'wpAuthToken';
648 $formDescriptor = [];
649 foreach ( $fieldInfo
as $fieldName => $singleFieldInfo ) {
650 $formDescriptor[$fieldName] = self::mapSingleFieldInfo( $singleFieldInfo, $fieldName );
653 $requestSnapshot =
serialize( $requests );
655 \Hooks::run(
'AuthChangeFormFields', [ $requests, $fieldInfo, &$formDescriptor, $action ] );
656 if ( $requestSnapshot !==
serialize( $requests ) ) {
657 LoggerFactory::getInstance(
'authentication' )->warning(
658 'AuthChangeFormFields hook changed auth requests' );
663 self::sortFormDescriptorFields( $formDescriptor );
665 return $formDescriptor;
676 $type = self::mapFieldInfoTypeToFormDescriptorType( $singleFieldInfo[
'type'] );
680 'name' => $fieldName,
683 if (
$type ===
'submit' && isset( $singleFieldInfo[
'label'] ) ) {
684 $descriptor[
'default'] =
wfMessage( $singleFieldInfo[
'label'] )->plain();
685 } elseif (
$type !==
'submit' ) {
686 $descriptor += array_filter( [
688 'label-message' => self::getField( $singleFieldInfo,
'label' ),
691 if ( isset( $singleFieldInfo[
'options'] ) ) {
692 $descriptor[
'options'] = array_flip( array_map(
function ( $message ) {
694 return $message->parse();
695 }, $singleFieldInfo[
'options'] ) );
698 if ( isset( $singleFieldInfo[
'value'] ) ) {
699 $descriptor[
'default'] = $singleFieldInfo[
'value'];
702 if ( empty( $singleFieldInfo[
'optional'] ) ) {
703 $descriptor[
'required'] =
true;
719 foreach ( $formDescriptor
as &$field ) {
720 $field[
'__index'] = $i++;
722 uasort( $formDescriptor,
function ( $first, $second ) {
723 return self::getField( $first,
'weight', 0 ) - self::getField( $second,
'weight', 0 )
724 ?: $first[
'__index'] - $second[
'__index'];
726 foreach ( $formDescriptor
as &$field ) {
727 unset( $field[
'__index'] );
738 protected static function getField(
array $array, $fieldName, $default = null ) {
739 if ( array_key_exists( $fieldName, $array ) ) {
740 return $array[$fieldName];
755 'password' =>
'password',
756 'select' =>
'select',
757 'checkbox' =>
'check',
758 'multiselect' =>
'multiselect',
759 'button' =>
'submit',
760 'hidden' =>
'hidden',
763 if ( !array_key_exists(
$type, $map ) ) {
764 throw new \LogicException(
'invalid field type: ' .
$type );
static array $messages
Customized messages.
the array() calling protocol came about after MediaWiki 1.4rc1.
hasOwnSubmitButton(AuthenticationRequest $req)
Checks whether the given AuthenticationRequest has its own submit button.
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 If you don't need a full Title object...
static newFatal($message)
Factory function for fatal errors.
needsSubmitButton(array $requests)
Returns true if the form built from the given AuthenticationRequests needs a submit button...
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...
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
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.
either a unescaped string or a HtmlArmor object 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"<
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)
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 hooks can tweak the array to change how login etc forms should look $requests
namespace and then decline to actually register it file or subcat img or subcat $title
static newGood($value=null)
Factory function for good results.
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...
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.
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
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.