* @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' );
*/
function execute( $par ) {
global $wgAuth;
- $this->checkReadOnly();
-
- $request = $this->getRequest();
- $this->mPassword = $request->getVal( 'wpPassword' );
- $this->mNewEmail = $request->getVal( 'wpNewEmail' );
$this->setHeaders();
$this->outputHeader();
$out = $this->getOutput();
$out->disallowUserJs();
-
- $user = $this->getUser();
+ $out->addModules( 'mediawiki.special.changeemail' );
if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) {
- $this->error( wfMsgExt( 'cannotchangeemail', 'parseinline' ) );
+ $this->error( 'cannotchangeemail' );
return;
}
+ $user = $this->getUser();
+ $request = $this->getRequest();
+
if ( !$request->wasPosted() && !$user->isLoggedIn() ) {
- $this->error( wfMsg( 'changeemail-no-info' ) );
+ $this->error( 'changeemail-no-info' );
return;
}
return;
}
+ $this->checkReadOnly();
+
+ $this->mPassword = $request->getVal( 'wpPassword' );
+ $this->mNewEmail = $request->getVal( 'wpNewEmail' );
+
if ( $request->wasPosted()
&& $user->matchEditToken( $request->getVal( 'token' ) ) )
{
$this->showForm();
}
+ /**
+ * @param $type string
+ */
protected function doReturnTo( $type = 'hard' ) {
$titleObj = Title::newFromText( $this->getRequest()->getVal( 'returnto' ) );
if ( !$titleObj instanceof Title ) {
}
}
+ /**
+ * @param $msg string
+ */
protected function error( $msg ) {
- $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $msg ) );
+ $this->getOutput()->wrapWikiMsg( "<p class='error'>\n$1\n</p>", $msg );
}
protected function showForm() {
+ global $wgRequirePasswordforEmailChange;
$user = $this->getUser();
$oldEmailText = $user->getEmail()
? $user->getEmail()
- : wfMsg( 'changeemail-none' );
+ : $this->msg( 'changeemail-none' )->text();
$this->getOutput()->addHTML(
- Xml::fieldset( wfMsg( 'changeemail-header' ) ) .
+ Xml::fieldset( $this->msg( 'changeemail-header' )->text() ) .
Xml::openElement( 'form',
array(
'method' => 'post',
'id' => 'mw-changeemail-form' ) ) . "\n" .
Html::hidden( 'token', $user->getEditToken() ) . "\n" .
Html::hidden( 'returnto', $this->getRequest()->getVal( 'returnto' ) ) . "\n" .
- wfMsgExt( 'changeemail-text', array( 'parse' ) ) . "\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" .
+ $this->msg( 'changeemail-text' )->parseAsBlock() . "\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', 'email', $this->mNewEmail ),
+ );
+ if ( $wgRequirePasswordforEmailChange ) {
+ $items[] = array( 'wpPassword', 'changeemail-password', 'password', $this->mPassword );
+ }
+
+ $this->getOutput()->addHTML(
+ $this->pretty( $items ) .
+ "\n" .
"<tr>\n" .
"<td></td>\n" .
'<td class="mw-input">' .
- Xml::submitButton( wfMsg( 'changeemail-submit' ) ) .
- Xml::submitButton( wfMsg( 'changeemail-cancel' ), array( 'name' => 'wpCancel' ) ) .
+ Xml::submitButton( $this->msg( 'changeemail-submit' )->text() ) .
+ Xml::submitButton( $this->msg( 'changeemail-cancel' )->text(), array( 'name' => 'wpCancel' ) ) .
"</td>\n" .
"</tr>\n" .
Xml::closeElement( 'table' ) .
);
}
+ /**
+ * @param $fields array
+ * @return string
+ */
protected function pretty( $fields ) {
$out = '';
foreach ( $fields as $list ) {
$out .= "<tr>\n";
$out .= "\t<td class='mw-label'>";
if ( $type != 'text' ) {
- $out .= Xml::label( wfMsg( $label ), $name );
+ $out .= Xml::label( $this->msg( $label )->text(), $name );
} else {
- $out .= wfMsgHtml( $label );
+ $out .= $this->msg( $label )->escaped();
}
$out .= "</td>\n";
$out .= "\t<td class='mw-input'>";
}
/**
+ * @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 ) {
+ global $wgAuth;
+
if ( $newaddr != '' && !Sanitizer::validateEmail( $newaddr ) ) {
- $this->error( wfMsgExt( 'invalidemailaddress', 'parseinline' ) );
+ $this->error( 'invalidemailaddress' );
return false;
}
$throttleCount = LoginForm::incLoginThrottle( $user->getName() );
if ( $throttleCount === true ) {
- $this->error( wfMsgHtml( 'login-throttled' ) );
+ $this->error( 'login-throttled' );
return false;
}
- if ( !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) {
- $this->error( wfMsgHtml( 'wrongpassword' ) );
+ global $wgRequirePasswordforEmailChange;
+ if ( $wgRequirePasswordforEmailChange && !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) {
+ $this->error( 'wrongpassword' );
return false;
}
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;
+
+ $wgAuth->updateExternalDB( $user );
+
+ return $status->value;
}
}