36use Wikimedia\ScopedCallback;
59 parent::__construct(
'Confirmemail',
'editmyprivateinfo' );
61 $this->userFactory = $userFactory;
87 if ( !$this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) ) {
91 if ( $code ===
null || $code ===
'' ) {
92 $this->
requireNamedUser(
'confirmemail_needlogin',
'exception-nologin',
true );
93 if ( Sanitizer::validateEmail( $this->
getUser()->getEmail() ) ) {
94 $this->showRequestForm();
96 $this->
getOutput()->addWikiMsg(
'confirmemail_noemail' );
99 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
100 $this->attemptConfirm( $code );
101 ScopedCallback::consume( $scope );
108 private function showRequestForm() {
112 if ( !$user->isEmailConfirmed() ) {
114 if ( $user->isEmailConfirmationPending() ) {
119 'default' =>
"<div class=\"error mw-confirmemail-pending\">\n" .
120 $this->
msg(
'confirmemail_pending' )->escaped() .
126 $out->addWikiMsg(
'confirmemail_text' );
127 $form = HTMLForm::factory(
'ooui', $descriptor, $this->
getContext() );
130 ->setSubmitTextMsg(
'confirmemail_send' )
131 ->setSubmitCallback( [ $this,
'submitSend' ] );
133 $retval = $form->show();
135 if ( $retval ===
true ) {
137 $out->addWikiMsg(
'confirmemail_sent' );
138 } elseif ( $retval instanceof Status && $retval->isGood() ) {
139 $out->addWikiTextAsInterface( $retval->getValue() );
146 $emailAuthenticated = $user->getEmailAuthenticationTimestamp();
147 $time = $lang->userTimeAndDate( $emailAuthenticated, $user );
148 $d = $lang->userDate( $emailAuthenticated, $user );
149 $t = $lang->userTime( $emailAuthenticated, $user );
150 $out->addWikiMsg(
'emailauthenticated', $time, $d, $t );
160 $status = $this->
getUser()->sendConfirmationMail();
161 if ( $status->isGood() ) {
162 return Status::newGood( $this->
msg(
'confirmemail_sent' )->text() );
165 $status->getWikiText(
'confirmemail_sendfailed',
false, $this->getLanguage() )
176 private function attemptConfirm( $code ) {
177 $user = $this->userFactory->newFromConfirmationCode(
179 IDBAccessObject::READ_LATEST
182 if ( !is_object( $user ) ) {
183 if ( User::isWellFormedConfirmationToken( $code ) ) {
184 $this->
getOutput()->addWikiMsg(
'confirmemail_invalid' );
186 $this->
getOutput()->addWikiMsg(
'confirmemail_invalid_format' );
195 $userLatest = $user->getInstanceForUpdate();
196 $userLatest->confirmEmail();
197 $userLatest->saveSettings();
198 $message = $this->
getUser()->isNamed() ?
'confirmemail_loggedin' :
'confirmemail_success';
199 $this->
getOutput()->addWikiMsg( $message );
201 if ( !$this->
getUser()->isNamed() ) {
203 $this->
getOutput()->returnToMain(
true, $title );
209class_alias( SpecialConfirmEmail::class,
'SpecialConfirmEmail' );
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getUser()
Shortcut to get the User executing this instance.
authorizeAction(?string $action=null)
Utility function for authorizing an action to be performed by the special page.
requireNamedUser( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin', bool $alwaysRedirectToLoginPage=false)
If the user is not logged in or is a temporary user, throws UserNotLoggedIn.
getPageTitle( $subpage=false)
Get a self-referential title object.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getAuthority()
Shortcut to get the Authority executing this instance.
getLanguage()
Shortcut to get user's language.
Shortcut to construct a special page which is unlisted by default.
Show an error when a user tries to do something they do not have the necessary permissions for.
Profiler base class that defines the interface and some shared functionality.
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
Redirect a user to the login page or account creation page.