MediaWiki  master
SpecialUnlinkAccounts.php
Go to the documentation of this file.
1 <?php
2 
6 
8  protected static $allowedActions = [ AuthManager::ACTION_UNLINK ];
9 
13  public function __construct( AuthManager $authManager ) {
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 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:768
SpecialUnlinkAccounts\getLoginSecurityLevel
getLoginSecurityLevel()
Definition: SpecialUnlinkAccounts.php:18
AuthManagerSpecialPage\displayForm
displayForm( $status)
Display the form.
Definition: AuthManagerSpecialPage.php:570
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:936
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
PROTO_HTTPS
const PROTO_HTTPS
Definition: Defines.php:193
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:814
SpecialUnlinkAccounts\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialUnlinkAccounts.php:34
AuthManagerSpecialPage
A special page subclass for authentication-related special pages.
Definition: AuthManagerSpecialPage.php:18
SpecialPage\$authManager
AuthManager null $authManager
Definition: SpecialPage.php:88
AuthManagerSpecialPage\trySubmit
trySubmit()
Attempts to do an authentication step with the submitted data.
Definition: AuthManagerSpecialPage.php:416
SpecialUnlinkAccounts\getDefaultAction
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
Definition: SpecialUnlinkAccounts.php:22
AuthManagerSpecialPage\$subPage
string $subPage
Subpage of the special page.
Definition: AuthManagerSpecialPage.php:39
AuthManagerSpecialPage\performAuthenticationStep
performAuthenticationStep( $action, array $requests)
Definition: AuthManagerSpecialPage.php:361
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:902
SpecialUnlinkAccounts\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages.
Definition: SpecialUnlinkAccounts.php:30
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:42
AuthManagerSpecialPage\loadAuth
loadAuth( $subPage, $authAction=null, $reset=false)
Load or initialize $authAction, $authRequests and $subPage.
Definition: AuthManagerSpecialPage.php:250
SpecialPage\setAuthManager
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
Definition: SpecialPage.php:534
SpecialUnlinkAccounts\getRequestBlacklist
getRequestBlacklist()
Allows blacklisting certain request types.
Definition: SpecialUnlinkAccounts.php:38
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:642
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:824
SpecialUnlinkAccounts\handleFormSubmit
handleFormSubmit( $data)
Submit handler callback for HTMLForm.
Definition: SpecialUnlinkAccounts.php:92
SpecialUnlinkAccounts
Definition: SpecialUnlinkAccounts.php:7
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:83
SpecialUnlinkAccounts\__construct
__construct(AuthManager $authManager)
Definition: SpecialUnlinkAccounts.php:13
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:102
AuthManagerSpecialPage\isActionAllowed
isActionAllowed( $action)
Checks whether AuthManager is ready to perform the action.
Definition: AuthManagerSpecialPage.php:321
SpecialUnlinkAccounts\$allowedActions
static $allowedActions
Definition: SpecialUnlinkAccounts.php:8
SpecialPage\getAuthManager
getAuthManager()
Definition: SpecialPage.php:544
AuthManagerSpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: AuthManagerSpecialPage.php:72
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30
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:733