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