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