47 parent::__construct(
'ChangeEmail',
'editmyprivateinfo' );
60 return $this->
getAuthManager()->allowsPropertyChange(
'emailaddress' );
69 $out->disallowUserJs();
70 $out->addModules(
'mediawiki.special.changeemail' );
71 parent::execute(
$par );
79 if ( !$this->
getAuthManager()->allowsPropertyChange(
'emailaddress' ) ) {
87 if ( !$this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) ) {
91 parent::checkExecutePermissions( $user );
100 'label-message' =>
'username',
105 'label-message' =>
'changeemail-oldemail',
106 'default' => $user->
getEmail() ?: $this->
msg(
'changeemail-none' )->text(),
110 'label-message' =>
'changeemail-newemail',
113 'help-message' =>
'changeemail-newemail-help',
123 $form->
setId(
'mw-changeemail-form' );
133 $this->status = $this->attemptChange( $this->
getUser(), $data[
'NewEmail'] );
135 return $this->status;
141 $returnTo = $request->getVal(
'returnto' );
142 $titleObj = $returnTo !==
null ? Title::newFromText( $returnTo ) :
null;
143 if ( !$titleObj instanceof
Title ) {
144 $titleObj = Title::newMainPage();
146 $query = $request->getVal(
'returntoquery',
'' );
148 if ( $this->status->value ===
true ) {
149 $this->
getOutput()->redirect( $titleObj->getFullUrlForRedirect( $query ) );
150 } elseif ( $this->status->value ===
'eauth' ) {
151 # Notify user that a confirmation email has been sent...
153 $out->addModuleStyles(
'mediawiki.codex.messagebox.styles' );
156 $out->msg(
'eauthentsent', $this->getUser()->getName() )->parse()
170 private function attemptChange(
User $user, $newAddr ) {
171 if ( $newAddr !==
'' && !Sanitizer::validateEmail( $newAddr ) ) {
172 return Status::newFatal(
'invalidemailaddress' );
176 if ( $newAddr === $oldAddr ) {
177 return Status::newFatal(
'changeemail-nochange' );
180 if ( strlen( $newAddr ) > 255 ) {
181 return Status::newFatal(
'changeemail-maxlength' );
186 if ( $newAddr !==
'' ) {
189 if ( !$status->
isGood() ) {
190 return Status::wrap( $status );
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();
225class_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.