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(),
164 $this->getPreservedParams(
false ), [
'title' => 1 ] );
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' );
212 return array_key_exists( $defaultKey, static::$messages )
213 ? static::$messages[$defaultKey] : $defaultKey;
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 ) ) {
307 throw new InvalidArgumentException(
'invalid action: ' . $action );
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:
334 throw new InvalidArgumentException(
'invalid action: ' . $action );
345 if ( !in_array( $action, static::$allowedActions,
true ) ) {
346 throw new InvalidArgumentException(
'invalid action: ' . $action );
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:
371 throw new InvalidArgumentException(
'only one auth request can be changed at a time' );
373 throw new InvalidArgumentException(
'no auth request' );
376 $status = $authManager->allowsAuthenticationDataChange(
$req );
377 Hooks::run(
'ChangeAuthenticationDataAudit', [
$req,
$status ] );
379 return AuthenticationResponse::newFail(
$status->getMessage() );
381 $authManager->changeAuthenticationData(
$req );
382 return AuthenticationResponse::newPass();
385 throw new InvalidArgumentException(
'invalid action: ' . $action );
402 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
403 $form->setSubmitCallback( [ $this,
'handleFormSubmit' ] );
409 if ( $sessionToken->wasNew() ) {
410 return Status::newFatal( $this->
messageKey(
'authform-newtoken' ) );
411 } elseif ( !$requestTokenValue ) {
412 return Status::newFatal( $this->
messageKey(
'authform-notoken' ) );
413 } elseif ( !$sessionToken->match( $requestTokenValue ) ) {
414 return Status::newFatal( $this->
messageKey(
'authform-wrongtoken' ) );
417 $form->prepareForm();
424 throw new UnexpectedValueException(
'HTMLForm::trySubmit() returned true' );
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 );
444 throw new UnexpectedValueException(
'invalid HTMLForm::trySubmit() return value: '
445 .
'first element of array is ' . gettype( reset(
$status ) ) );
450 throw new UnexpectedValueException(
'invalid HTMLForm::trySubmit() return type: '
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;
531 if (
$context->getRequest() !== $this->getRequest() ) {
539 $form->addHiddenField(
'authAction', $this->authAction );
553 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
554 $form->prepareForm()->displayForm(
$status );
568 $customSubmitButtonPresent =
false;
575 if (
$req->required === AuthenticationRequest::PRIMARY_REQUIRED ) {
577 $customSubmitButtonPresent =
true;
583 return !$customSubmitButtonPresent;
592 foreach (
$req->getFieldInfo()
as $field => $info ) {
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 ) {
655 \Hooks::run(
'AuthChangeFormFields', [
$requests, $fieldInfo, &$formDescriptor, $action ] );
657 LoggerFactory::getInstance(
'authentication' )->warning(
658 'AuthChangeFormFields hook changed auth requests' );
665 return $formDescriptor;
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 ) {
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 );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
A special page subclass for authentication-related special pages.
getContinueAction( $action)
Gets the _CONTINUE version of an action.
handleReturnBeforeExecute( $subPage)
Handle redirection from the /return subpage.
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...
handleReauthBeforeExecute( $subPage)
Handle redirection when the user needs to (re)authenticate.
beforeExecute( $subPage)
Gets called before.
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
WebRequest null $savedRequest
If set, will be used instead of the real request.
string $authAction
one of the AuthManager::ACTION_* constants.
performAuthenticationStep( $action, array $requests)
getAuthForm(array $requests, $action)
displayForm( $status)
Display the form.
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
bool $isReturn
True if the current request is a result of returning from a redirect flow.
static mapFieldInfoTypeToFormDescriptorType( $type)
Maps AuthenticationRequest::getFieldInfo() types to HTMLForm types.
fieldInfoToFormDescriptor(array $requests, array $fieldInfo, $action)
Turns a field info array into a form descriptor.
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
handleFormSubmit( $data)
Submit handler callback for HTMLForm.
static array $messages
Customized messages.
AuthenticationRequest[] $authRequests
needsSubmitButton(array $requests)
Returns true if the form built from the given AuthenticationRequests needs a submit button.
string $subPage
Subpage of the special page.
isContinued()
Returns true if this is not the first step of the authentication.
hasOwnSubmitButton(AuthenticationRequest $req)
Checks whether the given AuthenticationRequest has its own submit button.
getRequestBlacklist()
Allows blacklisting certain request types.
static mapSingleFieldInfo( $singleFieldInfo, $fieldName)
Maps an authentication field configuration for a single field (as returned by AuthenticationRequest::...
static getField(array $array, $fieldName, $default=null)
Get an array value, or a default if it does not exist.
getRequest()
Get the WebRequest being used for this instance.
messageKey( $defaultKey)
Return custom message key.
setRequest(array $data, $wasPosted=null)
Override the POST data, GET data from the real request is preserved.
trySubmit()
Attempts to do an authentication step with the submitted data.
getToken()
Returns the CSRF token.
static sortFormDescriptorFields(array &$formDescriptor)
Sort the fields of a form descriptor by their 'weight' property.
addTabIndex(&$formDescriptor)
Adds a sequential tabindex starting from 1 to all form elements.
getAuthFormDescriptor( $requests, $action)
Generates a HTMLForm descriptor array from a set of authentication requests.
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
Change the form descriptor that determines how a field will look in the authentication form.
getPreservedParams( $withToken=false)
Returns URL query parameters which can be used to reload the page (or leave and return) while preserv...
getTokenName()
Returns the name of the CSRF token (under which it should be found in the POST or GET data).
static string[] $allowedActions
The list of actions this special page deals with.
getRequest()
Get the WebRequest object.
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...
An error page which can definitely be safely rendered using the OutputPage.
static generateHex( $chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
Variant of the Message class.
Parent class for all special pages.
getName()
Get the name of this Special Page.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
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,...
getContext()
Gets the context this SpecialPage is executed in.
getPageTitle( $subpage=false)
Get a self-referential title object.
getFullTitle()
Return the full title, including $par.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
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
this hook is for auditing only $req
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
the array() calling protocol came about after MediaWiki 1.4rc1.
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' 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
namespace and then decline to actually register it file or subcat img or subcat $title
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 unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
error also a ContextSource you ll probably need to make sure the header is varied on $request
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
this hook is for auditing only $response
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