* (bug 10117) Special:Wantedpages doesn't handle invalid titles in result - now print...
[lhc/web/wiklou.git] / includes / SpecialUserlogin.php
index 879886c..7fa01d2 100644 (file)
@@ -19,10 +19,9 @@ function wfSpecialUserlogin() {
 }
 
 /**
- * @todo document, briefly.
+ * implements Special:Login
  * @addtogroup SpecialPage
  */
-
 class LoginForm {
 
        const SUCCESS = 0;
@@ -33,6 +32,7 @@ class LoginForm {
        const WRONG_PASS = 5;
        const EMPTY_PASS = 6;
        const RESET_PASS = 7;
+       const ABORTED = 8;
 
        var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
        var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
@@ -40,7 +40,7 @@ class LoginForm {
 
        /**
         * Constructor
-        * @param webrequest $request A webrequest object passed by reference
+        * @param WebRequest $request A WebRequest object passed by reference
         */
        function LoginForm( &$request ) {
                global $wgLang, $wgAllowRealName, $wgEnableEmail;
@@ -229,6 +229,7 @@ class LoginForm {
                        return false;
                }
 
+               # Check anonymous user ($wgUser) limitations :
                if (!$wgUser->isAllowedToCreateAccount()) {
                        $this->userNotPrivilegedMessage();
                        return false;
@@ -242,6 +243,7 @@ class LoginForm {
                        return;
                }
 
+               # Now create a dummy user ($u) and check if it is valid
                $name = trim( $this->mName );
                $u = User::newFromName( $name, 'creatable' );
                if ( is_null( $u ) ) {
@@ -259,7 +261,7 @@ class LoginForm {
                        return false;
                }
 
-               if ( !$wgUser->isValidPassword( $this->mPassword ) ) {
+               if ( !$u->isValidPassword( $this->mPassword ) ) {
                        $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
                        return false;
                }
@@ -363,6 +365,12 @@ class LoginForm {
                        $u->load();
                }
 
+               // Give general extensions, such as a captcha, a chance to abort logins
+               $abort = self::ABORTED;
+               if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword, &$abort ) ) ) {
+                       return $abort;
+               }
+               
                if (!$u->checkPassword( $this->mPassword )) {
                        if( $u->checkTemporaryPassword( $this->mPassword ) ) {
                                // The e-mailed temporary password should not be used
@@ -392,16 +400,18 @@ class LoginForm {
                                // reset form; bot interfaces etc will probably just
                                // fail cleanly here.
                                //
-                               return self::RESET_PASS;
+                               $retval = self::RESET_PASS;
                        } else {
-                               return '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
+                               $retval = '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
                        }
                } else {
                        $wgAuth->updateUser( $u );
                        $wgUser = $u;
 
-                       return self::SUCCESS;
+                       $retval = self::SUCCESS;
                }
+               wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $retval ) );
+               return $retval;
        }
 
        function processLogin() {
@@ -695,6 +705,7 @@ class LoginForm {
                $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
+               $wgOut->disallowUserJs();  // just in case...
                $wgOut->addTemplate( $template );
        }