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