From: Aaron Schulz Date: Wed, 26 Nov 2008 03:37:11 +0000 (+0000) Subject: Cleanup for r43841: X-Git-Tag: 1.31.0-rc.0~44196 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=c851c28f760cdad96ecdff8aeefe17ac08c064c5;p=lhc%2Fweb%2Fwiklou.git Cleanup for r43841: * Fix odd invocation to use the normal extend method for pages * Add passwordaudit hooks * Fix specialpage member variable collision --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index d34c0049d6..345e5feaa6 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -469,7 +469,7 @@ $wgAutoloadLocalClasses = array( 'SpecialContributions' => 'includes/specials/SpecialContributions.php', 'NewPagesPager' => 'includes/specials/SpecialNewpages.php', 'PageArchive' => 'includes/specials/SpecialUndelete.php', - 'PasswordResetForm' => 'includes/specials/SpecialResetpass.php', + 'PasswordReset' => 'includes/specials/SpecialResetpass.php', 'PopularPagesPage' => 'includes/specials/SpecialPopularpages.php', 'PreferencesForm' => 'includes/specials/SpecialPreferences.php', 'RandomPage' => 'includes/specials/SpecialRandompage.php', diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index b282ebb315..bcfc944a6b 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -89,7 +89,7 @@ class SpecialPage 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ), 'Preferences' => array( 'SpecialPage', 'Preferences' ), 'Watchlist' => array( 'SpecialPage', 'Watchlist' ), - 'Resetpass' => array( 'SpecialPage', 'Resetpass' ), + 'Resetpass' => 'PasswordReset', 'Recentchanges' => 'SpecialRecentchanges', diff --git a/includes/specials/SpecialResetpass.php b/includes/specials/SpecialResetpass.php index 67b639d284..05889c80ab 100644 --- a/includes/specials/SpecialResetpass.php +++ b/includes/specials/SpecialResetpass.php @@ -4,26 +4,13 @@ * @ingroup SpecialPage */ -/** Constructor */ -function wfSpecialResetpass( $par ) { - $form = new PasswordResetForm(); - $form->execute( $par ); -} - /** * Let users recover their password. * @ingroup SpecialPage */ -class PasswordResetForm extends SpecialPage { - function __construct( $name=null, $reset=null ) { - if( $name !== null ) { - $this->mName = $name; - $this->mOldpass = $reset; - } else { - global $wgRequest; - $this->mName = $wgRequest->getVal( 'wpName' ); - $this->mOldpass = $wgRequest->getVal( 'wpPassword' ); - } +class PasswordReset extends SpecialPage { + public function __construct() { + parent::__construct( 'Resetpass' ); } /** @@ -32,6 +19,14 @@ class PasswordResetForm extends SpecialPage { function execute( $par ) { global $wgUser, $wgAuth, $wgOut, $wgRequest; + $this->mUserName = $wgRequest->getVal( 'wpName' ); + $this->mOldpass = $wgRequest->getVal( 'wpPassword' ); + $this->mNewpass = $wgRequest->getVal( 'wpNewPassword' ); + $this->mRetype = $wgRequest->getVal( 'wpRetype' ); + + $this->setHeaders(); + $this->outputHeader(); + if( !$wgAuth->allowPasswordChange() ) { $this->error( wfMsg( 'resetpass_forbidden' ) ); return; @@ -42,18 +37,16 @@ class PasswordResetForm extends SpecialPage { return; } - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) { - $newpass = $wgRequest->getVal( 'wpNewPassword' ); - $retype = $wgRequest->getVal( 'wpRetype' ); + if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal('token') ) ) { try { - $this->attemptReset( $newpass, $retype ); + $this->attemptReset( $this->mNewpass, $this->mRetype ); $wgOut->addWikiMsg( 'resetpass_success' ); if( !$wgUser->isLoggedIn() ) { $data = array( - 'action' => 'submitlogin', - 'wpName' => $this->mName, - 'wpPassword' => $newpass, - 'returnto' => $wgRequest->getVal( 'returnto' ), + 'action' => 'submitlogin', + 'wpName' => $this->mUserName, + 'wpPassword' => $this->mNewpass, + 'returnto' => $wgRequest->getVal( 'returnto' ), ); if( $wgRequest->getCheck( 'wpRemember' ) ) { $data['wpRemember'] = 1; @@ -84,8 +77,8 @@ class PasswordResetForm extends SpecialPage { $wgOut->disallowUserJs(); $self = SpecialPage::getTitleFor( 'Resetpass' ); - if ( !$this->mName ) { - $this->mName = $wgUser->getName(); + if ( !$this->mUserName ) { + $this->mUserName = $wgUser->getName(); } $rememberMe = ''; if ( !$wgUser->isLoggedIn() ) { @@ -112,12 +105,12 @@ class PasswordResetForm extends SpecialPage { 'action' => $self->getLocalUrl(), 'id' => 'mw-resetpass-form' ) ) . Xml::hidden( 'token', $wgUser->editToken() ) . - Xml::hidden( 'wpName', $this->mName ) . + Xml::hidden( 'wpName', $this->mUserName ) . Xml::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) . wfMsgExt( 'resetpass_text', array( 'parse' ) ) . '' . $this->pretty( array( - array( 'wpName', 'username', 'text', $this->mName ), + array( 'wpName', 'username', 'text', $this->mUserName ), array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass ), array( 'wpNewPassword', 'newpassword', 'password', '' ), array( 'wpRetype', 'yourpasswordagain', 'password', '' ), @@ -131,7 +124,8 @@ class PasswordResetForm extends SpecialPage { '' . '
' . Xml::closeElement( 'form' ) . - Xml::closeElement( 'fieldset' ) ); + Xml::closeElement( 'fieldset' ) + ); } function pretty( $fields ) { @@ -162,21 +156,32 @@ class PasswordResetForm extends SpecialPage { /** * @throws PasswordError when cannot set the new password because requirements not met. */ - function attemptReset( $newpass, $retype ) { - $user = User::newFromName( $this->mName ); - if( $user->isAnon() ) { + protected function attemptReset( $newpass, $retype ) { + $user = User::newFromName( $this->mUserName ); + if( !$user || $user->isAnon() ) { throw new PasswordError( 'no such user' ); } - - if( !$user->checkTemporaryPassword( $this->mOldpass ) && !$user->checkPassword( $this->mOldpass ) ) { - throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) ); - } - + if( $newpass !== $retype ) { + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'badretype' ) ); throw new PasswordError( wfMsg( 'badretype' ) ); } - $user->setPassword( $newpass ); + if( !$user->checkPassword( $this->mOldpass ) ) { + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) ); + throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) ); + } + + try { + $user->setPassword( $this->mNewpass ); + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'success' ) ); + $this->mNewpass = $this->mOldpass = $this->mRetypePass = ''; + } catch( PasswordError $e ) { + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'error' ) ); + $this->mainPrefsForm( 'error', $e->getMessage() ); + return; + } + $user->setCookies(); $user->saveSettings(); }