MediaWiki REL1_39
SpecialLinkAccounts.php
Go to the documentation of this file.
1<?php
2
7
14 protected static $allowedActions = [
15 AuthManager::ACTION_LINK, AuthManager::ACTION_LINK_CONTINUE,
16 ];
17
21 public function __construct( AuthManager $authManager ) {
22 parent::__construct( 'LinkAccounts' );
23 $this->setAuthManager( $authManager );
24 }
25
26 protected function getGroupName() {
27 return 'users';
28 }
29
30 public function isListed() {
31 return $this->getAuthManager()->canLinkAccounts();
32 }
33
34 protected function getRequestBlacklist() {
35 return $this->getConfig()->get( MainConfigNames::ChangeCredentialsBlacklist );
36 }
37
43 public function execute( $subPage ) {
44 $this->setHeaders();
45 $this->loadAuth( $subPage );
46
47 if ( !$this->isActionAllowed( $this->authAction ) ) {
48 if ( $this->authAction === AuthManager::ACTION_LINK ) {
49 // looks like no linking provider is installed or willing to take this user
50 $titleMessage = $this->msg( 'cannotlink-no-provider-title' );
51 $errorMessage = $this->msg( 'cannotlink-no-provider' );
52 throw new ErrorPageError( $titleMessage, $errorMessage );
53 } else {
54 // user probably back-button-navigated into an auth session that no longer exists
55 // FIXME would be nice to show a message
56 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false,
57 PROTO_HTTPS ) );
58 return;
59 }
60 }
61
62 $this->outputHeader();
63
64 $status = $this->trySubmit();
65
66 if ( $status === false || !$status->isOK() ) {
67 $this->displayForm( $status );
68 return;
69 }
70
71 $response = $status->getValue();
72
73 switch ( $response->status ) {
74 case AuthenticationResponse::PASS:
75 $this->success();
76 break;
77 case AuthenticationResponse::FAIL:
78 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
79 $this->displayForm( StatusValue::newFatal( $response->message ) );
80 break;
81 case AuthenticationResponse::REDIRECT:
82 $this->getOutput()->redirect( $response->redirectTarget );
83 break;
84 case AuthenticationResponse::UI:
85 $this->authAction = AuthManager::ACTION_LINK_CONTINUE;
86 $this->authRequests = $response->neededRequests;
87 $this->displayForm( StatusValue::newFatal( $response->message ) );
88 break;
89 default:
90 throw new LogicException( 'invalid AuthenticationResponse' );
91 }
92 }
93
94 protected function getDefaultAction( $subPage ) {
95 return AuthManager::ACTION_LINK;
96 }
97
103 protected function getAuthForm( array $requests, $action ) {
104 $form = parent::getAuthForm( $requests, $action );
105 $form->setSubmitTextMsg( 'linkaccounts-submit' );
106 return $form;
107 }
108
112 protected function success() {
113 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
114 $this->displayForm( StatusValue::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
115 }
116}
const PROTO_HTTPS
Definition Defines.php:194
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.
A class containing constants representing the names of configuration variables.
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.
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.