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
22 public function __construct(
23 AuthManager $authManager,
24 private readonly SessionManager $sessionManager,
25 ) {
26 parent::__construct( 'UnlinkAccounts' );
27 $this->setAuthManager( $authManager );
28 }
29
31 protected function getLoginSecurityLevel() {
32 return 'UnlinkAccount';
33 }
34
36 protected function getDefaultAction( $subPage ) {
37 return AuthManager::ACTION_UNLINK;
38 }
39
44 protected function getGroupName() {
45 return 'login';
46 }
47
49 public function isListed() {
50 return $this->getAuthManager()->canLinkAccounts();
51 }
52
54 protected function getRequestBlacklist() {
56 }
57
59 public function execute( $subPage ) {
60 $this->setHeaders();
61 $this->loadAuth( $subPage );
62
63 if ( !$this->isActionAllowed( $this->authAction ) ) {
64 if ( $this->authAction === AuthManager::ACTION_UNLINK ) {
65 // Looks like there are no linked accounts to unlink
66 $titleMessage = $this->msg( 'cannotunlink-no-provider-title' );
67 $errorMessage = $this->msg( 'cannotunlink-no-provider' );
68 throw new ErrorPageError( $titleMessage, $errorMessage );
69 } else {
70 // user probably back-button-navigated into an auth session that no longer exists
71 // FIXME would be nice to show a message
72 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) );
73 return;
74 }
75 }
76
77 $this->outputHeader();
78
79 $status = $this->trySubmit();
80
81 if ( $status === false || !$status->isOK() ) {
82 $this->displayForm( $status );
83 return;
84 }
85
87 $response = $status->getValue();
88
89 if ( $response->status === AuthenticationResponse::FAIL ) {
90 $this->displayForm( StatusValue::newFatal( $response->message ) );
91 return;
92 }
93
94 $status = StatusValue::newGood();
95 $status->warning( 'unlinkaccounts-success' );
96 $this->loadAuth( $subPage, null, true ); // update requests so the unlinked one doesn't show up
97
98 // Reset sessions - if the user unlinked an account because it was compromised,
99 // log attackers out from sessions obtained via that account.
100 $session = $this->getRequest()->getSession();
101 $user = $this->getUser();
102 $this->sessionManager->invalidateSessionsForUser( $user );
103 $session->setUser( $user );
104 $session->resetId();
105
106 $this->displayForm( $status );
107 }
108
110 public function handleFormSubmit( $data ) {
111 // unlink requests do not accept user input so repeat parent code but skip call to
112 // AuthenticationRequest::loadRequestsFromSubmission
113 $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests );
114 return Status::newGood( $response );
115 }
116}
117
122class_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 ...
isListed()
Whether this special page is listed in Special:SpecialPages.to override 1.3 (r3583) bool
handleFormSubmit( $data)
Submit handler callback for HTMLForm.Status
__construct(AuthManager $authManager, private readonly SessionManager $sessionManager,)
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.