MediaWiki master
SpecialUnlinkAccounts.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Specials;
4
12use StatusValue;
13
20 protected static $allowedActions = [ AuthManager::ACTION_UNLINK ];
21 private SessionManager $sessionManager;
22
23 public function __construct( AuthManager $authManager, SessionManager $sessionManager ) {
24 parent::__construct( 'UnlinkAccounts' );
25 $this->setAuthManager( $authManager );
26 $this->sessionManager = $sessionManager;
27 }
28
30 protected function getLoginSecurityLevel() {
31 return 'UnlinkAccount';
32 }
33
35 protected function getDefaultAction( $subPage ) {
36 return AuthManager::ACTION_UNLINK;
37 }
38
43 protected function getGroupName() {
44 return 'login';
45 }
46
48 public function isListed() {
49 return $this->getAuthManager()->canLinkAccounts();
50 }
51
53 protected function getRequestBlacklist() {
55 }
56
58 public function execute( $subPage ) {
59 $this->setHeaders();
60 $this->loadAuth( $subPage );
61
62 if ( !$this->isActionAllowed( $this->authAction ) ) {
63 if ( $this->authAction === AuthManager::ACTION_UNLINK ) {
64 // Looks like there are no linked accounts to unlink
65 $titleMessage = $this->msg( 'cannotunlink-no-provider-title' );
66 $errorMessage = $this->msg( 'cannotunlink-no-provider' );
67 throw new ErrorPageError( $titleMessage, $errorMessage );
68 } else {
69 // user probably back-button-navigated into an auth session that no longer exists
70 // FIXME would be nice to show a message
71 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) );
72 return;
73 }
74 }
75
76 $this->outputHeader();
77
78 $status = $this->trySubmit();
79
80 if ( $status === false || !$status->isOK() ) {
81 $this->displayForm( $status );
82 return;
83 }
84
86 $response = $status->getValue();
87
88 if ( $response->status === AuthenticationResponse::FAIL ) {
89 $this->displayForm( StatusValue::newFatal( $response->message ) );
90 return;
91 }
92
93 $status = StatusValue::newGood();
94 $status->warning( $this->msg( 'unlinkaccounts-success' ) );
95 $this->loadAuth( $subPage, null, true ); // update requests so the unlinked one doesn't show up
96
97 // Reset sessions - if the user unlinked an account because it was compromised,
98 // log attackers out from sessions obtained via that account.
99 $session = $this->getRequest()->getSession();
100 $user = $this->getUser();
101 $this->sessionManager->invalidateSessionsForUser( $user );
102 $session->setUser( $user );
103 $session->resetId();
104
105 $this->displayForm( $status );
106 }
107
109 public function handleFormSubmit( $data ) {
110 // unlink requests do not accept user input so repeat parent code but skip call to
111 // AuthenticationRequest::loadRequestsFromSubmission
112 $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests );
113 return Status::newGood( $response );
114 }
115}
116
121class_alias( SpecialUnlinkAccounts::class, 'SpecialUnlinkAccounts' );
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 to hold authentication response data.
An error page which can definitely be safely rendered using the OutputPage.
A class containing constants representing the names of configuration variables.
const RemoveCredentialsBlacklist
Name constant for the RemoveCredentialsBlacklist setting, for use with Config::get()
This serves as the entry point to the MediaWiki session handling system.
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.
getRequest()
Get the WebRequest being used for this instance.WebRequest 1.18
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
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...
getDefaultAction( $subPage)
Get the default action for this special page if none is given via URL/POST data.Subclasses should ove...
execute( $subPage)
Default execute method Checks user permissions.This must be overridden by subclasses; it will be made...
getRequestBlacklist()
Allows blacklisting certain request types.to override array A list of AuthenticationRequest subclass ...
__construct(AuthManager $authManager, SessionManager $sessionManager)
isListed()
Whether this special page is listed in Special:SpecialPages.to override 1.3 (r3583) bool
handleFormSubmit( $data)
Submit handler callback for HTMLForm.Status
getGroupName()
Under which header this special page is listed in Special:SpecialPages.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
Generic operation result class Has warning/error list, boolean status and arbitrary value.