r22002 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22001‎ | r22002 | r22003 >
Date:18:31, 8 May 2007
Author:brion
Status:old
Tags:
Comment:
Tweak audit hooks
Modified paths:
  • /trunk/extensions/ConfirmEdit/ConfirmEdit.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/SpecialPreferences.php (modified) (history)
  • /trunk/phase3/includes/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -409,10 +409,11 @@
410410 &$text: string containing partially parsed text
411411 &$this->mStripState: Parser's internal StripState object
412412
413 -'LoginBadPass': a login attempt has failed with an invalid password.
414 - No return data is accepted; this hook is for auditing only.
 413+'LoginAuthenticateAudit': a login attempt for a valid user account either succeeded or failed.
 414+ No return data is accepted; this hook is for auditing only.
415415 $user: the User object being authenticated against
416416 $password: the password being submitted and found wanting
 417+$retval: a LoginForm class constant with authenticateUserData() return value (SUCCESS, WRONG_PASS, etc)
417418
418419 'LogPageValidTypes': action being logged. DEPRECATED: Use $wgLogTypes
419420 &$type: array of strings
Index: trunk/phase3/includes/SpecialUserlogin.php
@@ -400,17 +400,18 @@
401401 // reset form; bot interfaces etc will probably just
402402 // fail cleanly here.
403403 //
404 - return self::RESET_PASS;
 404+ $retval = self::RESET_PASS;
405405 } else {
406 - wfRunHooks( 'LoginBadPass', array( $u, $this->mPassword ) );
407 - return '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
 406+ $retval = '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
408407 }
409408 } else {
410409 $wgAuth->updateUser( $u );
411410 $wgUser = $u;
412411
413 - return self::SUCCESS;
 412+ $retval = self::SUCCESS;
414413 }
 414+ wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $retval ) );
 415+ return $retval;
415416 }
416417
417418 function processLogin() {
Index: trunk/phase3/includes/SpecialPreferences.php
@@ -211,19 +211,23 @@
212212
213213 if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) {
214214 if ( $this->mNewpass != $this->mRetypePass ) {
 215+ wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'badretype' ) );
215216 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
216217 return;
217218 }
218219
219220 if (!$wgUser->checkPassword( $this->mOldpass )) {
 221+ wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'wrongpassword' ) );
220222 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
221223 return;
222224 }
223225
224226 try {
225227 $wgUser->setPassword( $this->mNewpass );
 228+ wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'success' ) );
226229 $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
227230 } catch( PasswordError $e ) {
 231+ wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'error' ) );
228232 $this->mainPrefsForm( 'error', $e->getMessage() );
229233 return;
230234 }
@@ -321,6 +325,9 @@
322326 $wgUser->setCookies();
323327 $wgUser->saveSettings();
324328 }
 329+ if( $oldadr != $newadr ) {
 330+ wfRunHooks( "PrefsEmailAudit", array( $wgUser, $oldadr, $newadr ) );
 331+ }
325332 }
326333
327334 if( $needRedirect && $error === false ) {
Index: trunk/extensions/ConfirmEdit/ConfirmEdit.php
@@ -176,7 +176,7 @@
177177 $wgHooks['UserCreateForm'][] = array( &$wgCaptcha, 'injectUserCreate' );
178178 $wgHooks['AbortNewAccount'][] = array( &$wgCaptcha, 'confirmUserCreate' );
179179
180 - $wgHooks['LoginBadPass'][] = array( &$wgCaptcha, 'triggerUserLogin' );
 180+ $wgHooks['LoginAuthenticateAudit'][] = array( &$wgCaptcha, 'triggerUserLogin' );
181181 $wgHooks['UserLoginForm'][] = array( &$wgCaptcha, 'injectUserLogin' );
182182 $wgHooks['AbortLogin'][] = array( &$wgCaptcha, 'confirmUserLogin' );
183183 }
@@ -300,11 +300,12 @@
301301 * captcha display to prevent too many hits from the same place.
302302 * @param User $user
303303 * @param string $password
 304+ * @param int $retval authentication return value
304305 * @return bool true to keep running callbacks
305306 */
306 - function triggerUserLogin( $user, $password ) {
 307+ function triggerUserLogin( $user, $password, $retval ) {
307308 global $wgCaptchaTriggers, $wgCaptchaBadLoginExpiration, $wgMemc;
308 - if( $wgCaptchaTriggers['badlogin'] ) {
 309+ if( $retval == LoginForm::WRONG_PASS && $wgCaptchaTriggers['badlogin'] ) {
309310 $key = $this->badLoginKey();
310311 $count = $wgMemc->get( $key );
311312 if( !$count ) {