3 namespace MediaWiki\Specials
;
7 use MediaWiki\Auth\AuthenticationRequest
;
8 use MediaWiki\Auth\AuthenticationResponse
;
9 use MediaWiki\Auth\AuthManager
;
10 use MediaWiki\HTMLForm\HTMLForm
;
11 use MediaWiki\MainConfigNames
;
12 use MediaWiki\SpecialPage\AuthManagerSpecialPage
;
16 * Link/unlink external accounts to the current user.
18 * To interact with this page, account providers need to register themselves with AuthManager.
20 * @ingroup SpecialPage
23 class SpecialLinkAccounts
extends AuthManagerSpecialPage
{
25 protected static $allowedActions = [
26 AuthManager
::ACTION_LINK
, AuthManager
::ACTION_LINK_CONTINUE
,
29 public function __construct( AuthManager
$authManager ) {
30 parent
::__construct( 'LinkAccounts' );
31 $this->setAuthManager( $authManager );
34 protected function getGroupName() {
38 public function isListed() {
39 return $this->getAuthManager()->canLinkAccounts();
42 protected function getRequestBlacklist() {
43 return $this->getConfig()->get( MainConfigNames
::ChangeCredentialsBlacklist
);
47 * @param null|string $subPage
48 * @throws ErrorPageError
50 public function execute( $subPage ) {
52 $this->loadAuth( $subPage );
54 if ( !$this->isActionAllowed( $this->authAction
) ) {
55 if ( $this->authAction
=== AuthManager
::ACTION_LINK
) {
56 // looks like no linking provider is installed or willing to take this user
57 $titleMessage = $this->msg( 'cannotlink-no-provider-title' );
58 $errorMessage = $this->msg( 'cannotlink-no-provider' );
59 throw new ErrorPageError( $titleMessage, $errorMessage );
61 // user probably back-button-navigated into an auth session that no longer exists
62 // FIXME would be nice to show a message
63 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false,
69 $this->outputHeader();
71 $status = $this->trySubmit();
73 if ( $status === false ||
!$status->isOK() ) {
74 $this->displayForm( $status );
78 $response = $status->getValue();
80 switch ( $response->status
) {
81 case AuthenticationResponse
::PASS
:
84 case AuthenticationResponse
::FAIL
:
85 $this->loadAuth( '', AuthManager
::ACTION_LINK
, true );
86 $this->displayForm( StatusValue
::newFatal( $response->message
) );
88 case AuthenticationResponse
::REDIRECT
:
89 $this->getOutput()->redirect( $response->redirectTarget
);
91 case AuthenticationResponse
::UI
:
92 $this->authAction
= AuthManager
::ACTION_LINK_CONTINUE
;
93 $this->authRequests
= $response->neededRequests
;
94 $this->displayForm( StatusValue
::newFatal( $response->message
) );
97 throw new LogicException( 'invalid AuthenticationResponse' );
101 protected function getDefaultAction( $subPage ) {
102 return AuthManager
::ACTION_LINK
;
106 * @param AuthenticationRequest[] $requests
107 * @param string $action AuthManager action name, should be ACTION_LINK or ACTION_LINK_CONTINUE
110 protected function getAuthForm( array $requests, $action ) {
111 $form = parent
::getAuthForm( $requests, $action );
112 $form->setSubmitTextMsg( 'linkaccounts-submit' );
117 * Show a success message.
119 protected function success() {
120 $this->loadAuth( '', AuthManager
::ACTION_LINK
, true );
121 $this->displayForm( StatusValue
::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
125 /** @deprecated class alias since 1.41 */
126 class_alias( SpecialLinkAccounts
::class, 'SpecialLinkAccounts' );