diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index c101897..4c972a2 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -281,6 +281,13 @@ class LoginForm extends SpecialPage { return false; } + // Patch for MediaWikiAuth extension + if ( self::checkImportableUser( $this->mUsername ) ) { + $this->mainLoginForm( wfMsg( 'userexists' ) ); + return false; + } + // Patch ends here + // If we are not allowing users to login locally, we should be checking // to see if the user is actually able to authenticate to the authenti- // cation server before they create an account (otherwise, they can @@ -698,8 +705,13 @@ class LoginForm extends SpecialPage { wfDebug( __METHOD__ . ": user does not exist\n" ); return self::NOT_EXISTS; } - if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword ) ) { + // Patch for MediaWikiAuth extension + $errormsg = null; + if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword, $errormsg ) ) { wfDebug( __METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n" ); + # The AuthPlugin may have set a custom error message + $this->mainLoginForm( isset( $errormsg ) ? $errormsg : wfMsg( 'wrongpassword' ) ); + // Patch ends here return self::WRONG_PLUGIN_PASS; } } @@ -763,7 +775,7 @@ class LoginForm extends SpecialPage { $this->mainLoginForm( $this->msg( 'noname' )->text() ); break; case self::WRONG_PLUGIN_PASS: - $this->mainLoginForm( $this->msg( 'wrongpassword' )->text() ); + # Message is handled in the authentication code break; case self::NOT_EXISTS: if( $this->getUser()->isAllowed( 'createaccount' ) ) { @@ -1124,6 +1136,47 @@ class LoginForm extends SpecialPage { } /** + * New function for MediaWikiAuth extension + * + * @param $username Mixed: username to check + * @return Boolean + */ + public static function checkImportableUser( $username ) { + $dbr = wfGetDB( DB_SLAVE ); + + # Check against existing users + if ( $dbr->tableExists( 'user' ) ) { + $res = $dbr->select( + 'user', + array( 'user_id' ), + array( 'user_name' => $username ), + __METHOD__ + ); + $row = $dbr->fetchObject( $res ); + # Check for valid id to see if user already exists; stop if it does + # In theory, anyway. + if ( $row > 0 ) { + return false; + } + + # Let's see if the count of revisions by their name is greater than 1 + # This is not 100% correct as it is possible to have a username + # like greenReaper, enter greenreaper, and match + # However, we're just checking to see if we should even try, here + $revisions = $dbr->selectField( + 'revision', + 'COUNT(1)', + array( 'rev_user_text' => $username ), + __METHOD__ + ); + if ( $revisions ) { + return true; + } + } + return false; + } + + /** * @private * * @param $user User