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( AuthManager $authManager ) {
23 parent::__construct( 'UnlinkAccounts' );
24 $this->setAuthManager( $authManager );
25 }
26
27 protected function getLoginSecurityLevel() {
28 return 'UnlinkAccount';
29 }
30
31 protected function getDefaultAction( $subPage ) {
32 return AuthManager::ACTION_UNLINK;
33 }
34
39 protected function getGroupName() {
40 return 'login';
41 }
42
43 public function isListed() {
44 return $this->getAuthManager()->canLinkAccounts();
45 }
46
47 protected function getRequestBlacklist() {
49 }
50
51 public function execute( $subPage ) {
52 $this->setHeaders();
53 $this->loadAuth( $subPage );
54
55 if ( !$this->isActionAllowed( $this->authAction ) ) {
56 if ( $this->authAction === AuthManager::ACTION_UNLINK ) {
57 // Looks like there are no linked accounts to unlink
58 $titleMessage = $this->msg( 'cannotunlink-no-provider-title' );
59 $errorMessage = $this->msg( 'cannotunlink-no-provider' );
60 throw new ErrorPageError( $titleMessage, $errorMessage );
61 } else {
62 // user probably back-button-navigated into an auth session that no longer exists
63 // FIXME would be nice to show a message
64 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, 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
79 $response = $status->getValue();
80
81 if ( $response->status === AuthenticationResponse::FAIL ) {
82 $this->displayForm( StatusValue::newFatal( $response->message ) );
83 return;
84 }
85
86 $status = StatusValue::newGood();
87 $status->warning( $this->msg( 'unlinkaccounts-success' ) );
88 $this->loadAuth( $subPage, null, true ); // update requests so the unlinked one doesn't show up
89
90 // Reset sessions - if the user unlinked an account because it was compromised,
91 // log attackers out from sessions obtained via that account.
92 $session = $this->getRequest()->getSession();
93 $user = $this->getUser();
94 SessionManager::singleton()->invalidateSessionsForUser( $user );
95 $session->setUser( $user );
96 $session->resetId();
97
98 $this->displayForm( $status );
99 }
100
101 public function handleFormSubmit( $data ) {
102 // unlink requests do not accept user input so repeat parent code but skip call to
103 // AuthenticationRequest::loadRequestsFromSubmission
104 $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests );
105 return Status::newGood( $response );
106 }
107}
108
113class_alias( SpecialUnlinkAccounts::class, 'SpecialUnlinkAccounts' );
const PROTO_HTTPS
Definition Defines.php:232
This serves as the entry point to the authentication system.
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.
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.
execute( $subPage)
Default execute method Checks user permissions.
getRequestBlacklist()
Allows blacklisting certain request types.
isListed()
Whether this special page is listed in Special:SpecialPages.
handleFormSubmit( $data)
Submit handler callback for HTMLForm.
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:54
Generic operation result class Has warning/error list, boolean status and arbitrary value.