Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialEmailInvalidate
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 4
42
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
 doesWrites
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 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 attemptInvalidate
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Specials;
22
23use IDBAccessObject;
24use MediaWiki\SpecialPage\UnlistedSpecialPage;
25use MediaWiki\User\UserFactory;
26use Profiler;
27use Wikimedia\ScopedCallback;
28
29/**
30 * Cancel an email confirmation using the e-mail confirmation code.
31 *
32 * @see SpecialConfirmEmail
33 * @ingroup SpecialPage
34 * @ingroup Auth
35 */
36class SpecialEmailInvalidate extends UnlistedSpecialPage {
37
38    private UserFactory $userFactory;
39
40    /**
41     * @param UserFactory $userFactory
42     */
43    public function __construct( UserFactory $userFactory ) {
44        parent::__construct( 'Invalidateemail', 'editmyprivateinfo' );
45
46        $this->userFactory = $userFactory;
47    }
48
49    public function doesWrites() {
50        return true;
51    }
52
53    public function execute( $code ) {
54        // Ignore things like primary queries/connections on GET requests.
55        // It's very convenient to just allow formless link usage.
56        $trxProfiler = Profiler::instance()->getTransactionProfiler();
57
58        $this->setHeaders();
59        $this->checkReadOnly();
60        $this->checkPermissions();
61
62        $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
63        $this->attemptInvalidate( $code );
64        ScopedCallback::consume( $scope );
65    }
66
67    /**
68     * Attempt to invalidate the user's email address and show success or failure
69     * as needed; if successful, link to main page
70     *
71     * @param string $code Confirmation code
72     */
73    private function attemptInvalidate( $code ) {
74        $user = $this->userFactory->newFromConfirmationCode(
75            (string)$code,
76            IDBAccessObject::READ_LATEST
77        );
78
79        if ( !is_object( $user ) ) {
80            $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
81
82            return;
83        }
84
85        $user->invalidateEmail();
86        $user->saveSettings();
87        $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
88
89        if ( !$this->getUser()->isRegistered() ) {
90            $this->getOutput()->returnToMain();
91        }
92    }
93}
94
95/** @deprecated class alias since 1.41 */
96class_alias( SpecialEmailInvalidate::class, 'SpecialEmailInvalidate' );