MediaWiki  master
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 
18  public function __construct() {
19  parent::__construct( 'LinkAccounts' );
20  }
21 
22  protected function getGroupName() {
23  return 'users';
24  }
25 
26  public function isListed() {
27  return MediaWikiServices::getInstance()->getAuthManager()->canLinkAccounts();
28  }
29 
30  protected function getRequestBlacklist() {
31  return $this->getConfig()->get( 'ChangeCredentialsBlacklist' );
32  }
33 
39  public function execute( $subPage ) {
40  $this->setHeaders();
41  $this->loadAuth( $subPage );
42 
43  if ( !$this->isActionAllowed( $this->authAction ) ) {
44  if ( $this->authAction === AuthManager::ACTION_LINK ) {
45  // looks like no linking provider is installed or willing to take this user
46  $titleMessage = $this->msg( 'cannotlink-no-provider-title' );
47  $errorMessage = $this->msg( 'cannotlink-no-provider' );
48  throw new ErrorPageError( $titleMessage, $errorMessage );
49  } else {
50  // user probably back-button-navigated into an auth session that no longer exists
51  // FIXME would be nice to show a message
52  $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false,
53  PROTO_HTTPS ) );
54  return;
55  }
56  }
57 
58  $this->outputHeader();
59 
60  $status = $this->trySubmit();
61 
62  if ( $status === false || !$status->isOK() ) {
63  $this->displayForm( $status );
64  return;
65  }
66 
67  $response = $status->getValue();
68 
69  switch ( $response->status ) {
70  case AuthenticationResponse::PASS:
71  $this->success();
72  break;
73  case AuthenticationResponse::FAIL:
74  $this->loadAuth( '', AuthManager::ACTION_LINK, true );
75  $this->displayForm( StatusValue::newFatal( $response->message ) );
76  break;
77  case AuthenticationResponse::REDIRECT:
78  $this->getOutput()->redirect( $response->redirectTarget );
79  break;
80  case AuthenticationResponse::UI:
81  $this->authAction = AuthManager::ACTION_LINK_CONTINUE;
82  $this->authRequests = $response->neededRequests;
83  $this->displayForm( StatusValue::newFatal( $response->message ) );
84  break;
85  default:
86  throw new LogicException( 'invalid AuthenticationResponse' );
87  }
88  }
89 
90  protected function getDefaultAction( $subPage ) {
91  return AuthManager::ACTION_LINK;
92  }
93 
99  protected function getAuthForm( array $requests, $action ) {
100  $form = parent::getAuthForm( $requests, $action );
101  $form->setSubmitTextMsg( 'linkaccounts-submit' );
102  return $form;
103  }
104 
108  protected function success() {
109  $this->loadAuth( '', AuthManager::ACTION_LINK, true );
110  $this->displayForm( StatusValue::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
111  }
112 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:669
AuthManagerSpecialPage\displayForm
displayForm( $status)
Display the form.
Definition: AuthManagerSpecialPage.php:549
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:800
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:69
$response
$response
Definition: opensearch_desc.php:44
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:716
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:149
SpecialLinkAccounts\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialLinkAccounts.php:26
SpecialLinkAccounts\getDefaultAction
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
Definition: SpecialLinkAccounts.php:90
AuthManagerSpecialPage
A special page subclass for authentication-related special pages.
Definition: AuthManagerSpecialPage.php:15
AuthManagerSpecialPage\trySubmit
trySubmit()
Attempts to do an authentication step with the submitted data.
Definition: AuthManagerSpecialPage.php:398
AuthManagerSpecialPage\$subPage
string $subPage
Subpage of the special page.
Definition: AuthManagerSpecialPage.php:36
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:766
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:232
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:551
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:209
SpecialLinkAccounts\$allowedActions
static $allowedActions
Definition: SpecialLinkAccounts.php:14
SpecialLinkAccounts\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialLinkAccounts.php:22
SpecialLinkAccounts\getRequestBlacklist
getRequestBlacklist()
Allows blacklisting certain request types.
Definition: SpecialLinkAccounts.php:30
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:88
SpecialLinkAccounts\success
success()
Show a success message.
Definition: SpecialLinkAccounts.php:108
SpecialLinkAccounts\execute
execute( $subPage)
Definition: SpecialLinkAccounts.php:39
AuthManagerSpecialPage\isActionAllowed
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
Definition: AuthManagerSpecialPage.php:303
SpecialLinkAccounts\__construct
__construct()
Definition: SpecialLinkAccounts.php:18
SpecialLinkAccounts
Links/unlinks external accounts to the current user.
Definition: SpecialLinkAccounts.php:13
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
SpecialLinkAccounts\getAuthForm
getAuthForm(array $requests, $action)
Definition: SpecialLinkAccounts.php:99
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:636
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:37