36use Wikimedia\ScopedCallback;
56 parent::__construct(
'Confirmemail',
'editmyprivateinfo' );
58 $this->userFactory = $userFactory;
84 if ( !$this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) ) {
88 if ( $code ===
null || $code ===
'' ) {
89 $this->
requireNamedUser(
'confirmemail_needlogin',
'exception-nologin',
true );
90 if ( Sanitizer::validateEmail( $this->
getUser()->getEmail() ) ) {
91 $this->showRequestForm();
93 $this->
getOutput()->addWikiMsg(
'confirmemail_noemail' );
96 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
97 $this->attemptConfirm( $code );
98 ScopedCallback::consume( $scope );
105 private function showRequestForm() {
109 if ( !$user->isEmailConfirmed() ) {
111 if ( $user->isEmailConfirmationPending() ) {
116 'default' =>
"<div class=\"error mw-confirmemail-pending\">\n" .
117 $this->
msg(
'confirmemail_pending' )->escaped() .
123 $out->addWikiMsg(
'confirmemail_text' );
124 $form = HTMLForm::factory(
'ooui', $descriptor, $this->
getContext() );
127 ->setSubmitTextMsg(
'confirmemail_send' )
128 ->setSubmitCallback( [ $this,
'submitSend' ] );
130 $retval = $form->show();
132 if ( $retval ===
true ) {
134 $out->addWikiMsg(
'confirmemail_sent' );
135 } elseif ( $retval instanceof Status && $retval->isGood() ) {
136 $out->addWikiTextAsInterface( $retval->getValue() );
143 $emailAuthenticated = $user->getEmailAuthenticationTimestamp();
144 $time = $lang->userTimeAndDate( $emailAuthenticated, $user );
145 $d = $lang->userDate( $emailAuthenticated, $user );
146 $t = $lang->userTime( $emailAuthenticated, $user );
147 $out->addWikiMsg(
'emailauthenticated', $time, $d, $t );
157 $status = $this->
getUser()->sendConfirmationMail();
158 if ( $status->isGood() ) {
159 return Status::newGood( $this->
msg(
'confirmemail_sent' )->text() );
162 $status->getWikiText(
'confirmemail_sendfailed',
false, $this->getLanguage() )
173 private function attemptConfirm( $code ) {
174 $user = $this->userFactory->newFromConfirmationCode(
176 IDBAccessObject::READ_LATEST
179 if ( !is_object( $user ) ) {
180 if ( User::isWellFormedConfirmationToken( $code ) ) {
181 $this->
getOutput()->addWikiMsg(
'confirmemail_invalid' );
183 $this->
getOutput()->addWikiMsg(
'confirmemail_invalid_format' );
192 $userLatest = $user->getInstanceForUpdate();
193 $userLatest->confirmEmail();
194 $userLatest->saveSettings();
195 $message = $this->
getUser()->isNamed() ?
'confirmemail_loggedin' :
'confirmemail_success';
196 $this->
getOutput()->addWikiMsg( $message );
198 if ( !$this->
getUser()->isNamed() ) {
200 $this->
getOutput()->returnToMain(
true, $title );
206class_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.
Profiler base class that defines the interface and some shared functionality.