MediaWiki  master
SpecialEmailInvalidate.php
Go to the documentation of this file.
1 <?php
25 use 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();
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 }
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
Profiler\instance
static instance()
Singleton.
Definition: Profiler.php:69
UnlistedSpecialPage
Shortcut to construct a special page which is unlisted by default.
Definition: UnlistedSpecialPage.php:31
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:358
SpecialEmailInvalidate
Special page allows users to cancel an email confirmation using the e-mail confirmation code.
Definition: SpecialEmailInvalidate.php:33
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:618
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:800
SpecialEmailInvalidate\execute
execute( $code)
Default execute method Checks user permissions.
Definition: SpecialEmailInvalidate.php:51
SpecialEmailInvalidate\$userFactory
UserFactory $userFactory
Definition: SpecialEmailInvalidate.php:36
SpecialEmailInvalidate\__construct
__construct(UserFactory $userFactory)
Definition: SpecialEmailInvalidate.php:41
SpecialEmailInvalidate\attemptInvalidate
attemptInvalidate( $code)
Attempt to invalidate the user's email address and show success or failure as needed; if successful,...
Definition: SpecialEmailInvalidate.php:71
SpecialEmailInvalidate\doesWrites
doesWrites()
Indicates whether this special page may perform database writes.
Definition: SpecialEmailInvalidate.php:47
SpecialPage\checkReadOnly
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
Definition: SpecialPage.php:371
MediaWiki\User\UserFactory
Creates User objects.
Definition: UserFactory.php:41