MediaWiki REL1_37
SpecialLinkAccounts.php
Go to the documentation of this file.
1<?php
2
6
13 protected static $allowedActions = [
14 AuthManager::ACTION_LINK, AuthManager::ACTION_LINK_CONTINUE,
15 ];
16
21 parent::__construct( 'LinkAccounts' );
22 $this->setAuthManager( $authManager );
23 }
24
25 protected function getGroupName() {
26 return 'users';
27 }
28
29 public function isListed() {
30 return $this->getAuthManager()->canLinkAccounts();
31 }
32
33 protected function getRequestBlacklist() {
34 return $this->getConfig()->get( 'ChangeCredentialsBlacklist' );
35 }
36
42 public function execute( $subPage ) {
43 $this->setHeaders();
44 $this->loadAuth( $subPage );
45
46 if ( !$this->isActionAllowed( $this->authAction ) ) {
47 if ( $this->authAction === AuthManager::ACTION_LINK ) {
48 // looks like no linking provider is installed or willing to take this user
49 $titleMessage = $this->msg( 'cannotlink-no-provider-title' );
50 $errorMessage = $this->msg( 'cannotlink-no-provider' );
51 throw new ErrorPageError( $titleMessage, $errorMessage );
52 } else {
53 // user probably back-button-navigated into an auth session that no longer exists
54 // FIXME would be nice to show a message
55 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false,
56 PROTO_HTTPS ) );
57 return;
58 }
59 }
60
61 $this->outputHeader();
62
63 $status = $this->trySubmit();
64
65 if ( $status === false || !$status->isOK() ) {
66 $this->displayForm( $status );
67 return;
68 }
69
70 $response = $status->getValue();
71
72 switch ( $response->status ) {
73 case AuthenticationResponse::PASS:
74 $this->success();
75 break;
76 case AuthenticationResponse::FAIL:
77 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
78 $this->displayForm( StatusValue::newFatal( $response->message ) );
79 break;
80 case AuthenticationResponse::REDIRECT:
81 $this->getOutput()->redirect( $response->redirectTarget );
82 break;
83 case AuthenticationResponse::UI:
84 $this->authAction = AuthManager::ACTION_LINK_CONTINUE;
85 $this->authRequests = $response->neededRequests;
86 $this->displayForm( StatusValue::newFatal( $response->message ) );
87 break;
88 default:
89 throw new LogicException( 'invalid AuthenticationResponse' );
90 }
91 }
92
93 protected function getDefaultAction( $subPage ) {
94 return AuthManager::ACTION_LINK;
95 }
96
102 protected function getAuthForm( array $requests, $action ) {
103 $form = parent::getAuthForm( $requests, $action );
104 $form->setSubmitTextMsg( 'linkaccounts-submit' );
105 return $form;
106 }
107
111 protected function success() {
112 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
113 $this->displayForm( StatusValue::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
114 }
115}
const PROTO_HTTPS
Definition Defines.php:193
A special page subclass for authentication-related special pages.
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
displayForm( $status)
Display the form.
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
string $subPage
Subpage of the special page.
trySubmit()
Attempts to do an authentication step with the submitted data.
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.
Links/unlinks external accounts to the current user.
__construct(AuthManager $authManager)
success()
Show a success message.
isListed()
Whether this special page is listed in Special:SpecialPages.
getAuthForm(array $requests, $action)
getRequestBlacklist()
Allows blacklisting certain request types.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
AuthManager null $authManager
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
getPageTitle( $subpage=false)
Get a self-referential title object.