<?php
/**
+ * Implements Special:Resetpass
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
* @ingroup SpecialPage
*/
/**
* Let users recover their password.
+ *
* @ingroup SpecialPage
*/
class SpecialResetpass extends SpecialPage {
function execute( $par ) {
global $wgUser, $wgAuth, $wgOut, $wgRequest;
+ if ( wfReadOnly() ) {
+ $wgOut->readOnlyPage();
+ return;
+ }
+
$this->mUserName = $wgRequest->getVal( 'wpName' );
$this->mOldpass = $wgRequest->getVal( 'wpPassword' );
$this->mNewpass = $wgRequest->getVal( 'wpNewPassword' );
$this->setHeaders();
$this->outputHeader();
+ $wgOut->disallowUserJs();
if( !$wgAuth->allowPasswordChange() ) {
$this->error( wfMsg( 'resetpass_forbidden' ) );
return;
}
+ if( $wgRequest->wasPosted() && $wgRequest->getBool( 'wpCancel' ) ) {
+ $this->doReturnTo();
+ return;
+ }
+
if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal('token') ) ) {
try {
$this->attemptReset( $this->mNewpass, $this->mRetype );
$login = new LoginForm( new FauxRequest( $data, true ) );
$login->execute();
}
- $titleObj = Title::newFromText( $wgRequest->getVal( 'returnto' ) );
- if ( !$titleObj instanceof Title ) {
- $titleObj = Title::newMainPage();
- }
- $wgOut->redirect( $titleObj->getFullURL() );
+ $this->doReturnTo();
} catch( PasswordError $e ) {
$this->error( $e->getMessage() );
}
}
$this->showForm();
}
+
+ function doReturnTo() {
+ global $wgRequest, $wgOut;
+ $titleObj = Title::newFromText( $wgRequest->getVal( 'returnto' ) );
+ if ( !$titleObj instanceof Title ) {
+ $titleObj = Title::newMainPage();
+ }
+ $wgOut->redirect( $titleObj->getFullURL() );
+ }
function error( $msg ) {
global $wgOut;
function showForm() {
global $wgOut, $wgUser, $wgRequest;
- $wgOut->disallowUserJs();
-
- $self = SpecialPage::getTitleFor( 'Resetpass' );
+ $self = $this->getTitle();
if ( !$this->mUserName ) {
$this->mUserName = $wgUser->getName();
}
$rememberMe = '';
if ( !$wgUser->isLoggedIn() ) {
+ global $wgCookieExpiration, $wgLang;
$rememberMe = '<tr>' .
'<td></td>' .
'<td class="mw-input">' .
- Xml::checkLabel( wfMsg( 'remembermypassword' ),
+ Xml::checkLabel(
+ wfMsgExt( 'remembermypassword', 'parsemag', $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) ) ),
'wpRemember', 'wpRemember',
$wgRequest->getCheck( 'wpRemember' ) ) .
'</td>' .
array(
'method' => 'post',
'action' => $self->getLocalUrl(),
- 'id' => 'mw-resetpass-form' ) ) .
- Xml::hidden( 'token', $wgUser->editToken() ) .
- Xml::hidden( 'wpName', $this->mUserName ) .
- Xml::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) .
- wfMsgExt( 'resetpass_text', array( 'parse' ) ) .
- Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) .
+ 'id' => 'mw-resetpass-form' ) ) . "\n" .
+ Html::hidden( 'token', $wgUser->editToken() ) . "\n" .
+ Html::hidden( 'wpName', $this->mUserName ) . "\n" .
+ Html::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) . "\n" .
+ wfMsgExt( 'resetpass_text', array( 'parse' ) ) . "\n" .
+ Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) . "\n" .
$this->pretty( array(
array( 'wpName', 'username', 'text', $this->mUserName ),
array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass ),
- array( 'wpNewPassword', 'newpassword', 'password', '' ),
- array( 'wpRetype', 'retypenew', 'password', '' ),
- ) ) .
+ array( 'wpNewPassword', 'newpassword', 'password', null ),
+ array( 'wpRetype', 'retypenew', 'password', null ),
+ ) ) . "\n" .
$rememberMe .
- '<tr>' .
- '<td></td>' .
+ "<tr>\n" .
+ "<td></td>\n" .
'<td class="mw-input">' .
Xml::submitButton( wfMsg( $submitMsg ) ) .
- '</td>' .
- '</tr>' .
+ Xml::submitButton( wfMsg( 'resetpass-submit-cancel' ), array( 'name' => 'wpCancel' ) ) .
+ "</td>\n" .
+ "</tr>\n" .
Xml::closeElement( 'table' ) .
Xml::closeElement( 'form' ) .
- Xml::closeElement( 'fieldset' )
+ Xml::closeElement( 'fieldset' ) . "\n"
);
}
function pretty( $fields ) {
$out = '';
- foreach( $fields as $list ) {
+ foreach ( $fields as $list ) {
list( $name, $label, $type, $value ) = $list;
if( $type == 'text' ) {
$field = htmlspecialchars( $value );
} else {
- $field = Xml::input( $name, 20, $value,
- array( 'id' => $name, 'type' => $type ) );
+ $attribs = array( 'id' => $name );
+ if ( $name == 'wpNewPassword' || $name == 'wpRetype' ) {
+ $attribs = array_merge( $attribs,
+ User::passwordChangeInputAttribs() );
+ }
+ if ( $name == 'wpPassword' ) {
+ $attribs[] = 'autofocus';
+ }
+ $field = Html::input( $name, $value, $type, $attribs );
}
- $out .= '<tr>';
- $out .= "<td class='mw-label'>";
+ $out .= "<tr>\n";
+ $out .= "\t<td class='mw-label'>";
if ( $type != 'text' )
$out .= Xml::label( wfMsg( $label ), $name );
else
- $out .= wfMsg( $label );
- $out .= '</td>';
- $out .= "<td class='mw-input'>";
+ $out .= wfMsgHtml( $label );
+ $out .= "</td>\n";
+ $out .= "\t<td class='mw-input'>";
$out .= $field;
- $out .= '</td>';
- $out .= '</tr>';
+ $out .= "</td>\n";
+ $out .= "</tr>";
}
return $out;
}
} catch( PasswordError $e ) {
wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'error' ) );
throw new PasswordError( $e->getMessage() );
- return;
}
$user->setCookies();