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,
54 array
$requests, array $fieldInfo, array &$formDescriptor, $action
64 return $this->savedRequest ?: $this->
getContext()->getRequest();
75 protected function setRequest( array $data, $wasPosted =
null ) {
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 );
210 return array_key_exists( $defaultKey, static::$messages )
211 ? static::$messages[$defaultKey] : $defaultKey;
236 !$reset && $this->subPage ===
$subPage && $this->authAction
245 if ( !in_array( $this->authAction, static::$allowedActions,
true ) ) {
249 if ( in_array( $continueAction, static::$allowedActions,
true ) ) {
250 $this->authAction = $continueAction;
255 $allReqs = AuthManager::singleton()->getAuthenticationRequests(
256 $this->authAction, $this->
getUser() );
257 $this->authRequests = array_filter( $allReqs,
function (
$req ) use (
$subPage ) {
267 return in_array( $this->authAction, [
268 AuthManager::ACTION_LOGIN_CONTINUE,
269 AuthManager::ACTION_CREATE_CONTINUE,
270 AuthManager::ACTION_LINK_CONTINUE,
281 case AuthManager::ACTION_LOGIN:
282 $action = AuthManager::ACTION_LOGIN_CONTINUE;
284 case AuthManager::ACTION_CREATE:
285 $action = AuthManager::ACTION_CREATE_CONTINUE;
287 case AuthManager::ACTION_LINK:
288 $action = AuthManager::ACTION_LINK_CONTINUE;
303 $authManager = AuthManager::singleton();
304 if ( !in_array( $action, static::$allowedActions,
true ) ) {
305 throw new InvalidArgumentException(
'invalid action: ' . $action );
310 : $authManager->getAuthenticationRequests( $action );
317 case AuthManager::ACTION_LOGIN:
318 case AuthManager::ACTION_LOGIN_CONTINUE:
319 return $authManager->canAuthenticateNow();
320 case AuthManager::ACTION_CREATE:
321 case AuthManager::ACTION_CREATE_CONTINUE:
322 return $authManager->canCreateAccounts();
323 case AuthManager::ACTION_LINK:
324 case AuthManager::ACTION_LINK_CONTINUE:
325 return $authManager->canLinkAccounts();
326 case AuthManager::ACTION_CHANGE:
327 case AuthManager::ACTION_REMOVE:
328 case AuthManager::ACTION_UNLINK:
332 throw new InvalidArgumentException(
'invalid action: ' . $action );
343 if ( !in_array( $action, static::$allowedActions,
true ) ) {
344 throw new InvalidArgumentException(
'invalid action: ' . $action );
347 $authManager = AuthManager::singleton();
352 case AuthManager::ACTION_LOGIN:
353 return $authManager->beginAuthentication(
$requests, $returnToUrl );
354 case AuthManager::ACTION_LOGIN_CONTINUE:
355 return $authManager->continueAuthentication(
$requests );
356 case AuthManager::ACTION_CREATE:
357 return $authManager->beginAccountCreation( $this->
getUser(), $requests,
359 case AuthManager::ACTION_CREATE_CONTINUE:
360 return $authManager->continueAccountCreation(
$requests );
361 case AuthManager::ACTION_LINK:
362 return $authManager->beginAccountLink( $this->
getUser(), $requests, $returnToUrl );
363 case AuthManager::ACTION_LINK_CONTINUE:
364 return $authManager->continueAccountLink(
$requests );
365 case AuthManager::ACTION_CHANGE:
366 case AuthManager::ACTION_REMOVE:
367 case AuthManager::ACTION_UNLINK:
369 throw new InvalidArgumentException(
'only one auth request can be changed at a time' );
371 throw new InvalidArgumentException(
'no auth request' );
374 $status = $authManager->allowsAuthenticationDataChange(
$req );
375 Hooks::run(
'ChangeAuthenticationDataAudit', [
$req,
$status ] );
377 return AuthenticationResponse::newFail(
$status->getMessage() );
379 $authManager->changeAuthenticationData(
$req );
380 return AuthenticationResponse::newPass();
383 throw new InvalidArgumentException(
'invalid action: ' . $action );
400 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
401 $form->setSubmitCallback( [ $this,
'handleFormSubmit' ] );
407 if ( $sessionToken->wasNew() ) {
408 return Status::newFatal( $this->
messageKey(
'authform-newtoken' ) );
409 } elseif ( !$requestTokenValue ) {
410 return Status::newFatal( $this->
messageKey(
'authform-notoken' ) );
411 } elseif ( !$sessionToken->match( $requestTokenValue ) ) {
412 return Status::newFatal( $this->
messageKey(
'authform-wrongtoken' ) );
415 $form->prepareForm();
422 throw new UnexpectedValueException(
'HTMLForm::trySubmit() returned true' );
423 } elseif (
$status ===
false ) {
431 } elseif ( is_string(
$status ) ) {
433 } elseif ( is_array(
$status ) ) {
434 if ( is_string( reset(
$status ) ) ) {
436 } elseif ( is_array( reset(
$status ) ) ) {
438 foreach (
$status as $message ) {
439 call_user_func_array( [
$status,
'fatal' ], $message );
442 throw new UnexpectedValueException(
'invalid HTMLForm::trySubmit() return value: '
443 .
'first element of array is ' . gettype( reset(
$status ) ) );
448 throw new UnexpectedValueException(
'invalid HTMLForm::trySubmit() return type: '
457 LoggerFactory::getInstance(
'authentication' )
458 ->warning(
'Validation error on return', [
'data' => $form->mFieldData,
459 'status' =>
$status->getWikiText() ] );
465 AuthManager::ACTION_CHANGE, AuthManager::ACTION_REMOVE, AuthManager::ACTION_UNLINK
467 if ( in_array( $this->authAction, $changeActions,
true ) &&
$status && !
$status->isOK() ) {
468 Hooks::run(
'ChangeAuthenticationDataAudit', [ reset( $this->authRequests ),
$status ] );
481 $requests = AuthenticationRequest::loadRequestsFromSubmission( $this->authRequests, $data );
513 $fieldInfo = AuthenticationRequest::mergeFieldInfo(
$requests );
518 return $formDescriptor;
529 if (
$context->getRequest() !== $this->getRequest() ) {
537 $form->addHiddenField(
'authAction', $this->authAction );
551 $form = $this->
getAuthForm( $this->authRequests, $this->authAction );
552 $form->prepareForm()->displayForm(
$status );
566 $customSubmitButtonPresent =
false;
573 if (
$req->required === AuthenticationRequest::PRIMARY_REQUIRED ) {
575 $customSubmitButtonPresent =
true;
581 return !$customSubmitButtonPresent;
590 foreach (
$req->getFieldInfo() as $field => $info ) {
591 if ( $info[
'type'] ===
'button' ) {
605 foreach ( $formDescriptor as $field => &$definition ) {
607 if ( array_key_exists(
'class', $definition ) ) {
608 $class = $definition[
'class'];
609 } elseif ( array_key_exists(
'type', $definition ) ) {
612 if ( $class !==
'HTMLInfoField' ) {
613 $definition[
'tabindex'] = $i;
624 return $this->
getRequest()->getSession()->getToken(
'AuthManagerSpecialPage:'
633 return 'wpAuthToken';
646 $formDescriptor = [];
647 foreach ( $fieldInfo as $fieldName => $singleFieldInfo ) {
653 \Hooks::run(
'AuthChangeFormFields', [
$requests, $fieldInfo, &$formDescriptor, $action ] );
655 LoggerFactory::getInstance(
'authentication' )->warning(
656 'AuthChangeFormFields hook changed auth requests' );
663 return $formDescriptor;
678 'name' => $fieldName,
681 if (
$type ===
'submit' && isset( $singleFieldInfo[
'label'] ) ) {
682 $descriptor[
'default'] = $singleFieldInfo[
'label']->plain();
683 } elseif (
$type !==
'submit' ) {
684 $descriptor += array_filter( [
686 'label-message' => self::getField( $singleFieldInfo,
'label' ),
689 if ( isset( $singleFieldInfo[
'options'] ) ) {
690 $descriptor[
'options'] = array_flip( array_map(
function ( $message ) {
692 return $message->parse();
693 }, $singleFieldInfo[
'options'] ) );
696 if ( isset( $singleFieldInfo[
'value'] ) ) {
697 $descriptor[
'default'] = $singleFieldInfo[
'value'];
700 if ( empty( $singleFieldInfo[
'optional'] ) ) {
701 $descriptor[
'required'] =
true;
717 foreach ( $formDescriptor as &$field ) {
718 $field[
'__index'] = $i++;
720 uasort( $formDescriptor,
function ( $first, $second ) {
722 ?: $first[
'__index'] - $second[
'__index'];
724 foreach ( $formDescriptor as &$field ) {
725 unset( $field[
'__index'] );
736 protected static function getField( array $array, $fieldName, $default =
null ) {
737 if ( array_key_exists( $fieldName, $array ) ) {
738 return $array[$fieldName];
753 'password' =>
'password',
754 'select' =>
'select',
755 'checkbox' =>
'check',
756 'multiselect' =>
'multiselect',
757 'button' =>
'submit',
758 'hidden' =>
'hidden',
761 if ( !array_key_exists(
$type, $map ) ) {
762 throw new \LogicException(
'invalid field type: ' .
$type );
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.
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 hook is for auditing only $req
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
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
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action or null $user:User who performed the tagging when the tagging is subsequent to the action or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy: boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status