MediaWiki  1.34.0
SpecialUnlinkAccounts.php
Go to the documentation of this file.
1 <?php
2 
6 
8  protected static $allowedActions = [ AuthManager::ACTION_UNLINK ];
9 
10  public function __construct() {
11  parent::__construct( 'UnlinkAccounts' );
12  }
13 
14  protected function getLoginSecurityLevel() {
15  return 'UnlinkAccount';
16  }
17 
18  protected function getDefaultAction( $subPage ) {
19  return AuthManager::ACTION_UNLINK;
20  }
21 
26  protected function getGroupName() {
27  return 'users';
28  }
29 
30  public function isListed() {
31  return AuthManager::singleton()->canLinkAccounts();
32  }
33 
34  protected function getRequestBlacklist() {
35  return $this->getConfig()->get( 'RemoveCredentialsBlacklist' );
36  }
37 
38  public function execute( $subPage ) {
39  $this->setHeaders();
40  $this->loadAuth( $subPage );
41 
42  if ( !$this->isActionAllowed( $this->authAction ) ) {
43  if ( $this->authAction === AuthManager::ACTION_UNLINK ) {
44  // Looks like there are no linked accounts to unlink
45  $titleMessage = $this->msg( 'cannotunlink-no-provider-title' );
46  $errorMessage = $this->msg( 'cannotunlink-no-provider' );
47  throw new ErrorPageError( $titleMessage, $errorMessage );
48  } else {
49  // user probably back-button-navigated into an auth session that no longer exists
50  // FIXME would be nice to show a message
51  $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) );
52  return;
53  }
54  }
55 
56  $this->outputHeader();
57 
58  $status = $this->trySubmit();
59 
60  if ( $status === false || !$status->isOK() ) {
61  $this->displayForm( $status );
62  return;
63  }
64 
66  $response = $status->getValue();
67 
68  if ( $response->status === AuthenticationResponse::FAIL ) {
69  $this->displayForm( StatusValue::newFatal( $response->message ) );
70  return;
71  }
72 
74  $status->warning( $this->msg( 'unlinkaccounts-success' ) );
75  $this->loadAuth( $subPage, null, true ); // update requests so the unlinked one doesn't show up
76 
77  // Reset sessions - if the user unlinked an account because it was compromised,
78  // log attackers out from sessions obtained via that account.
79  $session = $this->getRequest()->getSession();
80  $user = $this->getUser();
81  SessionManager::singleton()->invalidateSessionsForUser( $user );
82  $session->setUser( $user );
83  $session->resetId();
84 
85  $this->displayForm( $status );
86  }
87 
88  public function handleFormSubmit( $data ) {
89  // unlink requests do not accept user input so repeat parent code but skip call to
90  // AuthenticationRequest::loadRequestsFromSubmission
91  $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests );
92  return Status::newGood( $response );
93  }
94 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:672
SpecialUnlinkAccounts\getLoginSecurityLevel
getLoginSecurityLevel()
Tells if the special page does something security-sensitive and needs extra defense against a stolen ...
Definition: SpecialUnlinkAccounts.php:14
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:792
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:69
$response
$response
Definition: opensearch_desc.php:38
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:719
SpecialUnlinkAccounts\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialUnlinkAccounts.php:30
AuthManagerSpecialPage
A special page subclass for authentication-related special pages.
Definition: AuthManagerSpecialPage.php:14
SpecialUnlinkAccounts\__construct
__construct()
Definition: SpecialUnlinkAccounts.php:10
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:18
AuthManagerSpecialPage\$subPage
string $subPage
Subpage of the special page.
Definition: AuthManagerSpecialPage.php:35
AuthManagerSpecialPage\performAuthenticationStep
performAuthenticationStep( $action, array $requests)
Definition: AuthManagerSpecialPage.php:343
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:758
SpecialUnlinkAccounts\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages.
Definition: SpecialUnlinkAccounts.php:26
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:38
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:34
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:537
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:729
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:200
SpecialUnlinkAccounts\handleFormSubmit
handleFormSubmit( $data)
Submit handler callback for HTMLForm.
Definition: SpecialUnlinkAccounts.php:88
SpecialUnlinkAccounts
Definition: SpecialUnlinkAccounts.php:7
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:50
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:85
$status
return $status
Definition: SyntaxHighlight.php:347
AuthManagerSpecialPage\isActionAllowed
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
Definition: AuthManagerSpecialPage.php:303
SpecialUnlinkAccounts\$allowedActions
static $allowedActions
Definition: SpecialUnlinkAccounts.php:8
AuthManagerSpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: AuthManagerSpecialPage.php:64
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:639