MediaWiki REL1_40
SpecialEmailInvalidate.php
Go to the documentation of this file.
1<?php
25use Wikimedia\ScopedCallback;
26
34
36 private $userFactory;
37
41 public function __construct( UserFactory $userFactory ) {
42 parent::__construct( 'Invalidateemail', 'editmyprivateinfo' );
43
44 $this->userFactory = $userFactory;
45 }
46
47 public function doesWrites() {
48 return true;
49 }
50
51 public function execute( $code ) {
52 // Ignore things like primary queries/connections on GET requests.
53 // It's very convenient to just allow formless link usage.
54 $trxProfiler = Profiler::instance()->getTransactionProfiler();
55
56 $this->setHeaders();
57 $this->checkReadOnly();
58 $this->checkPermissions();
59
60 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
61 $this->attemptInvalidate( $code );
62 ScopedCallback::consume( $scope );
63 }
64
71 private function attemptInvalidate( $code ) {
72 $user = $this->userFactory->newFromConfirmationCode(
73 (string)$code,
74 UserFactory::READ_LATEST
75 );
76
77 if ( !is_object( $user ) ) {
78 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
79
80 return;
81 }
82
83 $user->invalidateEmail();
84 $user->saveSettings();
85 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
86
87 if ( !$this->getUser()->isRegistered() ) {
88 $this->getOutput()->returnToMain();
89 }
90 }
91}
Creates User objects.
Special page allows users to cancel an email confirmation using the e-mail confirmation code.
doesWrites()
Indicates whether this special page may perform database writes.
execute( $code)
Default execute method Checks user permissions.
__construct(UserFactory $userFactory)
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
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.
Shortcut to construct a special page which is unlisted by default.