23use Wikimedia\ScopedCallback;
43 parent::__construct(
'Confirmemail',
'editmyprivateinfo' );
45 $this->userFactory = $userFactory;
72 if ( !$this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) ) {
76 if ( $code ===
null || $code ===
'' ) {
77 $this->
requireNamedUser(
'confirmemail_needlogin',
'exception-nologin',
true );
78 if ( Sanitizer::validateEmail( $this->
getUser()->getEmail() ) ) {
79 $this->showRequestForm();
81 $this->
getOutput()->addWikiMsg(
'confirmemail_noemail' );
84 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
85 $this->attemptConfirm( $code );
86 ScopedCallback::consume( $scope );
93 private function showRequestForm() {
97 if ( !$user->isEmailConfirmed() ) {
99 if ( $user->isEmailConfirmationPending() ) {
104 'default' =>
"<div class=\"error mw-confirmemail-pending\">\n" .
105 $this->
msg(
'confirmemail_pending' )->escaped() .
111 $out->addWikiMsg(
'confirmemail_text' );
112 $form = HTMLForm::factory(
'ooui', $descriptor, $this->
getContext() );
115 ->setSubmitTextMsg(
'confirmemail_send' )
116 ->setSubmitCallback( $this->submitSend( ... ) );
118 $retval = $form->show();
120 if ( $retval ===
true || ( $retval instanceof Status && $retval->isGood() ) ) {
121 $out->addWikiMsg(
'confirmemail_sent' );
128 $emailAuthenticated = $user->getEmailAuthenticationTimestamp();
129 $time = $lang->userTimeAndDate( $emailAuthenticated, $user );
130 $d = $lang->userDate( $emailAuthenticated, $user );
131 $t = $lang->userTime( $emailAuthenticated, $user );
132 $out->addWikiMsg(
'emailauthenticated', $time, $d, $t );
141 private function submitSend() {
142 $status = $this->
getUser()->sendConfirmationMail();
143 if ( $status->isGood() ) {
144 return Status::newGood();
146 return Status::newFatal(
new RawMessage(
147 $status->getWikiText(
'confirmemail_sendfailed',
false, $this->getLanguage() )
158 private function attemptConfirm( $code ) {
159 $user = $this->userFactory->newFromConfirmationCode(
161 IDBAccessObject::READ_LATEST
164 if ( !is_object( $user ) ) {
165 if ( User::isWellFormedConfirmationToken( $code ) ) {
166 $this->
getOutput()->addWikiMsg(
'confirmemail_invalid' );
168 $this->
getOutput()->addWikiMsg(
'confirmemail_invalid_format' );
177 $userLatest = $user->getInstanceFromPrimary() ??
throw new LogicException(
'No user' );
178 $userLatest->confirmEmail();
179 $userLatest->saveSettings();
180 $message = $this->
getUser()->isNamed() ?
'confirmemail_loggedin' :
'confirmemail_success';
181 $this->
getOutput()->addWikiMsg( $message );
183 if ( !$this->
getUser()->isNamed() ) {
185 $this->
getOutput()->returnToMain(
true, $title );
191class_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.