| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Specials; |
| 4 |
|
| 5 |
use ErrorPageError; |
| 6 |
use MediaWiki\Auth\AuthenticationResponse; |
| 7 |
use MediaWiki\Auth\AuthManager; |
| 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 |
|
| 16 |
|
| 17 |
|
| 18 |
class SpecialUnlinkAccounts extends AuthManagerSpecialPage { |
| 19 |
|
| 20 |
protected static $allowedActions = [ AuthManager::ACTION_UNLINK ]; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function __construct( AuthManager $authManager ) { |
| 26 |
parent::__construct( 'UnlinkAccounts' ); |
| 27 |
$this->setAuthManager( $authManager ); |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
public function getRestriction(): string { |
| 32 |
return 'editmyprivateinfo'; |
| 33 |
} |
| 34 |
|
| 35 |
protected function getLoginSecurityLevel() { |
| 36 |
return 'UnlinkAccount'; |
| 37 |
} |
| 38 |
|
| 39 |
protected function getDefaultAction( $subPage ) { |
| 40 |
return AuthManager::ACTION_UNLINK; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
protected function getGroupName() { |
| 48 |
return 'login'; |
| 49 |
} |
| 50 |
|
| 51 |
public function isListed() { |
| 52 |
return $this->getAuthManager()->canLinkAccounts(); |
| 53 |
} |
| 54 |
|
| 55 |
protected function getRequestBlacklist() { |
| 56 |
return $this->getConfig()->get( MainConfigNames::RemoveCredentialsBlacklist ); |
| 57 |
} |
| 58 |
|
| 59 |
public function execute( $subPage ) { |
| 60 |
$this->setHeaders(); |
| 61 |
$this->loadAuth( $subPage ); |
| 62 |
|
| 63 |
if ( !$this->isActionAllowed( $this->authAction ) ) { |
| 64 |
if ( $this->authAction === AuthManager::ACTION_UNLINK ) { |
| 65 |
|
| 66 |
$titleMessage = $this->msg( 'cannotunlink-no-provider-title' ); |
| 67 |
$errorMessage = $this->msg( 'cannotunlink-no-provider' ); |
| 68 |
throw new ErrorPageError( $titleMessage, $errorMessage ); |
| 69 |
} else { |
| 70 |
|
| 71 |
|
| 72 |
$this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) ); |
| 73 |
return; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
$this->outputHeader(); |
| 78 |
|
| 79 |
$status = $this->trySubmit(); |
| 80 |
|
| 81 |
if ( $status === false || !$status->isOK() ) { |
| 82 |
$this->displayForm( $status ); |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
$response = $status->getValue(); |
| 88 |
|
| 89 |
if ( $response->status === AuthenticationResponse::FAIL ) { |
| 90 |
$this->displayForm( StatusValue::newFatal( $response->message ) ); |
| 91 |
return; |
| 92 |
} |
| 93 |
|
| 94 |
$status = StatusValue::newGood(); |
| 95 |
$status->warning( $this->msg( 'unlinkaccounts-success' ) ); |
| 96 |
$this->loadAuth( $subPage, null, true ); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
$session = $this->getRequest()->getSession(); |
| 101 |
$user = $this->getUser(); |
| 102 |
SessionManager::singleton()->invalidateSessionsForUser( $user ); |
| 103 |
$session->setUser( $user ); |
| 104 |
$session->resetId(); |
| 105 |
|
| 106 |
$this->displayForm( $status ); |
| 107 |
} |
| 108 |
|
| 109 |
public function handleFormSubmit( $data ) { |
| 110 |
|
| 111 |
|
| 112 |
$response = $this->performAuthenticationStep( $this->authAction, $this->authRequests ); |
| 113 |
return Status::newGood( $response ); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
class_alias( SpecialUnlinkAccounts::class, 'SpecialUnlinkAccounts' ); |