Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
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 / 23
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 / 13
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 MediaWiki\SpecialPage\UnlistedSpecialPage;
24use MediaWiki\User\UserFactory;
25use Profiler;
26use Wikimedia\Rdbms\IDBAccessObject;
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    public function __construct( UserFactory $userFactory ) {
41        parent::__construct( 'Invalidateemail', 'editmyprivateinfo' );
42
43        $this->userFactory = $userFactory;
44    }
45
46    public function doesWrites() {
47        return true;
48    }
49
50    public function execute( $code ) {
51        // Ignore things like primary queries/connections on GET requests.
52        // It's very convenient to just allow formless link usage.
53        $trxProfiler = Profiler::instance()->getTransactionProfiler();
54
55        $this->setHeaders();
56        $this->checkReadOnly();
57        $this->checkPermissions();
58
59        $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
60        $this->attemptInvalidate( $code );
61        ScopedCallback::consume( $scope );
62    }
63
64    /**
65     * Attempt to invalidate the user's email address and show success or failure
66     * as needed; if successful, link to main page
67     *
68     * @param string $code Confirmation code
69     */
70    private function attemptInvalidate( $code ) {
71        $user = $this->userFactory->newFromConfirmationCode(
72            (string)$code,
73            IDBAccessObject::READ_LATEST
74        );
75
76        if ( !is_object( $user ) ) {
77            $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
78
79            return;
80        }
81
82        $userLatest = $user->getInstanceForUpdate();
83        $userLatest->invalidateEmail();
84        $userLatest->saveSettings();
85        $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
86
87        if ( !$this->getUser()->isRegistered() ) {
88            $this->getOutput()->returnToMain();
89        }
90    }
91}
92
93/** @deprecated class alias since 1.41 */
94class_alias( SpecialEmailInvalidate::class, 'SpecialEmailInvalidate' );