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.
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.
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
21 namespace MediaWiki\Specials
;
23 use MediaWiki\SpecialPage\UnlistedSpecialPage
;
24 use MediaWiki\User\UserFactory
;
26 use Wikimedia\Rdbms\IDBAccessObject
;
27 use Wikimedia\ScopedCallback
;
30 * Cancel an email confirmation using the e-mail confirmation code.
32 * @see SpecialConfirmEmail
33 * @ingroup SpecialPage
36 class SpecialEmailInvalidate
extends UnlistedSpecialPage
{
38 private UserFactory
$userFactory;
41 * @param UserFactory $userFactory
43 public function __construct( UserFactory
$userFactory ) {
44 parent
::__construct( 'Invalidateemail', 'editmyprivateinfo' );
46 $this->userFactory
= $userFactory;
49 public function doesWrites() {
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();
59 $this->checkReadOnly();
60 $this->checkPermissions();
62 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY
);
63 $this->attemptInvalidate( $code );
64 ScopedCallback
::consume( $scope );
68 * Attempt to invalidate the user's email address and show success or failure
69 * as needed; if successful, link to main page
71 * @param string $code Confirmation code
73 private function attemptInvalidate( $code ) {
74 $user = $this->userFactory
->newFromConfirmationCode(
76 IDBAccessObject
::READ_LATEST
79 if ( !is_object( $user ) ) {
80 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
85 $user->invalidateEmail();
86 $user->saveSettings();
87 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
89 if ( !$this->getUser()->isRegistered() ) {
90 $this->getOutput()->returnToMain();
95 /** @deprecated class alias since 1.41 */
96 class_alias( SpecialEmailInvalidate
::class, 'SpecialEmailInvalidate' );