34 parent::__construct(
'ChangeEmail',
'editmyprivateinfo' );
48 return $this->
getAuthManager()->allowsPropertyChange(
'emailaddress' );
57 $out->disallowUserJs();
58 $out->addModules(
'mediawiki.special.changeemail' );
59 parent::execute(
$par );
68 if ( !$this->
getAuthManager()->allowsPropertyChange(
'emailaddress' ) ) {
76 if ( !$this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) ) {
80 parent::checkExecutePermissions( $user );
90 'label-message' =>
'username',
95 'label-message' =>
'changeemail-oldemail',
96 'default' => $user->
getEmail() ?: $this->
msg(
'changeemail-none' )->text(),
100 'label-message' =>
'changeemail-newemail',
103 'help-message' =>
'changeemail-newemail-help',
114 $form->
setId(
'mw-changeemail-form' );
125 $this->status = $this->attemptChange( $this->
getUser(), $data[
'NewEmail'] );
127 return $this->status;
133 $returnTo = $request->getVal(
'returnto' );
134 $titleObj = $returnTo !==
null ? Title::newFromText( $returnTo ) :
null;
135 if ( !$titleObj instanceof
Title ) {
136 $titleObj = Title::newMainPage();
138 $query = $request->getVal(
'returntoquery',
'' );
140 if ( $this->status->value ===
true ) {
141 $this->
getOutput()->redirect( $titleObj->getFullUrlForRedirect( $query ) );
142 } elseif ( $this->status->value ===
'eauth' ) {
143 # Notify user that a confirmation email has been sent...
145 $out->addModuleStyles(
'mediawiki.codex.messagebox.styles' );
148 $out->msg(
'eauthentsent', $this->getUser()->getName() )->parse()
162 private function attemptChange(
User $user, $newAddr ) {
163 if ( $newAddr !==
'' && !Sanitizer::validateEmail( $newAddr ) ) {
164 return Status::newFatal(
'invalidemailaddress' );
168 if ( $newAddr === $oldAddr ) {
169 return Status::newFatal(
'changeemail-nochange' );
172 if ( strlen( $newAddr ) > 255 ) {
173 return Status::newFatal(
'changeemail-maxlength' );
178 if ( $newAddr !==
'' ) {
181 if ( !$status->
isGood() ) {
182 return Status::wrap( $status );
187 $changeStatus = Status::newGood();
189 !$this->
getHookRunner()->onUserCanChangeEmail( $userLatest, $oldAddr, $newAddr, $changeStatus )
190 && !$changeStatus->isGood()
192 return $changeStatus;
195 $status = $userLatest->setEmailWithConfirmation( $newAddr );
196 if ( !$status->
isGood() ) {
200 LoggerFactory::getInstance(
'authentication' )->info(
201 'Changing email address for {user} from {oldemail} to {newemail}', [
202 'user' => $userLatest->getName(),
203 'oldemail' => $oldAddr,
204 'newemail' => $newAddr,
208 $this->
getHookRunner()->onPrefsEmailAudit( $userLatest, $oldAddr, $newAddr );
210 $userLatest->saveSettings();
227class_alias( SpecialChangeEmail::class,
'SpecialChangeEmail' );
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
An error page which can definitely be safely rendered using the OutputPage.
Special page which uses an HTMLForm to handle processing.
string null $par
The subpage of the special page.
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.
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
getRequest()
Get the WebRequest being used for this instance.
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.
getName()
Get the canonical, unlocalized name of this special page without namespace.
isGood()
Returns whether the operation completed and didn't have any error or warnings.