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