In QueryPage: fixing a misleading comment. value needn't be numeric.
[lhc/web/wiklou.git] / includes / SpecialUserlogin.php
index f84f640..32799e5 100644 (file)
-<?
+<?php
+
+require_once('UserMailer.php');
 
 function wfSpecialUserlogin()
 {
-       global $wpCreateaccount, $wpCreateaccountMail;
-       global $wpLoginattempt, $wpMailmypassword;
-       global $action;
-
-       $fields = array( "wpName", "wpPassword", "wpName",
-         "wpPassword", "wpRetype", "wpEmail" );
-       wfCleanFormFields( $fields );
-
-       if ( isset( $wpCreateaccount ) ) {
-               addNewAccount();
-       } else if ( isset( $wpCreateaccountMail ) ) {
-               addNewAccountMailPassword();
-       } else if ( isset( $wpMailmypassword ) ) {
-               mailPassword();
-       } else if ( "submit" == $action || isset( $wpLoginattempt ) ) {
-               processLogin();
-       } else {
-               mainLoginForm( "" );
+       global $wgCommandLineMode;
+       global $wgRequest;
+       if( !$wgCommandLineMode && !isset( $_COOKIE[ini_get("session.name")] )  ) {
+               User::SetupSession();
        }
+       
+       $form = new LoginForm( $wgRequest );
+       $form->execute();
 }
 
-
-/* private */ function addNewAccountMailPassword()
-{
-       global $wgOut, $wpEmail, $wpName;
+class LoginForm {
+       var $mName, $mPassword, $mRetype, $mReturnto, $mCookieCheck, $mPosted;
+       var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
+       var $mLoginattempt, $mRemember, $mEmail;
        
-       if ("" == $wpEmail) {
-               mainLoginForm( wfMsg( "noemail", $wpName ) );
-               return;
+       function LoginForm( &$request ) {
+               global $wgLang, $wgAllowRealName;
+
+               $this->mName = $request->getText( 'wpName' );
+               $this->mPassword = $request->getText( 'wpPassword' );
+               $this->mRetype = $request->getText( 'wpRetype' );
+               $this->mReturnto = $request->getVal( 'returnto' );
+               $this->mCookieCheck = $request->getVal( "wpCookieCheck" );
+               $this->mPosted = $request->wasPosted();
+               $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
+               $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' );
+               $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' );
+               $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
+               $this->mAction = $request->getVal( 'action' );
+               $this->mRemember = $request->getCheck( 'wpRemember' );
+               $this->mEmail = $request->getText( 'wpEmail' );
+               if ($wgAllowRealName) {
+                   $this->mRealName = $request->getText( 'wpRealName' );
+               } else {
+                   $this->mRealName = '';
+               }
+           
+               # When switching accounts, it sucks to get automatically logged out
+               if( $this->mReturnto == $wgLang->specialPage( "Userlogout" ) ) {
+                       $this->mReturnto = "";
+               }
        }
 
-       $u = addNewaccountInternal();
-
-       if ($u == NULL) {
-               return;
+       function execute() {
+               if ( !is_null( $this->mCookieCheck ) ) {
+                       $this->onCookieRedirectCheck( $this->mCookieCheck );
+               } else if( $this->mPosted ) {
+                       if( $this->mCreateaccount ) {
+                               return $this->addNewAccount();
+                       } else if ( $this->mCreateaccountMail ) {
+                               return $this->addNewAccountMailPassword();
+                       } else if ( $this->mMailmypassword ) {
+                               return $this->mailPassword();
+                       } else if ( ( "submit" == $this->mAction ) || $this->mLoginattempt ) {
+                               return $this->processLogin();
+                       }
+               }
+               $this->mainLoginForm( "" );
        }
 
-       $u->saveSettings();
-       if (mailPasswordInternal($u) == NULL)
+       /* private */ function addNewAccountMailPassword()
        {
-               return;  
-       }
+               global $wgOut;
+               
+               if ("" == $this->mEmail) {
+                       $this->mainLoginForm( wfMsg( "noemail", $this->mName ) );
+                       return;
+               }
 
-       $wgOut->setPageTitle( wfMsg( "accmailtitle" ) );
-       $wgOut->setRobotpolicy( "noindex,nofollow" );
-       $wgOut->setArticleFlag( false );
+               $u = $this->addNewaccountInternal();
 
-       $wgOut->addWikiText( wfMsg( "accmailtext", $u->getName(), $u->getEmail() ) );
-       $wgOut->returnToMain( false );
+               if ($u == NULL) {
+                       return;
+               }
 
-       $u = 0;
-}
+               $u->saveSettings();
+               $error = $this->mailPasswordInternal($u);
 
+               $wgOut->setPageTitle( wfMsg( "accmailtitle" ) );
+               $wgOut->setRobotpolicy( "noindex,nofollow" );
+               $wgOut->setArticleRelated( false );
+       
+               if ( $error === "" ) {
+                       $wgOut->addWikiText( wfMsg( "accmailtext", $u->getName(), $u->getEmail() ) );
+                       $wgOut->returnToMain( false );
+               } else {
+                       $this->mainLoginForm( wfMsg( "mailerror", $error ) );
+               }
 
-/* private */ function addNewAccount()
-{
-       global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
-       global $wpEmail, $wgDeferredUpdateList;
+               $u = 0;
+       }
 
-       $u = addNewAccountInternal();
 
-       if ($u == NULL) {
-               return;
-       }
+       /* private */ function addNewAccount()
+       {
+               global $wgUser, $wgOut;
+               global $wgDeferredUpdateList;
 
-       $wgUser = $u;
-       successfulLogin( wfMsg( "welcomecreation", $wgUser->getName() ) );
-}
+               $u = $this->addNewAccountInternal();
 
+               if ($u == NULL) {
+                       return;
+               }
 
-/* private */ function addNewAccountInternal()
-{
-       global $wgUser, $wgOut, $wpPassword, $wpRetype, $wpName, $wpRemember;
-       global $wpEmail, $wgDeferredUpdateList;
+               $wgUser = $u;
+               $wgUser->setCookies();
 
-        if (!cookieCheck()) {
-                return;
-        }
+               $up = new UserUpdate();
+               array_push( $wgDeferredUpdateList, $up );
 
-       if (!$wgUser->isAllowedToCreateAccount()) {
-               userNotPrivilegedMessage();
-               return;
+               if( $this->hasSessionCookie() ) {
+                       return $this->successfulLogin( wfMsg( "welcomecreation", $wgUser->getName() ) );
+               } else {
+                       return $this->cookieRedirectCheck( "new" );
+               }
        }
 
-       if ( 0 != strcmp( $wpPassword, $wpRetype ) ) {
-               mainLoginForm( wfMsg( "badretype" ) );
-               return;
-       }
-       $wpName = trim( $wpName );
-       if ( ( "" == $wpName ) ||
-         preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $wpName ) ||
-         (strpos( $wpName, "/" ) !== false) ) 
+
+       /* private */ function addNewAccountInternal()
        {
-               mainLoginForm( wfMsg( "noname" ) );
-               return;
-       }
-       if ( wfReadOnly() ) {
-               $wgOut->readOnlyPage();
-               return;
-       }
-       $u = User::newFromName( $wpName );
+               global $wgUser, $wgOut;
+               global $wgMaxNameChars;
+               global $wgMemc, $wgAccountCreationThrottle, $wgDBname, $wgIP;
 
-       if ( 0 != $u->idForName() ) {
-               mainLoginForm( wfMsg( "userexists" ) );
-               return;
-       }
-       $u->addToDatabase();
-       $u->setPassword( $wpPassword );
-       $u->setEmail( $wpEmail );
-       if ( 1 == $wpRemember ) { $r = 1; }
-       else { $r = 0; }
-       $u->setOption( "rememberpassword", $r );
-       
-       return $u;
-}
+               if (!$wgUser->isAllowedToCreateAccount()) {
+                       $this->userNotPrivilegedMessage();
+                       return;
+               }
 
+               if ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) {
+                       $this->mainLoginForm( wfMsg( "badretype" ) );
+                       return;
+               }
+               
+               $name = trim( $this->mName );
+               $u = User::newFromName( $name );
+               if ( ( "" == $name ) ||
+                 preg_match( "/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/", $name ) ||
+                 (strpos( $name, "/" ) !== false) ||
+                 (strlen( $name ) > $wgMaxNameChars) ||
+                 ucFirst($name) != $u->getName() ) 
+               {
+                       $this->mainLoginForm( wfMsg( "noname" ) );
+                       return;
+               }
+               if ( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+               
+               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 );
+               $u->setRealName( $this->mRealName );
 
-/* private */ function processLogin()
-{
-       global $wgUser, $wpName, $wpPassword, $wpRemember;
-       global $returnto;
+               if ( $this->mRemember ) { $r = 1; }
+               else { $r = 0; }
+               $u->setOption( "rememberpassword", $r );
+               
+               return $u;
+       }
 
-        if (!cookieCheck()) {
-                return;
-        }
 
-       if ( "" == $wpName ) {
-               mainLoginForm( wfMsg( "noname" ) );
-               return;
-       }
-       $u = User::newFromName( $wpName );
-       $id = $u->idForName();
-       if ( 0 == $id ) {
-               mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
-               return;
-       }
-       $u->setId( $id );
-       $u->loadFromDatabase();
-       $ep = $u->encryptPassword( $wpPassword );
-       if ( 0 != strcmp( $ep, $u->getPassword() ) ) {
-               if ( 0 != strcmp( $ep, $u->getNewpassword() ) ) {
-                       mainLoginForm( wfMsg( "wrongpassword" ) );
+
+       /* private */ function processLogin()
+       {
+               global $wgUser;
+               global $wgDeferredUpdateList;
+
+               if ( "" == $this->mName ) {
+                       $this->mainLoginForm( wfMsg( "noname" ) );
+                       return;
+               }
+               $u = User::newFromName( $this->mName );
+               $id = $u->idForName();
+               if ( 0 == $id ) {
+                       $this->mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
+                       return;
+               }
+               $u->setId( $id );
+               $u->loadFromDatabase();
+               if (!$u->checkPassword( $this->mPassword )) {
+                       $this->mainLoginForm( wfMsg( "wrongpassword" ) );
                        return;
                }
-       }
-
-       # We've verified now, update the real record
-       #
-       if ( 1 == $wpRemember ) {
-               $r = 1;
-               $u->setCookiePassword( $wpPassword );
-       } else {
-               $r = 0;
-       }
-       $u->setOption( "rememberpassword", $r );
 
-       $wgUser = $u;
-       successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) );
-}
+               # We've verified now, update the real record
+               #
+               if ( $this->mRemember ) {
+                       $r = 1;
+                       $u->setCookiePassword( $this->mPassword );
+               } else {
+                       $r = 0;
+               }
+               $u->setOption( "rememberpassword", $r );
 
-/* private */ function mailPassword()
-{
-       global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
-       global $wgCookiePath, $wgCookieDomain, $wgDBname;
+               $wgUser = $u;
+               $wgUser->setCookies();
 
-       if ( "" == $wpName ) {
-               mainLoginForm( wfMsg( "noname" ) );
-               return;
-       }
-       $u = User::newFromName( $wpName );
-       $id = $u->idForName();
-       if ( 0 == $id ) {
-               mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
-               return;
-       }
-       $u->setId( $id );
-       $u->loadFromDatabase();
+               $up = new UserUpdate();
+               array_push( $wgDeferredUpdateList, $up );
 
-       if (mailPasswordInternal($u) == NULL) {
-               return;
+               if( $this->hasSessionCookie() ) {
+                       return $this->successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) );
+               } else {
+                       return $this->cookieRedirectCheck( "login" );
+               }
        }
 
