Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
SpecialUnlinkAccounts | |
0.00% |
0 / 36 |
|
0.00% |
0 / 8 |
182 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getLoginSecurityLevel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isListed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRequestBlacklist | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
42 | |||
handleFormSubmit | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Specials; |
4 | |
5 | use MediaWiki\Auth\AuthenticationResponse; |
6 | use MediaWiki\Auth\AuthManager; |
7 | use MediaWiki\Exception\ErrorPageError; |
8 | use MediaWiki\MainConfigNames; |
9 | use MediaWiki\Session\SessionManager; |
10 | use MediaWiki\SpecialPage\AuthManagerSpecialPage; |
11 | use MediaWiki\Status\Status; |
12 | use StatusValue; |
13 | |
14 | /** |
15 | * @ingroup SpecialPage |
16 | * @ingroup Auth |
17 | */ |
18 | class SpecialUnlinkAccounts extends AuthManagerSpecialPage { |
19 | /** @inheritDoc */ |
20 | protected static $allowedActions = [ AuthManager::ACTION_UNLINK ]; |
21 | |
22 | public function __construct( AuthManager $authManager ) { |
23 | parent::__construct( 'UnlinkAccounts' ); |
24 | $this->setAuthManager( $authManager ); |
25 | } |
26 | |
27 | protected function getLoginSecurityLevel() { |
28 | return 'UnlinkAccount'; |
29 | } |
30 | |
31 | protected function getDefaultAction( $subPage ) { |
32 | return AuthManager::ACTION_UNLINK; |
33 | } |
34 | |
35 | /** |
36 | * Under which header this special page is listed in Special:SpecialPages. |
37 | * @return string |
38 | */ |
39 | protected function getGroupName() { |
40 | return 'login'; |
41 | } |
42 | |
43 | public function isListed() { |
44 | return $this->getAuthManager()->canLinkAccounts(); |
45 | } |
46 | |
47 | protected function getRequestBlacklist() { |
48 | return $this->getConfig()->get( MainConfigNames::RemoveCredentialsBlacklist ); |
49 | } |
50 | |
51 | public function execute( $subPage ) { |
52 | $this->setHeaders(); |
53 | $this->loadAuth( $subPage ); |
54 | |
55 | if ( !$this->isActionAllowed( $this->authAction ) ) { |
56 | if ( $this->authAction === AuthManager::ACTION_UNLINK ) { |
57 | // Looks like there are no linked accounts to unlink |
58 | $titleMessage = $this->msg( 'cannotunlink-no-provider-title' ); |
59 | $errorMessage = $this->msg( 'cannotunlink-no-provider' ); |
60 | throw new ErrorPageError( $titleMessage, $errorMessage ); |
61 | } else { |
62 | // user probably back-button-navigated into an auth session that no longer exists |
63 | // FIXME would be nice to show a message |
64 | $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) ); |
65 | return; |
66 | } |
67 | } |
68 | |
69 | $this->outputHeader(); |
70 | |
71 | $status = $this->trySubmit(); |
72 | |
73 | if ( $status === false || !$status->isOK() ) { |
74 | $this->displayForm( $status ); |
75 | return; |
76 | } |
77 | |
78 | /** @var AuthenticationResponse $response */ |
79 | $response = $status->getValue(); |
80 | |
81 | if ( $response->status === AuthenticationResponse::FAIL ) { |
82 | $this->displayForm( StatusValue::newFatal( $response->message ) ); |
83 | return; |
84 | } |
85 | |
86 | $status = StatusValue::newGood(); |
87 | $status->warning( $this->msg( 'unlinkaccounts-success' ) ); |
88 | $this->loadAuth( $subPage, null, true ); // update requests so the unlinked one doesn't show up |
89 | |
90 | // Reset sessions - if the user unlinked an account because it was compromised, |
91 | // log attackers out from sessions obtained via that account. |
92 | $session = $this->getRequest()->getSession(); |
93 | $user = $this->getUser(); |
94 | SessionManager::singleton()->invalidateSessionsForUser( $user ); |
95 | $session->setUser( $user ); |
96 | $session->resetId(); |
97 | |
98 | $this->displayForm( $status ); |
99 | } |
100 | |
101 | public function handleFormSubmit( $data ) { |
102 | // unlink requests do not accept user input so repeat parent code but skip call to |
103 | // AuthenticationRequest::loadRequestsFromSubmission |
104 | $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests ); |
105 | return Status::newGood( $response ); |
106 | } |
107 | } |
108 | |
109 | /** |
110 | * Retain the old class name for backwards compatibility. |
111 | * @deprecated since 1.41 |
112 | */ |
113 | class_alias( SpecialUnlinkAccounts::class, 'SpecialUnlinkAccounts' ); |