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;
40 public function __construct( UserFactory
$userFactory ) {
41 parent
::__construct( 'Invalidateemail', 'editmyprivateinfo' );
43 $this->userFactory
= $userFactory;
46 public function doesWrites() {
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();
56 $this->checkReadOnly();
57 $this->checkPermissions();
59 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY
);
60 $this->attemptInvalidate( $code );
61 ScopedCallback
::consume( $scope );
65 * Attempt to invalidate the user's email address and show success or failure
66 * as needed; if successful, link to main page
68 * @param string $code Confirmation code
70 private function attemptInvalidate( $code ) {
71 $user = $this->userFactory
->newFromConfirmationCode(
73 IDBAccessObject
::READ_LATEST
76 if ( !is_object( $user ) ) {
77 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
82 $userLatest = $user->getInstanceForUpdate();
83 $userLatest->invalidateEmail();
84 $userLatest->saveSettings();
85 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
87 if ( !$this->getUser()->isRegistered() ) {
88 $this->getOutput()->returnToMain();
93 /** @deprecated class alias since 1.41 */
94 class_alias( SpecialEmailInvalidate
::class, 'SpecialEmailInvalidate' );