* @ingroup SpecialPage
*/
class SpecialResetpass extends SpecialPage {
+
+ private $mSelfChange = true; // Usually, but sometimes not :)
+
public function __construct() {
parent::__construct( 'Resetpass' );
}
function execute( $par ) {
global $wgUser, $wgAuth, $wgOut, $wgRequest;
- $this->mUserName = $wgRequest->getVal( 'wpName' );
+ $this->mUserName = $wgRequest->getVal( 'wpName', $par );
$this->mOldpass = $wgRequest->getVal( 'wpPassword' );
$this->mNewpass = $wgRequest->getVal( 'wpNewPassword' );
$this->mRetype = $wgRequest->getVal( 'wpRetype' );
$this->error( wfMsg( 'resetpass_forbidden' ) );
return;
}
+
+ // Default to our own username when not given one
+ if ( !$this->mUserName ) {
+ $this->mUserName = $wgUser->getName();
+ }
+
+ // Are we changing our own?
+ if ( $wgUser->getName() != $this->mUserName ) {
+ $this->mSelfChange = false; // We're changing someone else
+ }
if( !$wgRequest->wasPosted() && !$wgUser->isLoggedIn() ) {
$this->error( wfMsg( 'resetpass-no-info' ) );
return;
}
+ if ( !$this->mSelfChange && !$wgUser->isAllowed( 'reset-passwords' ) ) {
+ $this->error( wfMsg( 'resetpass-no-others' ) );
+ return;
+ }
+
if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal('token') ) ) {
try {
$this->attemptReset( $this->mNewpass, $this->mRetype );
$wgOut->addWikiMsg( 'resetpass_success' );
- if( !$wgUser->isLoggedIn() ) {
+ // Only attempt this login session if we're changing our own password
+ if( $this->mSelfChange && !$wgUser->isLoggedIn() ) {
$data = array(
'action' => 'submitlogin',
'wpName' => $this->mUserName,
$wgOut->disallowUserJs();
$self = SpecialPage::getTitleFor( 'Resetpass' );
- if ( !$this->mUserName ) {
- $this->mUserName = $wgUser->getName();
- }
+
$rememberMe = '';
if ( !$wgUser->isLoggedIn() ) {
$rememberMe = '<tr>' .
'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' ) ) .
$this->pretty( array(
- array( 'wpName', 'username', 'text', $this->mUserName ),
- array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass ),
- array( 'wpNewPassword', 'newpassword', 'password', '' ),
- array( 'wpRetype', 'retypenew', 'password', '' ),
+ array( 'wpName', 'username', 'text', $this->mUserName, !$this->mSelfChange ),
+ array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass, $this->mSelfChange ),
+ array( 'wpNewPassword', 'newpassword', 'password', '', true ),
+ array( 'wpRetype', 'retypenew', 'password', '', true ),
) ) .
$rememberMe .
'<tr>' .
function pretty( $fields ) {
$out = '';
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 ) );
- }
+ list( $name, $label, $type, $value, $enabled ) = $list;
+ $params = array( 'id' => $name, 'type' => $type );
+ if ( !$enabled )
+ $params['disabled'] = 'disabled';
+ $field = Xml::input( $name, 20, $value, $params );
$out .= '<tr>';
- $out .= "<td class='mw-label'>";
- if ( $type != 'text' )
- $out .= Xml::label( wfMsg( $label ), $name );
- else
- $out .= wfMsg( $label );
+ $out .= '<td class="mw-label">';
+ $out .= Xml::label( wfMsg( $label ), $name );
$out .= '</td>';
- $out .= "<td class='mw-input'>";
+ $out .= '<td class="mw-input">';
$out .= $field;
$out .= '</td>';
$out .= '</tr>';
throw new PasswordError( wfMsg( 'badretype' ) );
}
- if( !$user->checkTemporaryPassword($this->mOldpass) && !$user->checkPassword($this->mOldpass) ) {
- wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) );
- throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) );
+ if ( $this->mSelfChange ) {
+ if( !$user->checkTemporaryPassword($this->mOldpass) && !$user->checkPassword($this->mOldpass) ) {
+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) );
+ throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) );
+ }
}
try {