MediaWiki REL1_39
SpecialUnlinkAccounts.php
Go to the documentation of this file.
1<?php
2
7
9 protected static $allowedActions = [ AuthManager::ACTION_UNLINK ];
10
14 public function __construct( AuthManager $authManager ) {
15 parent::__construct( 'UnlinkAccounts' );
16 $this->setAuthManager( $authManager );
17 }
18
19 protected function getLoginSecurityLevel() {
20 return 'UnlinkAccount';
21 }
22
23 protected function getDefaultAction( $subPage ) {
24 return AuthManager::ACTION_UNLINK;
25 }
26
31 protected function getGroupName() {
32 return 'users';
33 }
34
35 public function isListed() {
36 return $this->getAuthManager()->canLinkAccounts();
37 }
38
39 protected function getRequestBlacklist() {
40 return $this->getConfig()->get( MainConfigNames::RemoveCredentialsBlacklist );
41 }
42
43 public function execute( $subPage ) {
44 $this->setHeaders();
45 $this->loadAuth( $subPage );
46
47 if ( !$this->isActionAllowed( $this->authAction ) ) {
48 if ( $this->authAction === AuthManager::ACTION_UNLINK ) {
49 // Looks like there are no linked accounts to unlink
50 $titleMessage = $this->msg( 'cannotunlink-no-provider-title' );
51 $errorMessage = $this->msg( 'cannotunlink-no-provider' );
52 throw new ErrorPageError( $titleMessage, $errorMessage );
53 } else {
54 // user probably back-button-navigated into an auth session that no longer exists
55 // FIXME would be nice to show a message
56 $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) );
57 return;
58 }
59 }
60
61 $this->outputHeader();
62
63 $status = $this->trySubmit();
64
65 if ( $status === false || !$status->isOK() ) {
66 $this->displayForm( $status );
67 return;
68 }
69
71 $response = $status->getValue();
72
73 if ( $response->status === AuthenticationResponse::FAIL ) {
74 $this->displayForm( StatusValue::newFatal( $response->message ) );
75 return;
76 }
77
78 $status = StatusValue::newGood();
79 $status->warning( $this->msg( 'unlinkaccounts-success' ) );
80 $this->loadAuth( $subPage, null, true ); // update requests so the unlinked one doesn't show up
81
82 // Reset sessions - if the user unlinked an account because it was compromised,
83 // log attackers out from sessions obtained via that account.
84 $session = $this->getRequest()->getSession();
85 $user = $this->getUser();
86 SessionManager::singleton()->invalidateSessionsForUser( $user );
87 $session->setUser( $user );
88 $session->resetId();
89
90 $this->displayForm( $status );
91 }
92
93 public function handleFormSubmit( $data ) {
94 // unlink requests do not accept user input so repeat parent code but skip call to
95 // AuthenticationRequest::loadRequestsFromSubmission
96 $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests );
97 return Status::newGood( $response );
98 }
99}
const PROTO_HTTPS
Definition Defines.php:194
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.
A class containing constants representing the names of configuration variables.
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.
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.