-       mainLoginForm( wfMsg( "passwordsent", $u->getName() ) );
-}
+       /* private */ function mailPassword()
+       {
+               global $wgUser, $wgDeferredUpdateList, $wgOutputEncoding;
+               global $wgCookiePath, $wgCookieDomain, $wgDBname;
 
+               if ( "" == $this->mName ) {
+                       $this->mainLoginForm( wfMsg( "noname" ) );
+                       return;
+               }
+               $u = User::newFromName( $this->mName );
+               $id = $u->idForName();
+               if ( 0 == $id ) {
+                       $this->mainLoginForm( wfMsg( "nosuchuser", $u->getName() ) );
+                       return;
+               }
+               $u->setId( $id );
+               $u->loadFromDatabase();
 
-/* private */ function mailPasswordInternal( $u )
-{
-       global $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
-       global $wgPasswordSender;
+               $error = $this->mailPasswordInternal( $u );
+               if ($error === "") {
+                       $this->mainLoginForm( wfMsg( "passwordsent", $u->getName() ) );
+               } else {
+                       $this->mainLoginForm( wfMsg( "mailerror", $error ) );
+               }
 
-       if ( "" == $u->getEmail() ) {
-               mainLoginForm( wfMsg( "noemail", $u->getName() ) );
-               return;
        }
-       $np = User::randomPassword();
-       $u->setNewpassword( $np );
-
-       setcookie( "{$wgDBname}Password", "", time() - 3600, $wgCookiePath, $wgCookieDomain );
-       $u->saveSettings();
 
-       $ip = getenv( "REMOTE_ADDR" );
-       if ( "" == $ip ) { $ip = "(Unknown)"; }
 
-       $m = wfMsg( "passwordremindertext", $ip, $u->getName(), $np );
-
-       mail( $u->getEmail(), wfMsg( "passwordremindertitle" ), $m,
-         "MIME-Version: 1.0\r\n" .
-         "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
-         "Content-transfer-encoding: 8bit\r\n" .
-         "From: $wgPasswordSender" );
-         
-       return $u;
-}
+       /* private */ function mailPasswordInternal( $u )
+       {
+               global $wgDeferredUpdateList, $wgOutputEncoding;
+               global $wgPasswordSender, $wgDBname, $wgIP;
+               global $wgCookiePath, $wgCookieDomain;
 
+               if ( "" == $u->getEmail() ) {
+                       $this->mainLoginForm( wfMsg( "noemail", $u->getName() ) );
+                       return;
+               }
+               $np = User::randomPassword();
+               $u->setNewpassword( $np );
 
+               setcookie( "{$wgDBname}Password", "", time() - 3600, $wgCookiePath, $wgCookieDomain );
+               $u->saveSettings();
 
+               $ip = $wgIP;
+               if ( "" == $ip ) { $ip = "(Unknown)"; }
 
+               $m = wfMsg( "passwordremindertext", $ip, $u->getName(), $np );
 
-/* private */ function successfulLogin( $msg )
-{
-       global $wgUser, $wgOut, $returnto;
-       global $wgDeferredUpdateList;
-
-       $wgUser->setCookies();
-       $up = new UserUpdate();
-       array_push( $wgDeferredUpdateList, $up );
-
-       $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
-       $wgOut->setRobotpolicy( "noindex,nofollow" );
-       $wgOut->setArticleFlag( false );
-       $wgOut->addHTML( $msg . "\n<p>" );
-       $wgOut->returnToMain();
-}
+               $error = userMailer( $u->getEmail(), $wgPasswordSender, wfMsg( "passwordremindertitle" ), $m );
+                 
+               return $error;
+       }
 
 
 
 
 
-function userNotPrivilegedMessage()
-{
-       global $wgOut, $wgUser, $wgLang;
+       /* private */ function successfulLogin( $msg )
+       {
+               global $wgUser;
+               global $wgDeferredUpdateList;
+               global $wgOut;
+
+               $wgOut->setPageTitle( wfMsg( "loginsuccesstitle" ) );
+               $wgOut->setRobotpolicy( "noindex,nofollow" );
+               $wgOut->setArticleRelated( false );
+               $wgOut->addHTML( $msg );
+               $wgOut->returnToMain();
+       }
 
-       $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) );
-       $wgOut->setRobotpolicy( "noindex,nofollow" );
-       $wgOut->setArticleFlag( false );
+       function userNotPrivilegedMessage()
+       {
+               global $wgOut, $wgUser, $wgLang;
+               
+               $wgOut->setPageTitle( wfMsg( "whitelistacctitle" ) );
+               $wgOut->setRobotpolicy( "noindex,nofollow" );
+               $wgOut->setArticleRelated( false );
+
+               $wgOut->addWikiText( wfMsg( "whitelistacctext" ) );
+               
+               $wgOut->returnToMain( false );
+       }
 
