MediaWiki REL1_37
SpecialUnlinkAccounts.php
Go to the documentation of this file.
1<?php
2
6
8 protected static $allowedActions = [ AuthManager::ACTION_UNLINK ];
9
14 parent::__construct( 'UnlinkAccounts' );
15 $this->setAuthManager( $authManager );
16 }
17
18 protected function getLoginSecurityLevel() {
19 return 'UnlinkAccount';
20 }
21
22 protected function getDefaultAction( $subPage ) {
23 return AuthManager::ACTION_UNLINK;
24 }
25
30 protected function getGroupName() {
31 return 'users';
32 }
33
34 public function isListed() {
35 return $this->getAuthManager()->canLinkAccounts();
36 }
37
38 protected function getRequestBlacklist() {
39 return $this->getConfig()->get( 'RemoveCredentialsBlacklist' );
40 }
41
42 public function execute( $subPage ) {
43 $this->setHeaders();
44 $this->loadAuth( $subPage );
45
46 if ( !$this->isActionAllowed( $this->authAction ) ) {
47 if ( $this->authAction === AuthManager::ACTION_UNLINK ) {
48 // Looks like there are no linked accounts to unlink
49 $titleMessage = $this->msg( 'cannotunlink-no-provider-title' );
50 $errorMessage = $this->msg( 'cannotunlink-no-provider' );
51 throw new ErrorPageError( $titleMessage, $errorMessage );
52 } else {
53 // user probably back-button-navigated into an auth session that no longer exists
54 // FIXME would be nice to show a message
55 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) );
56 return;
57 }
58 }
59
60 $this->outputHeader();
61
62 $status = $this->trySubmit();
63
64 if ( $status === false || !$status->isOK() ) {
65 $this->displayForm( $status );
66 return;
67 }
68
70 $response = $status->getValue();
71
72 if ( $response->status === AuthenticationResponse::FAIL ) {
73 $this->displayForm( StatusValue::newFatal( $response->message ) );
74 return;
75 }
76
77 $status = StatusValue::newGood();
78 $status->warning( $this->msg( 'unlinkaccounts-success' ) );
79 $this->loadAuth( $subPage, null, true ); // update requests so the unlinked one doesn't show up
80
81 // Reset sessions - if the user unlinked an account because it was compromised,
82 // log attackers out from sessions obtained via that account.
83 $session = $this->getRequest()->getSession();
84 $user = $this->getUser();
85 SessionManager::singleton()->invalidateSessionsForUser( $user );
86 $session->setUser( $user );
87 $session->resetId();
88
89 $this->displayForm( $status );
90 }
91
92 public function handleFormSubmit( $data ) {
93 // unlink requests do not accept user input so repeat parent code but skip call to
94 // AuthenticationRequest::loadRequestsFromSubmission
95 $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests );
96 return Status::newGood( $response );
97 }
98}
const PROTO_HTTPS
Definition Defines.php:193
A special page subclass for authentication-related special pages.
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
performAuthenticationStep( $action, array $requests)
displayForm( $status)
Display the form.
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
string $subPage
Subpage of the special page.
getRequest()
Get the WebRequest being used for this instance.
trySubmit()
Attempts to do an authentication step with the submitted data.
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 to hold authentication response data.
This serves as the entry point to the MediaWiki session handling system.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
AuthManager null $authManager
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
getPageTitle( $subpage=false)
Get a self-referential title object.
__construct(AuthManager $authManager)
handleFormSubmit( $data)
Submit handler callback for HTMLForm.
execute( $subPage)
Default execute method Checks user permissions.
getGroupName()
Under which header this special page is listed in Special:SpecialPages.
isListed()
Whether this special page is listed in Special:SpecialPages.
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
getRequestBlacklist()
Allows blacklisting certain request types.