MediaWiki master
SpecialEmailInvalidate.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
9use LogicException;
14use Wikimedia\ScopedCallback;
15
24
25 public function __construct(
26 private readonly UserFactory $userFactory,
27 ) {
28 parent::__construct( 'Invalidateemail', 'editmyprivateinfo' );
29 }
30
32 public function doesWrites() {
33 return true;
34 }
35
37 public function execute( $code ) {
38 // Ignore things like primary queries/connections on GET requests.
39 // It's very convenient to just allow formless link usage.
40 $trxProfiler = Profiler::instance()->getTransactionProfiler();
41
42 $this->setHeaders();
43 $this->checkReadOnly();
44 $this->checkPermissions();
45
46 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
47 $this->attemptInvalidate( $code );
48 ScopedCallback::consume( $scope );
49 }
50
57 private function attemptInvalidate( $code ) {
58 $user = $this->userFactory->newFromConfirmationCode(
59 (string)$code,
60 IDBAccessObject::READ_LATEST
61 );
62
63 if ( !is_object( $user ) ) {
64 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
65
66 return;
67 }
68
69 $userLatest = $user->getInstanceFromPrimary() ?? throw new LogicException( 'No user' );
70 $userLatest->invalidateEmail();
71 $userLatest->saveSettings();
72 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
73
74 if ( !$this->getUser()->isRegistered() ) {
75 $this->getOutput()->returnToMain();
76 }
77 }
78}
79
81class_alias( SpecialEmailInvalidate::class, 'SpecialEmailInvalidate' );
Profiler base class that defines the interface and some shared functionality.
Definition Profiler.php:25
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.This must be overridden by subclasses; it will be made...
doesWrites()
Indicates whether POST requests to this special page require write access to the wiki....
__construct(private readonly UserFactory $userFactory,)
Create User objects.
Interface for database access objects.