MediaWiki master
SpecialLinkAccounts.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Specials;
4
6use LogicException;
13use StatusValue;
14
24 protected static $allowedActions = [
25 AuthManager::ACTION_LINK, AuthManager::ACTION_LINK_CONTINUE,
26 ];
27
31 public function __construct( AuthManager $authManager ) {
32 parent::__construct( 'LinkAccounts' );
33 $this->setAuthManager( $authManager );
34 }
35
36 protected function getGroupName() {
37 return 'login';
38 }
39
40 public function isListed() {
41 return $this->getAuthManager()->canLinkAccounts();
42 }
43
44 protected function getRequestBlacklist() {
46 }
47
53 public function execute( $subPage ) {
54 $this->setHeaders();
55 $this->loadAuth( $subPage );
56
57 if ( !$this->isActionAllowed( $this->authAction ) ) {
58 if ( $this->authAction === AuthManager::ACTION_LINK ) {
59 // looks like no linking provider is installed or willing to take this user
60 $titleMessage = $this->msg( 'cannotlink-no-provider-title' );
61 $errorMessage = $this->msg( 'cannotlink-no-provider' );
62 throw new ErrorPageError( $titleMessage, $errorMessage );
63 } else {
64 // user probably back-button-navigated into an auth session that no longer exists
65 // FIXME would be nice to show a message
66 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false,
67 PROTO_HTTPS ) );
68 return;
69 }
70 }
71
72 $this->outputHeader();
73
74 $status = $this->trySubmit();
75
76 if ( $status === false || !$status->isOK() ) {
77 $this->displayForm( $status );
78 return;
79 }
80
81 $response = $status->getValue();
82
83 switch ( $response->status ) {
84 case AuthenticationResponse::PASS:
85 $this->success();
86 break;
87 case AuthenticationResponse::FAIL:
88 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
89 $this->displayForm( StatusValue::newFatal( $response->message ) );
90 break;
91 case AuthenticationResponse::REDIRECT:
92 $this->getOutput()->redirect( $response->redirectTarget );
93 break;
94 case AuthenticationResponse::UI:
95 $this->authAction = AuthManager::ACTION_LINK_CONTINUE;
96 $this->authRequests = $response->neededRequests;
97 $this->displayForm( StatusValue::newFatal( $response->message ) );
98 break;
99 default:
100 throw new LogicException( 'invalid AuthenticationResponse' );
101 }
102 }
103
104 protected function getDefaultAction( $subPage ) {
105 return AuthManager::ACTION_LINK;
106 }
107
113 protected function getAuthForm( array $requests, $action ) {
114 $form = parent::getAuthForm( $requests, $action );
115 $form->setSubmitTextMsg( 'linkaccounts-submit' );
116 return $form;
117 }
118
122 protected function success() {
123 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
124 $this->displayForm( StatusValue::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
125 }
126}
127
129class_alias( SpecialLinkAccounts::class, 'SpecialLinkAccounts' );
const PROTO_HTTPS
Definition Defines.php:204
An error page which can definitely be safely rendered using the OutputPage.
This serves as the entry point to the authentication system.
This is a value object for authentication requests.
This is a value object to hold authentication response data.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
A class containing constants representing the names of configuration variables.
const ChangeCredentialsBlacklist
Name constant for the ChangeCredentialsBlacklist setting, for use with Config::get()
A special page subclass for authentication-related special pages.
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
trySubmit()
Attempts to do an authentication step with the submitted data.
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
getPageTitle( $subpage=false)
Get a self-referential title object.
getConfig()
Shortcut to get main config object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
Link/unlink external accounts to the current user.
getDefaultAction( $subPage)
Get the default action for this special page if none is given via URL/POST data.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
isListed()
Whether this special page is listed in Special:SpecialPages.
getRequestBlacklist()
Allows blacklisting certain request types.
Generic operation result class Has warning/error list, boolean status and arbitrary value.