26use Wikimedia\ScopedCallback;
45 parent::__construct(
'Confirmemail',
'editmyprivateinfo' );
47 $this->userFactory = $userFactory;
65 $trxProfiler = Profiler::instance()->getTransactionProfiler();
73 if ( !$this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) ) {
77 if ( $code ===
null || $code ===
'' ) {
79 if ( Sanitizer::validateEmail( $this->
getUser()->getEmail() ) ) {
80 $this->showRequestForm();
82 $this->
getOutput()->addWikiMsg(
'confirmemail_noemail' );
85 $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY );
86 $this->attemptConfirm( $code );
87 ScopedCallback::consume( $scope );
94 private function showRequestForm() {
98 if ( !$user->isEmailConfirmed() ) {
100 if ( $user->isEmailConfirmationPending() ) {
105 'default' =>
"<div class=\"error mw-confirmemail-pending\">\n" .
106 $this->
msg(
'confirmemail_pending' )->escaped() .
112 $out->addWikiMsg(
'confirmemail_text' );
116 ->setSubmitTextMsg(
'confirmemail_send' )
117 ->setSubmitCallback( [ $this,
'submitSend' ] );
119 $retval = $form->show();
121 if ( $retval ===
true ) {
123 $out->addWikiMsg(
'confirmemail_sent' );
124 } elseif ( $retval instanceof
Status && $retval->
isGood() ) {
125 $out->addWikiTextAsInterface( $retval->getValue() );
132 $emailAuthenticated = $user->getEmailAuthenticationTimestamp();
133 $time =
$lang->userTimeAndDate( $emailAuthenticated, $user );
134 $d =
$lang->userDate( $emailAuthenticated, $user );
135 $t =
$lang->userTime( $emailAuthenticated, $user );
136 $out->addWikiMsg(
'emailauthenticated', $time, $d,
$t );
146 $status = $this->
getUser()->sendConfirmationMail();
147 if ( $status->isGood() ) {
148 return Status::newGood( $this->
msg(
'confirmemail_sent' )->text() );
151 $status->getWikiText(
'confirmemail_sendfailed',
false, $this->getLanguage() )
162 private function attemptConfirm( $code ) {
163 $user = $this->userFactory->newFromConfirmationCode(
165 UserFactory::READ_LATEST
168 if ( !is_object( $user ) ) {
169 $this->
getOutput()->addWikiMsg(
'confirmemail_invalid' );
175 if ( $user->pingLimiter(
'confirmemail' ) ) {
176 $this->
getOutput()->addWikiMsg(
'actionthrottledtext' );
181 $userLatest = $user->getInstanceForUpdate();
182 $userLatest->confirmEmail();
183 $userLatest->saveSettings();
184 $message = $this->
getUser()->isRegistered() ?
'confirmemail_loggedin' :
'confirmemail_success';
185 $this->
getOutput()->addWikiMsg( $message );
187 if ( !$this->
getUser()->isRegistered() ) {
Show an error when a user tries to do something they do not have the necessary permissions for.
Special page allows users to request email confirmation message, and handles processing of the confir...
doesWrites()
Indicates whether this special page may perform database writes.
execute( $code)
Main execution point.
__construct(UserFactory $userFactory)
submitSend()
Callback for HTMLForm send confirmation mail.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
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,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Shortcut to construct a special page which is unlisted by default.
if(!isset( $args[0])) $lang