diff options
Diffstat (limited to 'includes/specials/SpecialChangeEmail.php')
-rw-r--r-- | includes/specials/SpecialChangeEmail.php | 84 |
1 files changed, 62 insertions, 22 deletions
diff --git a/includes/specials/SpecialChangeEmail.php b/includes/specials/SpecialChangeEmail.php index 0f85f516..fc726106 100644 --- a/includes/specials/SpecialChangeEmail.php +++ b/includes/specials/SpecialChangeEmail.php @@ -27,10 +27,26 @@ * @ingroup SpecialPage */ class SpecialChangeEmail extends UnlistedSpecialPage { + + /** + * Users password + * @var string + */ + protected $mPassword; + + /** + * Users new email address + * @var string + */ + protected $mNewEmail; + public function __construct() { parent::__construct( 'ChangeEmail' ); } + /** + * @return Bool + */ function isListed() { global $wgAuth; return $wgAuth->allowPropChange( 'emailaddress' ); @@ -42,11 +58,13 @@ class SpecialChangeEmail extends UnlistedSpecialPage { function execute( $par ) { global $wgAuth; - $this->checkReadOnly(); - $this->setHeaders(); $this->outputHeader(); + $out = $this->getOutput(); + $out->disallowUserJs(); + $out->addModules( 'mediawiki.special.changeemail' ); + if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) { $this->error( 'cannotchangeemail' ); return; @@ -65,9 +83,7 @@ class SpecialChangeEmail extends UnlistedSpecialPage { return; } - $out = $this->getOutput(); - $out->disallowUserJs(); - $out->addModules( 'mediawiki.special.changeemail' ); + $this->checkReadOnly(); $this->mPassword = $request->getVal( 'wpPassword' ); $this->mNewEmail = $request->getVal( 'wpNewEmail' ); @@ -90,6 +106,9 @@ class SpecialChangeEmail extends UnlistedSpecialPage { $this->showForm(); } + /** + * @param $type string + */ protected function doReturnTo( $type = 'hard' ) { $titleObj = Title::newFromText( $this->getRequest()->getVal( 'returnto' ) ); if ( !$titleObj instanceof Title ) { @@ -102,11 +121,15 @@ class SpecialChangeEmail extends UnlistedSpecialPage { } } + /** + * @param $msg string + */ protected function error( $msg ) { $this->getOutput()->wrapWikiMsg( "<p class='error'>\n$1\n</p>", $msg ); } protected function showForm() { + global $wgRequirePasswordforEmailChange; $user = $this->getUser(); $oldEmailText = $user->getEmail() @@ -123,13 +146,20 @@ class SpecialChangeEmail extends UnlistedSpecialPage { Html::hidden( 'token', $user->getEditToken() ) . "\n" . Html::hidden( 'returnto', $this->getRequest()->getVal( 'returnto' ) ) . "\n" . $this->msg( 'changeemail-text' )->parseAsBlock() . "\n" . - Xml::openElement( 'table', array( 'id' => 'mw-changeemail-table' ) ) . "\n" . - $this->pretty( array( - array( 'wpName', 'username', 'text', $user->getName() ), - array( 'wpOldEmail', 'changeemail-oldemail', 'text', $oldEmailText ), - array( 'wpNewEmail', 'changeemail-newemail', 'input', $this->mNewEmail ), - array( 'wpPassword', 'yourpassword', 'password', $this->mPassword ), - ) ) . "\n" . + Xml::openElement( 'table', array( 'id' => 'mw-changeemail-table' ) ) . "\n" + ); + $items = array( + array( 'wpName', 'username', 'text', $user->getName() ), + array( 'wpOldEmail', 'changeemail-oldemail', 'text', $oldEmailText ), + array( 'wpNewEmail', 'changeemail-newemail', 'input', $this->mNewEmail ), + ); + if ( $wgRequirePasswordforEmailChange ) { + $items[] = array( 'wpPassword', 'yourpassword', 'password', $this->mPassword ); + } + + $this->getOutput()->addHTML( + $this->pretty( $items ) . + "\n" . "<tr>\n" . "<td></td>\n" . '<td class="mw-input">' . @@ -143,6 +173,10 @@ class SpecialChangeEmail extends UnlistedSpecialPage { ); } + /** + * @param $fields array + * @return string + */ protected function pretty( $fields ) { $out = ''; foreach ( $fields as $list ) { @@ -173,6 +207,9 @@ class SpecialChangeEmail extends UnlistedSpecialPage { } /** + * @param $user User + * @param $pass string + * @param $newaddr string * @return bool|string true or string on success, false on failure */ protected function attemptChange( User $user, $pass, $newaddr ) { @@ -187,7 +224,8 @@ class SpecialChangeEmail extends UnlistedSpecialPage { return false; } - if ( !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) { + global $wgRequirePasswordforEmailChange; + if ( $wgRequirePasswordforEmailChange && !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) { $this->error( 'wrongpassword' ); return false; } @@ -196,18 +234,20 @@ class SpecialChangeEmail extends UnlistedSpecialPage { LoginForm::clearLoginThrottle( $user->getName() ); } - list( $status, $info ) = Preferences::trySetUserEmail( $user, $newaddr ); - if ( $status !== true ) { - if ( $status instanceof Status ) { - $this->getOutput()->addHTML( - '<p class="error">' . - $this->getOutput()->parseInline( $status->getWikiText( $info ) ) . - '</p>' ); - } + $oldaddr = $user->getEmail(); + $status = $user->setEmailWithConfirmation( $newaddr ); + if ( !$status->isGood() ) { + $this->getOutput()->addHTML( + '<p class="error">' . + $this->getOutput()->parseInline( $status->getWikiText( 'mailerror' ) ) . + '</p>' ); return false; } + wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) ); + $user->saveSettings(); - return $info ? $info : true; + + return $status->value; } } |