Now it is straightforward to fix bug 89, subst: template parameters.
[lhc/web/wiklou.git] / includes / SpecialUserlogin.php
index 700cf6c..bd78387 100644 (file)
@@ -1,9 +1,19 @@
 <?php
-
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ *
+ */
 require_once('UserMailer.php');
 
-function wfSpecialUserlogin()
-{
+/**
+ * consutrctor
+ */
+function wfSpecialUserlogin() {
        global $wgCommandLineMode;
        global $wgRequest;
        if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] )  ) {
@@ -14,6 +24,11 @@ function wfSpecialUserlogin()
        $form->execute();
 }
 
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
 class LoginForm {
        var $mName, $mPassword, $mRetype, $mReturnto, $mCookieCheck, $mPosted;
        var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
@@ -50,6 +65,7 @@ class LoginForm {
        function execute() {
                if ( !is_null( $this->mCookieCheck ) ) {
                        $this->onCookieRedirectCheck( $this->mCookieCheck );
+                       return;
                } else if( $this->mPosted ) {
                        if( $this->mCreateaccount ) {
                                return $this->addNewAccount();
@@ -64,8 +80,10 @@ class LoginForm {
                $this->mainLoginForm( "" );
        }
 
-       /* private */ function addNewAccountMailPassword()
-       {
+       /**
+        * @access private
+        */
+       function addNewAccountMailPassword() {
                global $wgOut;
                
                if ("" == $this->mEmail) {
@@ -97,8 +115,10 @@ class LoginForm {
        }
 
 
-       /* private */ function addNewAccount()
-       {
+       /**
+        * @access private
+        */
+       function addNewAccount() {
                global $wgUser, $wgOut;
                global $wgDeferredUpdateList;
 
@@ -122,24 +142,14 @@ class LoginForm {
        }
 
 
-       /* private */ function addNewAccountInternal()
-       {
+       /**
+        * @access private
+        */
+       function addNewAccountInternal() {
                global $wgUser, $wgOut;
                global $wgMaxNameChars;
                global $wgMemc, $wgAccountCreationThrottle, $wgDBname, $wgIP;
 
-               if ( $wgAccountCreationThrottle ) {
-                       $key = "$wgDBname:acctcreate:ip:$wgIP";
-                       $value = $wgMemc->incr( $key );
-                       if ( !$value ) {
-                               $wgMemc->set( $key, 1, 86400 );
-                       }
-                       if ( $value > $wgAccountCreationThrottle ) {
-                               $this->throttleHit( $wgAccountCreationThrottle );
-                               return;
-                       }
-               }
-
                if (!$wgUser->isAllowedToCreateAccount()) {
                        $this->userNotPrivilegedMessage();
                        return;
@@ -151,10 +161,13 @@ class LoginForm {
                }
                
                $name = trim( $this->mName );
-               if ( ( "" == $name ) ||
+               $u = User::newFromName( $name );
+               if ( is_null( $u ) ||
+                 ( "" == $name ) ||
                  preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $name ) ||
                  (strpos( $name, "/" ) !== false) ||
-                 (strlen( $name ) > $wgMaxNameChars) ) 
+                 (strlen( $name ) > $wgMaxNameChars) ||
+                 ucFirst($name) != $u->getName() ) 
                {
                        $this->mainLoginForm( wfMsg( "noname" ) );
                        return;
@@ -163,12 +176,24 @@ class LoginForm {
                        $wgOut->readOnlyPage();
                        return;
                }
-               $u = User::newFromName( $name );
                
                if ( 0 != $u->idForName() ) {
                        $this->mainLoginForm( wfMsg( "userexists" ) );
                        return;
                }
+
+               if ( $wgAccountCreationThrottle ) {
+                       $key = "$wgDBname:acctcreate:ip:$wgIP";
+                       $value = $wgMemc->incr( $key );
+                       if ( !$value ) {
+                               $wgMemc->set( $key, 1, 86400 );
+                       }
+                       if ( $value > $wgAccountCreationThrottle ) {
+                               $this->throttleHit( $wgAccountCreationThrottle );
+                               return;
+                       }
+               }
+
                $u->addToDatabase();
                $u->setPassword( $this->mPassword );
                $u->setEmail( $this->mEmail );
@@ -181,10 +206,10 @@ class LoginForm {
                return $u;
        }
 
-
-
-       /* private */ function processLogin()
-       {
+       /**
+        * @access private
+        */
+       function processLogin() {
                global $wgUser;
                global $wgDeferredUpdateList;
 
@@ -193,6 +218,10 @@ class LoginForm {
                        return;
                }
                $u = User::newFromName( $this->mName );
+               if( is_null( $u ) ) {
+                       $this->mainLoginForm( wfMsg( "noname" ) );
+                       return;
+               }
                $id = $u->idForName();
                if ( 0 == $id ) {
                        $this->mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
@@ -200,12 +229,9 @@ class LoginForm {
                }
                $u->setId( $id );
                $u->loadFromDatabase();
-               $ep = $u->encryptPassword( $this->mPassword );
-               if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
-                       if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
-                               $this->mainLoginForm( wfMsg( "wrongpassword" ) );
-                               return;
-                       }
+               if (!$u->checkPassword( $this->mPassword )) {
+                       $this->mainLoginForm( wfMsg( "wrongpassword" ) );
+                       return;
                }
 
                # We've verified now, update the real record
@@ -231,8 +257,10 @@ class LoginForm {
                }
        }
 
-       /* private */ function mailPassword()
-       {
+       /**
+        * @access private
+        */
+       function mailPassword() {
                global $wgUser, $wgDeferredUpdateList, $wgOutputEncoding;
                global $wgCookiePath, $wgCookieDomain, $wgDBname;
 
@@ -241,6 +269,10 @@ class LoginForm {
                        return;
                }
                $u = User::newFromName( $this->mName );
+               if( is_null( $u ) ) {
+                       $this->mainLoginForm( wfMsg( "noname" ) );
+                       return;
+               }
                $id = $u->idForName();
                if ( 0 == $id ) {
                        $this->mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
@@ -259,15 +291,16 @@ class LoginForm {
        }
 
 
-       /* private */ function mailPasswordInternal( $u )
-       {
+       /**
+        * @access private
+        */
+       function mailPasswordInternal( $u ) {
                global $wgDeferredUpdateList, $wgOutputEncoding;
                global $wgPasswordSender, $wgDBname, $wgIP;
                global $wgCookiePath, $wgCookieDomain;
 
                if ( "" == $u->getEmail() ) {
-                       $this->mainLoginForm( wfMsg( "noemail", $u->getName() ) );
-                       return;
+                       return wfMsg( "noemail", $u->getName() );
                }
                $np = User::randomPassword();
                $u->setNewpassword( $np );
@@ -286,11 +319,10 @@ class LoginForm {
        }
 
 
-
-
-
-       /* private */ function successfulLogin( $msg )
-       {
+       /**
+        * @access private
+        */
+       function successfulLogin( $msg ) {
                global $wgUser;
                global $wgDeferredUpdateList;
                global $wgOut;
@@ -298,12 +330,11 @@ class LoginForm {
                $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
                $wgOut->setRobotpolicy( "noindex,nofollow" );
                $wgOut->setArticleRelated( false );
-               $wgOut->addHTML( $msg );
+               $wgOut->addWikiText( $msg );
                $wgOut->returnToMain();
        }
 
-       function userNotPrivilegedMessage()
-       {
+       function userNotPrivilegedMessage() {
                global $wgOut, $wgUser, $wgLang;
                
                $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) );
@@ -315,8 +346,10 @@ class LoginForm {
                $wgOut->returnToMain( false );
        }
 
-       /* private */ function mainLoginForm( $err )
-       {
+       /**
+        * @access private
+        */
+       function mainLoginForm( $err ) {
                global $wgUser, $wgOut, $wgLang;
                global $wgDBname, $wgAllowRealName;
 
@@ -330,7 +363,7 @@ class LoginForm {
                $ca = wfMsg( "createaccount" );
                $cam = wfMsg( "createaccountmail" );
                $ye = wfMsg( "youremail" );
-               if ($wgAllowRealName) {
+               if( $wgAllowRealName ) {
                    $yrn = wfMsg( "yourrealname" );
                } else {
                    $yrn = '';
@@ -376,11 +409,11 @@ class LoginForm {
                $titleObj = Title::makeTitle( NS_SPECIAL, "Userlogin" );
                $action = $titleObj->escapeLocalUrl( $q );
 
-               $encName = wfEscapeHTML( $this->mName );
-               $encPassword = wfEscapeHTML( $this->mPassword );
-               $encRetype = wfEscapeHTML( $this->mRetype );
-               $encEmail = wfEscapeHTML( $this->mEmail );
-               $encRealName = wfEscapeHTML( $this->mRealName );
+               $encName = htmlspecialchars( $this->mName );
+               $encPassword = htmlspecialchars( $this->mPassword );
+               $encRetype = htmlspecialchars( $this->mRetype );
+               $encEmail = htmlspecialchars( $this->mEmail );
+               $encRealName = htmlspecialchars( $this->mRealName );
 
                if ($wgUser->getID() != 0) {
                        $cambutton = "<input tabindex='6' type='submit' name=\"wpCreateaccountMail\" value=\"{$cam}\" />";
@@ -449,14 +482,18 @@ class LoginForm {
                $wgOut->addHTML( $endText );
        }
 
-       /* private */ function hasSessionCookie()
-       {
+       /**
+        * @access private
+        */
+       function hasSessionCookie() {
                global $wgDisableCookieCheck;
                return ( $wgDisableCookieCheck ) ? true : ( "" != $_COOKIE[session_name()] );
        }
          
-       /* private */ function cookieRedirectCheck( $type )
-       {
+       /**
+        * @access private
+        */
+       function cookieRedirectCheck( $type ) {
                global $wgOut, $wgLang;
 
                $titleObj = Title::makeTitle( NS_SPECIAL, "Userlogin" );
@@ -465,7 +502,10 @@ class LoginForm {
                return $wgOut->redirect( $check );
        }
 
-       /* private */ function onCookieRedirectCheck( $type ) {
+       /**
+        * @access private
+        */
+       function onCookieRedirectCheck( $type ) {
                global $wgUser;
 
                if ( !$this->hasSessionCookie() ) {
@@ -482,7 +522,10 @@ class LoginForm {
                }
        }
 
-       /* private */ function throttleHit( $limit ) {
+       /**
+        * @access private
+        */
+       function throttleHit( $limit ) {
                global $wgOut;
 
                $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );