Index: SpecialUserlogin.php =================================================================== --- SpecialUserlogin.php (revision 67921) +++ SpecialUserlogin.php (working copy) @@ -234,6 +234,13 @@ return false; } + // Patch for MediaWikiAuth extension + if ( $this->checkImportableUser( $this->mName ) ) { + $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 @@ -594,8 +601,15 @@ 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; } } @@ -647,7 +661,7 @@ $this->mainLoginForm( wfMsg( 'noname' ) ); break; case self::WRONG_PLUGIN_PASS: - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); + # Message is handled in the authentication code break; case self::NOT_EXISTS: if( $wgUser->isAllowed( 'createaccount' ) ){ @@ -688,6 +702,51 @@ } /** + * New function for MediaWikiAuth extension + * + * @param $username Mixed: username to check + * @return Boolean + */ + private function checkImportableUser( $username ) { + # Check against a table of existing names to import + $dbr = wfGetDB( DB_SLAVE ); + + # If this table exists, there's users to import + if ( $dbr->tableExists( 'user' ) ) { + $res = $dbr->select( + 'user', + array( 'user_id' ), + array( 'user_name' => $username ), + __METHOD__ + ); + $row = $dbr->fetchObject( $res ); + if ( $row ) { + $dbr->freeResult( $res ); + return true; + } + $dbr->freeResult( $res ); + + # Because some people have ' in their usernames + $username = $dbr->strencode( $username ); + + # 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)', + 'rev_user_text = \'' . $username . '\'', + __METHOD__ + ); + if ( $revisions ) { + return true; + } + } + return false; + } + + /** * @private */ function mailPassword() { @@ -746,7 +805,14 @@ return; } if ( 0 == $u->getID() ) { - $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $u->getName() ) ) ); + // Patch for MediaWikiAuth extension + # Try and get this to work for users that might be imported + if ( $this->checkImportableUser( $u->getName() ) ) { + $this->mainLoginForm( wfMsg( 'mwa-must-be-imported' ) ); + } else { + $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $u->getName() ) ) ); + } + // Patch ends here return; }