MediaWiki master
SpecialEmailInvalidate.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
29use Profiler;
30use Wikimedia\ScopedCallback;
31
39
40 private UserFactory $userFactory;
41
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
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
98class_alias( SpecialEmailInvalidate::class, 'SpecialEmailInvalidate' );
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getOutput()
Get the OutputPage being used for this instance.
Shortcut to construct a special page which is unlisted by default.
Special page allows users to cancel an email confirmation using the e-mail confirmation code.
execute( $code)
Default execute method Checks user permissions.
doesWrites()
Indicates whether this special page may perform database writes.
Creates User objects.
Profiler base class that defines the interface and some shared functionality.
Definition Profiler.php:37
static instance()
Definition Profiler.php:105
Interface for database access objects.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...