MediaWiki master
SpecialLinkAccounts.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Specials;
4
5use LogicException;
13use StatusValue;
14
25 protected static $allowedActions = [
26 AuthManager::ACTION_LINK, AuthManager::ACTION_LINK_CONTINUE,
27 ];
28
29 public function __construct( AuthManager $authManager ) {
30 parent::__construct( 'LinkAccounts' );
31 $this->setAuthManager( $authManager );
32 }
33
35 protected function getGroupName() {
36 return 'login';
37 }
38
40 public function isListed() {
41 return $this->getAuthManager()->canLinkAccounts();
42 }
43
45 protected function getRequestBlacklist() {
47 }
48
53 public function execute( $subPage ) {
54 $this->setHeaders();
55 $this->loadAuth( $subPage );
56
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 );
63 } else {
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,
67 PROTO_HTTPS ) );
68 return;
69 }
70 }
71
72 $this->outputHeader();
73
74 $status = $this->trySubmit();
75
76 if ( $status === false || !$status->isOK() ) {
77 $this->displayForm( $status );
78 return;
79 }
80
81 $response = $status->getValue();
82
83 switch ( $response->status ) {
84 case AuthenticationResponse::PASS:
85 $this->success();
86 break;
87 case AuthenticationResponse::FAIL:
88 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
89 $this->displayForm( StatusValue::newFatal( $response->message ) );
90 break;
91 case AuthenticationResponse::REDIRECT:
92 $this->getOutput()->redirect( $response->redirectTarget );
93 break;
94 case AuthenticationResponse::UI:
95 $this->authAction = AuthManager::ACTION_LINK_CONTINUE;
96 $this->authRequests = $response->neededRequests;
97 $this->displayForm( StatusValue::newFatal( $response->message ) );
98 break;
99 default:
100 throw new LogicException( 'invalid AuthenticationResponse' );
101 }
102 }
103
105 protected function getDefaultAction( $subPage ) {
106 return AuthManager::ACTION_LINK;
107 }
108
114 protected function getAuthForm( array $requests, $action ) {
115 $form = parent::getAuthForm( $requests, $action );
116 $form->setSubmitTextMsg( 'linkaccounts-submit' );
117 return $form;
118 }
119
123 protected function success() {
124 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
125 $this->displayForm( StatusValue::newFatal( $this->msg( 'linkaccounts-success-text' ) ) );
126 }
127}
128
130class_alias( SpecialLinkAccounts::class, 'SpecialLinkAccounts' );
const PROTO_HTTPS
Definition Defines.php:218
AuthManager is the authentication system in MediaWiki and serves entry point for authentication.
This is a value object for authentication requests.
This is a value object to hold authentication response data.
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:195
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.
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 By default the message key is the canonical name of...
Link/unlink external accounts to the current user.
getDefaultAction( $subPage)
Get the default action for this special page if none is given via URL/POST data.Subclasses should ove...
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.to override 1.3 (r3583) bool
getRequestBlacklist()
Allows blacklisting certain request types.to override array A list of AuthenticationRequest subclass ...
Generic operation result class Has warning/error list, boolean status and arbitrary value.