MediaWiki  master
SpecialLinkAccounts.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Specials;
4 
6 use HTMLForm;
7 use LogicException;
13 use StatusValue;
14 
21  protected static $allowedActions = [
23  ];
24 
28  public function __construct( AuthManager $authManager ) {
29  parent::__construct( 'LinkAccounts' );
30  $this->setAuthManager( $authManager );
31  }
32 
33  protected function getGroupName() {
34  return 'login';
35  }
36 
37  public function isListed() {
38  return $this->getAuthManager()->canLinkAccounts();
39  }
40 
41  protected function getRequestBlacklist() {
43  }
44 
50  public function execute( $subPage ) {
51  $this->setHeaders();
52  $this->loadAuth( $subPage );
53 
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 );
60  } else {
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,
64  PROTO_HTTPS ) );
65  return;
66  }
67  }
68 
69  $this->outputHeader();
70 
71  $status = $this->trySubmit();
72 
73  if ( $status === false || !$status->isOK() ) {
74  $this->displayForm( $status );
75  return;
76  }
77 
78  $response = $status->getValue();
79 
80  switch ( $response->status ) {
82  $this->success();
83  break;
85  $this->loadAuth( '', AuthManager::ACTION_LINK, true );
86  $this->displayForm( StatusValue::newFatal( $response->message ) );
87  break;
89  $this->getOutput()->redirect( $response->redirectTarget );
90  break;
92  $this->authAction = AuthManager::ACTION_LINK_CONTINUE;
93  $this->authRequests = $response->neededRequests;
94  $this->displayForm( StatusValue::newFatal( $response->message ) );
95  break;
96  default:
97  throw new LogicException( 'invalid AuthenticationResponse' );
98  }
99  }
100 
101  protected function getDefaultAction( $subPage ) {
103  }
104 
110  protected function getAuthForm( array $requests, $action ) {
111  $form = parent::getAuthForm( $requests, $action );
112  $form->setSubmitTextMsg( 'linkaccounts-submit' );
113  return $form;
114  }
115 
119  protected function success() {
120  $this->loadAuth( '', AuthManager::ACTION_LINK, true );
121  $this->displayForm( StatusValue::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
122  }
123 }
124 
128 class_alias( SpecialLinkAccounts::class, 'SpecialLinkAccounts' );
const PROTO_HTTPS
Definition: Defines.php:192
An error page which can definitely be safely rendered using the OutputPage.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:158
This serves as the entry point to the authentication system.
const ACTION_LINK_CONTINUE
Continue a user linking process that was interrupted by the need for user input or communication with...
const ACTION_LINK
Link an existing user to a third-party account.
This is a value object for authentication requests.
This is a value object to hold authentication response data.
const FAIL
Indicates that the authentication failed.
const PASS
Indicates that the authentication succeeded.
const UI
Indicates that the authentication needs further user input of some sort.
const REDIRECT
Indicates that the authentication needs to be redirected to a third party to proceed.
A class containing constants representing the names of configuration variables.
const ChangeCredentialsBlacklist
Name constant for the ChangeCredentialsBlacklist setting, for use with Config::get()
A special page subclass for authentication-related special pages.
string $subPage
Subpage of the special page.
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
trySubmit()
Attempts to do an authentication step with the submitted data.
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
getPageTitle( $subpage=false)
Get a self-referential title object.
getConfig()
Shortcut to get main config object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Links/unlinks external accounts to the current user.
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
isListed()
Whether this special page is listed in Special:SpecialPages.
getRequestBlacklist()
Allows blacklisting certain request types.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:46
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:73