MediaWiki master
SpecialEmailInvalidate.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
25use Profiler;
27use Wikimedia\ScopedCallback;
28
37
38 private UserFactory $userFactory;
39
43 public function __construct( UserFactory $userFactory ) {
44 parent::__construct( 'Invalidateemail', 'editmyprivateinfo' );
45
46 $this->userFactory = $userFactory;
47 }
48
49 public function doesWrites() {
50 return true;
51 }
52
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();
57
58 $this->setHeaders();
59 $this->checkReadOnly();
60 $this->checkPermissions();
61
62 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
63 $this->attemptInvalidate( $code );
64 ScopedCallback::consume( $scope );
65 }
66
73 private function attemptInvalidate( $code ) {
74 $user = $this->userFactory->newFromConfirmationCode(
75 (string)$code,
76 IDBAccessObject::READ_LATEST
77 );
78
79 if ( !is_object( $user ) ) {
80 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
81
82 return;
83 }
84
85 $user->invalidateEmail();
86 $user->saveSettings();
87 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
88
89 if ( !$this->getUser()->isRegistered() ) {
90 $this->getOutput()->returnToMain();
91 }
92 }
93}
94
96class_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.
Cancel an email confirmation using the e-mail confirmation code.
execute( $code)
Default execute method Checks user permissions.
doesWrites()
Indicates whether POST requests to this special page require write access to the wiki.
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.