MediaWiki master
SpecialLinkAccounts.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Specials;
4
6use LogicException;
13use StatusValue;
14
21 protected static $allowedActions = [
22 AuthManager::ACTION_LINK, AuthManager::ACTION_LINK_CONTINUE,
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 ) {
81 case AuthenticationResponse::PASS:
82 $this->success();
83 break;
84 case AuthenticationResponse::FAIL:
85 $this->loadAuth( '', AuthManager::ACTION_LINK, true );
86 $this->displayForm( StatusValue::newFatal( $response->message ) );
87 break;
88 case AuthenticationResponse::REDIRECT:
89 $this->getOutput()->redirect( $response->redirectTarget );
90 break;
91 case AuthenticationResponse::UI:
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 ) {
102 return AuthManager::ACTION_LINK;
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
128class_alias( SpecialLinkAccounts::class, 'SpecialLinkAccounts' );
const PROTO_HTTPS
Definition Defines.php:201
An error page which can definitely be safely rendered using the OutputPage.
This serves as the entry point to the authentication system.
This is a value object for authentication requests.
This is a value object to hold authentication response data.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
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 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.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...