Debian Codegraph @

includes/specials/SpecialUnlinkAccounts.php

raw symbols SCIP
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 * @ingroup SpecialPage
16 * @ingroup Auth
17 */
18 class SpecialUnlinkAccounts extends AuthManagerSpecialPage {
19 /** @inheritDoc */
20 protected static $allowedActions = [ AuthManager::ACTION_UNLINK ];
21
22 /**
23 * @param AuthManager $authManager
24 */
25 public function __construct( AuthManager $authManager ) {
26 parent::__construct( 'UnlinkAccounts' );
27 $this->setAuthManager( $authManager );
28 }
29
30 /** @inheritDoc */
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 * Under which header this special page is listed in Special:SpecialPages.
45 * @return string
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 // Looks like there are no linked accounts to unlink
66 $titleMessage = $this->msg( 'cannotunlink-no-provider-title' );
67 $errorMessage = $this->msg( 'cannotunlink-no-provider' );
68 throw new ErrorPageError( $titleMessage, $errorMessage );
69 } else {
70 // user probably back-button-navigated into an auth session that no longer exists
71 // FIXME would be nice to show a message
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 /** @var AuthenticationResponse $response */
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 ); // update requests so the unlinked one doesn't show up
97
98 // Reset sessions - if the user unlinked an account because it was compromised,
99 // log attackers out from sessions obtained via that account.
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 // unlink requests do not accept user input so repeat parent code but skip call to
111 // AuthenticationRequest::loadRequestsFromSubmission
112 $response = $this->performAuthenticationStep( $this->authAction, $this->authRequests );
113 return Status::newGood( $response );
114 }
115 }
116
117 /**
118 * Retain the old class name for backwards compatibility.
119 * @deprecated since 1.41
120 */
121 class_alias( SpecialUnlinkAccounts::class, 'SpecialUnlinkAccounts' );