MediaWiki  master
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 
20  public function __construct( AuthManager $authManager ) {
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 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:768
AuthManagerSpecialPage\displayForm
displayForm( $status)
Display the form.
Definition: AuthManagerSpecialPage.php:570
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:936
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:193
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:814
SpecialLinkAccounts\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialLinkAccounts.php:29
SpecialLinkAccounts\getDefaultAction
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
Definition: SpecialLinkAccounts.php:93
AuthManagerSpecialPage
A special page subclass for authentication-related special pages.
Definition: AuthManagerSpecialPage.php:18
SpecialPage\$authManager
AuthManager null $authManager
Definition: SpecialPage.php:88
AuthManagerSpecialPage\trySubmit
trySubmit()
Attempts to do an authentication step with the submitted data.
Definition: AuthManagerSpecialPage.php:416
SpecialLinkAccounts\__construct
__construct(AuthManager $authManager)
Definition: SpecialLinkAccounts.php:20
AuthManagerSpecialPage\$subPage
string $subPage
Subpage of the special page.
Definition: AuthManagerSpecialPage.php:39
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:902
MediaWiki\Auth\AuthenticationResponse
This is a value object to hold authentication response data.
Definition: AuthenticationResponse.php:37
AuthManagerSpecialPage\loadAuth
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
Definition: AuthManagerSpecialPage.php:250
SpecialPage\setAuthManager
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
Definition: SpecialPage.php:534
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:642
SpecialLinkAccounts\$allowedActions
static $allowedActions
Definition: SpecialLinkAccounts.php:13
SpecialLinkAccounts\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialLinkAccounts.php:25
SpecialLinkAccounts\getRequestBlacklist
getRequestBlacklist()
Allows blacklisting certain request types.
Definition: SpecialLinkAccounts.php:33
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:102
SpecialLinkAccounts\success
success()
Show a success message.
Definition: SpecialLinkAccounts.php:111
SpecialLinkAccounts\execute
execute( $subPage)
Definition: SpecialLinkAccounts.php:42
AuthManagerSpecialPage\isActionAllowed
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
Definition: AuthManagerSpecialPage.php:321
SpecialPage\getAuthManager
getAuthManager()
Definition: SpecialPage.php:544
SpecialLinkAccounts
Links/unlinks external accounts to the current user.
Definition: SpecialLinkAccounts.php:12
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30
SpecialLinkAccounts\getAuthForm
getAuthForm(array $requests, $action)
Definition: SpecialLinkAccounts.php:102
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:733
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:38