r43971 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43970‎ | r43971 | r43972 >
Date:03:37, 26 November 2008
Author:aaron
Status:ok
Tags:
Comment:
Cleanup for r43841:
* Fix odd invocation to use the normal extend method for pages
* Add passwordaudit hooks
* Fix specialpage member variable collision
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialResetpass.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -469,7 +469,7 @@
470470 'SpecialContributions' => 'includes/specials/SpecialContributions.php',
471471 'NewPagesPager' => 'includes/specials/SpecialNewpages.php',
472472 'PageArchive' => 'includes/specials/SpecialUndelete.php',
473 - 'PasswordResetForm' => 'includes/specials/SpecialResetpass.php',
 473+ 'PasswordReset' => 'includes/specials/SpecialResetpass.php',
474474 'PopularPagesPage' => 'includes/specials/SpecialPopularpages.php',
475475 'PreferencesForm' => 'includes/specials/SpecialPreferences.php',
476476 'RandomPage' => 'includes/specials/SpecialRandompage.php',
Index: trunk/phase3/includes/specials/SpecialResetpass.php
@@ -4,26 +4,13 @@
55 * @ingroup SpecialPage
66 */
77
8 -/** Constructor */
9 -function wfSpecialResetpass( $par ) {
10 - $form = new PasswordResetForm();
11 - $form->execute( $par );
12 -}
13 -
148 /**
159 * Let users recover their password.
1610 * @ingroup SpecialPage
1711 */
18 -class PasswordResetForm extends SpecialPage {
19 - function __construct( $name=null, $reset=null ) {
20 - if( $name !== null ) {
21 - $this->mName = $name;
22 - $this->mOldpass = $reset;
23 - } else {
24 - global $wgRequest;
25 - $this->mName = $wgRequest->getVal( 'wpName' );
26 - $this->mOldpass = $wgRequest->getVal( 'wpPassword' );
27 - }
 12+class PasswordReset extends SpecialPage {
 13+ public function __construct() {
 14+ parent::__construct( 'Resetpass' );
2815 }
2916
3017 /**
@@ -32,6 +19,14 @@
3320 function execute( $par ) {
3421 global $wgUser, $wgAuth, $wgOut, $wgRequest;
3522
 23+ $this->mUserName = $wgRequest->getVal( 'wpName' );
 24+ $this->mOldpass = $wgRequest->getVal( 'wpPassword' );
 25+ $this->mNewpass = $wgRequest->getVal( 'wpNewPassword' );
 26+ $this->mRetype = $wgRequest->getVal( 'wpRetype' );
 27+
 28+ $this->setHeaders();
 29+ $this->outputHeader();
 30+
3631 if( !$wgAuth->allowPasswordChange() ) {
3732 $this->error( wfMsg( 'resetpass_forbidden' ) );
3833 return;
@@ -42,18 +37,16 @@
4338 return;
4439 }
4540
46 - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
47 - $newpass = $wgRequest->getVal( 'wpNewPassword' );
48 - $retype = $wgRequest->getVal( 'wpRetype' );
 41+ if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal('token') ) ) {
4942 try {
50 - $this->attemptReset( $newpass, $retype );
 43+ $this->attemptReset( $this->mNewpass, $this->mRetype );
5144 $wgOut->addWikiMsg( 'resetpass_success' );
5245 if( !$wgUser->isLoggedIn() ) {
5346 $data = array(
54 - 'action' => 'submitlogin',
55 - 'wpName' => $this->mName,
56 - 'wpPassword' => $newpass,
57 - 'returnto' => $wgRequest->getVal( 'returnto' ),
 47+ 'action' => 'submitlogin',
 48+ 'wpName' => $this->mUserName,
 49+ 'wpPassword' => $this->mNewpass,
 50+ 'returnto' => $wgRequest->getVal( 'returnto' ),
5851 );
5952 if( $wgRequest->getCheck( 'wpRemember' ) ) {
6053 $data['wpRemember'] = 1;
@@ -84,8 +77,8 @@
8578 $wgOut->disallowUserJs();
8679
8780 $self = SpecialPage::getTitleFor( 'Resetpass' );
88 - if ( !$this->mName ) {
89 - $this->mName = $wgUser->getName();
 81+ if ( !$this->mUserName ) {
 82+ $this->mUserName = $wgUser->getName();
9083 }
9184 $rememberMe = '';
9285 if ( !$wgUser->isLoggedIn() ) {
@@ -112,12 +105,12 @@
113106 'action' => $self->getLocalUrl(),
114107 'id' => 'mw-resetpass-form' ) ) .
115108 Xml::hidden( 'token', $wgUser->editToken() ) .
116 - Xml::hidden( 'wpName', $this->mName ) .
 109+ Xml::hidden( 'wpName', $this->mUserName ) .
117110 Xml::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) .
118111 wfMsgExt( 'resetpass_text', array( 'parse' ) ) .
119112 '<table>' .
120113 $this->pretty( array(
121 - array( 'wpName', 'username', 'text', $this->mName ),
 114+ array( 'wpName', 'username', 'text', $this->mUserName ),
122115 array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass ),
123116 array( 'wpNewPassword', 'newpassword', 'password', '' ),
124117 array( 'wpRetype', 'yourpasswordagain', 'password', '' ),
@@ -131,7 +124,8 @@
132125 '</tr>' .
133126 '</table>' .
134127 Xml::closeElement( 'form' ) .
135 - Xml::closeElement( 'fieldset' ) );
 128+ Xml::closeElement( 'fieldset' )
 129+ );
136130 }
137131
138132 function pretty( $fields ) {
@@ -162,21 +156,32 @@
163157 /**
164158 * @throws PasswordError when cannot set the new password because requirements not met.
165159 */
166 - function attemptReset( $newpass, $retype ) {
167 - $user = User::newFromName( $this->mName );
168 - if( $user->isAnon() ) {
 160+ protected function attemptReset( $newpass, $retype ) {
 161+ $user = User::newFromName( $this->mUserName );
 162+ if( !$user || $user->isAnon() ) {
169163 throw new PasswordError( 'no such user' );
170164 }
 165+
 166+ if( $newpass !== $retype ) {
 167+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'badretype' ) );
 168+ throw new PasswordError( wfMsg( 'badretype' ) );
 169+ }
171170
172 - if( !$user->checkTemporaryPassword( $this->mOldpass ) && !$user->checkPassword( $this->mOldpass ) ) {
 171+ if( !$user->checkPassword( $this->mOldpass ) ) {
 172+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) );
173173 throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) );
174174 }
175 -
176 - if( $newpass !== $retype ) {
177 - throw new PasswordError( wfMsg( 'badretype' ) );
 175+
 176+ try {
 177+ $user->setPassword( $this->mNewpass );
 178+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'success' ) );
 179+ $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
 180+ } catch( PasswordError $e ) {
 181+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'error' ) );
 182+ $this->mainPrefsForm( 'error', $e->getMessage() );
 183+ return;
178184 }
179 -
180 - $user->setPassword( $newpass );
 185+
181186 $user->setCookies();
182187 $user->saveSettings();
183188 }
Index: trunk/phase3/includes/SpecialPage.php
@@ -89,7 +89,7 @@
9090 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
9191 'Preferences' => array( 'SpecialPage', 'Preferences' ),
9292 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
93 - 'Resetpass' => array( 'SpecialPage', 'Resetpass' ),
 93+ 'Resetpass' => 'PasswordReset',
9494
9595
9696 'Recentchanges' => 'SpecialRecentchanges',

Follow-up revisions

RevisionCommit summaryAuthorDate
r44047Renamed PasswordReset class to SpecialResetpass and fixed an entry in Special...ialex19:42, 29 November 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r43841Move password resetting out of Special:Preferences, adapt Special:ResetPass t...mrzman05:03, 22 November 2008

Status & tagging log