-       $wgOut->addWikiText( wfMsg( "whitelistacctext" ) );
-       $wgOut->returnToMain( false );
-}
+       /* private */ function mainLoginForm( $err )
+       {
+               global $wgUser, $wgOut, $wgLang;
+               global $wgDBname, $wgAllowRealName;
+
+               $le = wfMsg( "loginerror" );
+               $yn = wfMsg( "yourname" );
+               $yp = wfMsg( "yourpassword" );
+               $ypa = wfMsg( "yourpasswordagain" );
+               $rmp = wfMsg( "remembermypassword" );
+               $nuo = wfMsg( "newusersonly" );
+               $li = wfMsg( "login" );
+               $ca = wfMsg( "createaccount" );
+               $cam = wfMsg( "createaccountmail" );
+               $ye = wfMsg( "youremail" );
+               if ($wgAllowRealName) {
+                   $yrn = wfMsg( "yourrealname" );
+               } else {
+                   $yrn = '';
+               }
+               $efl = wfMsg( "emailforlost" );
+               $mmp = wfMsg( "mailmypassword" );
+               $endText = wfMsg( "loginend" );
 
+               if ( $endText = "&lt;loginend&gt;" ) {
+                       $endText = "";
+               }
 
+               if ( "" == $this->mName ) {
+                       if ( 0 != $wgUser->getID() ) {
+                               $this->mName = $wgUser->getName();
+                       } else {
+                               $this->mName = @$_COOKIE["{$wgDBname}UserName"];
+                       }
+               }
 
+               $wgOut->setPageTitle( wfMsg( "userlogin" ) );
+               $wgOut->setRobotpolicy( "noindex,nofollow" );
+               $wgOut->setArticleRelated( false );
 
-/* private */ function mainLoginForm( $err )
-{
-       global $wgUser, $wgOut, $wgLang, $returnto;
-       global $wpName, $wpPassword, $wpRetype, $wpRemember;
-       global $wpEmail, $HTTP_COOKIE_VARS, $wgDBname;
-
-       $le = wfMsg( "loginerror" );
-       $yn = wfMsg( "yourname" );
-       $yp = wfMsg( "yourpassword" );
-       $ypa = wfMsg( "yourpasswordagain" );
-       $rmp = wfMsg( "remembermypassword" );
-       $ayn = wfMsg( "areyounew" );
-       $nuo = wfMsg( "newusersonly" );
-       $li = wfMsg( "login" );
-       $ca = wfMsg( "createaccount" );
-       $cam = wfMsg( "createaccountmail" );
-       $ye = wfMsg( "youremail" );
-       $efl = wfMsg( "emailforlost" );
-       $mmp = wfMsg( "mailmypassword" );
-
-       $name = $wpName;
-       if ( "" == $name ) {
-               if ( 0 != $wgUser->getID() ) {
-                       $name = $wgUser->getName();
+               if ( "" == $err ) {
+                       $lp = wfMsg( "loginprompt" );
+                       $wgOut->addHTML( "<h2>$li:</h2>\n<p>$lp</p>" );
                } else {
-                       $name = $HTTP_COOKIE_VARS["{$wgDBname}UserName"];
+                       $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1' 
+       color='red'>$err</font>\n" );
+               }
+               if ( 1 == $wgUser->getOption( "rememberpassword" ) ) {
+                       $checked = " checked";
+               } else {
+                       $checked = "";
+               }
+               
+               $q = "action=submit";
+               if ( !empty( $this->mReturnto ) ) {
+                       $q .= "&returnto=" . wfUrlencode( $this->mReturnto );
+               }
+               
+               $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 );
+
+               if ($wgUser->getID() != 0) {
+                       $cambutton = "<input tabindex='6' type='submit' name=\"wpCreateaccountMail\" value=\"{$cam}\" />";
+               } else {
+                       $cambutton = "";
                }
-       }
-       $pwd = $wpPassword;
-
-       $wgOut->setPageTitle( wfMsg( "userlogin" ) );
-       $wgOut->setRobotpolicy( "noindex,nofollow" );
-       $wgOut->setArticleFlag( false );
 
-       if ( "" == $err ) {
-               $wgOut->addHTML( "<h2>$li:</h2>\n" );
-       } else {
-               $wgOut->addHTML( "<h2>$le:</h2>\n<font size='+1' 
-color='red'>$err</font>\n" );
-       }
-       if ( 1 == $wgUser->getOption( "rememberpassword" ) ) {
-               $checked = " checked";
-       } else {
-               $checked = "";
+               $wgOut->addHTML( "
+       <form name=\"userlogin\" id=\"userlogin\" method=\"post\" action=\"{$action}\">
+       <table border='0'><tr>
+       <td align='right'>$yn:</td>
+       <td align='left'>
+       <input tabindex='1' type='text' name=\"wpName\" value=\"{$encName}\" size='20' />
+       </td>
+       <td align='left'>
+       <input tabindex='3' type='submit' name=\"wpLoginattempt\" value=\"{$li}\" />
+       </td>
+       </tr>
+       <tr>
+       <td align='right'>$yp:</td>
+       <td align='left'>
+       <input tabindex='2' type='password' name=\"wpPassword\" value=\"{$encPassword}\" size='20' />
+       </td>
+       <td align='left'>
+       <input tabindex='7' type='checkbox' name=\"wpRemember\" value=\"1\" id=\"wpRemember\"$checked /><label for=\"wpRemember\">$rmp</label>
+       </td>
+       </tr>");
+
+               if ($wgUser->isAllowedToCreateAccount()) {
+                       $encRetype = htmlspecialchars( $this->mRetype );
+                       $encEmail = htmlspecialchars( $this->mEmail );
+       $wgOut->addHTML("<tr><td colspan='3'>&nbsp;</td></tr><tr>
+       <td align='right'>$ypa:</td>
+       <td align='left'>
+       <input tabindex='4' type='password' name=\"wpRetype\" value=\"{$encRetype}\" 
+       size='20' />
+       </td><td>$nuo</td></tr>
+       <tr>
+       <td align='right'>$ye:</td>
+       <td align='left'>
+       <input tabindex='6' type='text' name=\"wpEmail\" value=\"{$encEmail}\" size='20' />
+       </td>");
+                   
+       if ($wgAllowRealName) {
+           $wgOut->addHTML("<td>&nbsp;</td>
+                             </tr><tr>
+                            <td align='right'>$yrn:</td>
+                            <td align='left'>
+                             <input tabindex='6' type='text' name=\"wpRealName\" value=\"{$encRealName}\" size='20' />
+                             </td>");
        }
-       $q = "action=submit";
-       if ( "" != $returnto ) { $q .= "&returnto=" . wfUrlencode($returnto); }
-       $action = wfLocalUrlE( $wgLang->specialPage( "Userlogin" ), $q );
-
-       $wpName = wfEscapeHTML( $wpName );
-       $wpPassword = wfEscapeHTML( $wpPassword );
-       $wpRetype = wfEscapeHTML( $wpRetype );
-       $wpEmail = wfEscapeHTML( $wpEmail );
-
-       if ($wgUser->getID() != 0) {
-               $cambutton = "<input tabindex=6 type=submit name=\"wpCreateaccountMail\" value=\"{$cam}\">";
+                   
+       $wgOut->addHTML("<td align='left'>
+       <input tabindex='7' type='submit' name=\"wpCreateaccount\" value=\"{$ca}\" />
+       $cambutton
+       </td></tr>");
+               }
+           
+               $wgOut->addHTML("
+       <tr><td colspan='3'>&nbsp;</td></tr><tr>
+       <td colspan='3' align='left'>
+       <p>$efl<br />
+       <input tabindex='8' type='submit' name=\"wpMailmypassword\" value=\"{$mmp}\" /></p>
+       </td></tr></table>
+       </form>\n" );
+               $wgOut->addHTML( $endText );
        }
 
-       $wgOut->addHTML( "
-<form name=\"userlogin\" id=\"userlogin\" method=\"post\" action=\"{$action}\">
-<table border=0><tr>
-<td align=right>$yn:</td>
-<td colspan=2 align=left>
-<input tabindex=1 type=text name=\"wpName\" value=\"{$name}\" size=20>
-</td></tr><tr>
-<td align=right>$yp:</td>
-<td align=left>
-<input tabindex=2 type=password name=\"wpPassword\" value=\"{$pwd}\" size=20>
-</td>
-<td align=left>
-<input tabindex=3 type=submit name=\"wpLoginattempt\" value=\"{$li}\">
-</td></tr>");
-
-       if ($wgUser->isAllowedToCreateAccount()) {
-
-$wgOut->addHTML("<tr><td colspan=3>&nbsp;</td></tr><tr>
-<td align=right>$ypa:</td>
-<td align=left>
-<input tabindex=4 type=password name=\"wpRetype\" value=\"{$wpRetype}\" 
-size=20>
-</td><td>$nuo</td></tr>
-<tr>
-<td align=right>$ye:</td>
-<td align=left>
-<input tabindex=5 type=text name=\"wpEmail\" value=\"{$wpEmail}\" size=20>
-</td><td align=left>
-<input tabindex=6 type=submit name=\"wpCreateaccount\" value=\"{$ca}\">
-$cambutton
-</td></tr>");
+       /* private */ function hasSessionCookie()
+       {
+               global $wgDisableCookieCheck;
+               return ( $wgDisableCookieCheck ) ? true : ( "" != $_COOKIE[session_name()] );
        }
+         
+       /* private */ function cookieRedirectCheck( $type )
+       {
+               global $wgOut, $wgLang;
 
-       $wgOut->addHTML("
-<tr>
-<td colspan=3 align=left>
-<input tabindex=7 type=checkbox name=\"wpRemember\" value=\"1\" id=\"wpRemember\"$checked><label for=\"wpRemember\">$rmp</label>
-</td></tr>
-<tr><td colspan=3>&nbsp;</td></tr><tr>
-<td colspan=3 align=left>
-<p>$efl<br>
-<input tabindex=8 type=submit name=\"wpMailmypassword\" value=\"{$mmp}\">
-</td></tr></table>
-</form>\n" );
-
-
-
-}
-
-/* private */ function cookieCheck() {
+               $titleObj = Title::makeTitle( NS_SPECIAL, "Userlogin" );
+               $check = $titleObj->getFullURL( "wpCookieCheck=$type" );
 
-       global $HTTP_COOKIE_VARS, $wgOut, $returnto;
-       global $wgDisableCookieCheck;
+               return $wgOut->redirect( $check );
+       }
 
-       if ( $wgDisableCookieCheck ) {
-               return true;
+       /* private */ function onCookieRedirectCheck( $type ) {
+               global $wgUser;
+
+               if ( !$this->hasSessionCookie() ) {
+                       if ( $type == "new" ) {
+                               return $this->mainLoginForm( wfMsg( "nocookiesnew" ) );
+                       } else if ( $type == "login" ) {
+                               return $this->mainLoginForm( wfMsg( "nocookieslogin" ) );
+                       } else {
+                               # shouldn't happen
+                               return $this->mainLoginForm( wfMsg( "error" ) );
+                       }
+               } else {
+                       return $this->successfulLogin( wfMsg( "loginsuccess", $wgUser->getName() ) );
+               }
        }
 
-       # XXX: kind of crude check to see if cookies are enabled, but it works OK
+       /* private */ function throttleHit( $limit ) {
+               global $wgOut;
 
-       if ( "" == $HTTP_COOKIE_VARS[session_name()])
-       {
-               # Don't go back to login page; they won't get time to
-               # enable cookies and send us one, so they'll get this msg again. Instead, 
-               # let them enable cookies on the error page, then go back to login page.
-               # XXX: wipes returnto, unfortunately.
-
-               $returnto = "Special:Userlogin";                
-               $wgOut->errorpage( "nocookies", "nocookiestext" );
-               return false;
+               $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );
        }
-
-       return true;
 }
-
 ?>