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
,
30 * @param AuthManager $authManager
32 public function __construct( AuthManager
$authManager ) {
33 parent
::__construct( 'LinkAccounts' );
34 $this->setAuthManager( $authManager );
37 protected function getGroupName() {
41 public function isListed() {
42 return $this->getAuthManager()->canLinkAccounts();
45 protected function getRequestBlacklist() {
46 return $this->getConfig()->get( MainConfigNames
::ChangeCredentialsBlacklist
);
50 * @param null|string $subPage
51 * @throws ErrorPageError
53 public function execute( $subPage ) {
55 $this->loadAuth( $subPage );
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 );
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,
72 $this->outputHeader();
74 $status = $this->trySubmit();
76 if ( $status === false ||
!$status->isOK() ) {
77 $this->displayForm( $status );
81 $response = $status->getValue();
83 switch ( $response->status
) {
84 case AuthenticationResponse
::PASS
:
87 case AuthenticationResponse
::FAIL
:
88 $this->loadAuth( '', AuthManager
::ACTION_LINK
, true );
89 $this->displayForm( StatusValue
::newFatal( $response->message
) );
91 case AuthenticationResponse
::REDIRECT
:
92 $this->getOutput()->redirect( $response->redirectTarget
);
94 case AuthenticationResponse
::UI
:
95 $this->authAction
= AuthManager
::ACTION_LINK_CONTINUE
;
96 $this->authRequests
= $response->neededRequests
;
97 $this->displayForm( StatusValue
::newFatal( $response->message
) );
100 throw new LogicException( 'invalid AuthenticationResponse' );
104 protected function getDefaultAction( $subPage ) {
105 return AuthManager
::ACTION_LINK
;
109 * @param AuthenticationRequest[] $requests
110 * @param string $action AuthManager action name, should be ACTION_LINK or ACTION_LINK_CONTINUE
113 protected function getAuthForm( array $requests, $action ) {
114 $form = parent
::getAuthForm( $requests, $action );
115 $form->setSubmitTextMsg( 'linkaccounts-submit' );
120 * Show a success message.
122 protected function success() {
123 $this->loadAuth( '', AuthManager
::ACTION_LINK
, true );
124 $this->displayForm( StatusValue
::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
128 /** @deprecated class alias since 1.41 */
129 class_alias( SpecialLinkAccounts
::class, 'SpecialLinkAccounts' );