Cripple the wiki text stuff for now. It doesn't SEEM dangerous but I haven't tested...
[lhc/web/wiklou.git] / includes / SpecialUserlogin.php
index 5e37f6f..6a605fd 100644 (file)
@@ -25,21 +25,9 @@ function wfSpecialUserlogin() {
  * @subpackage SpecialPage
  */
 class LoginForm {
-       private
-               $mAction,
-               $mCookieCheck,
-               $mCreateaccount,
-               $mCreateaccountMail,
-               $mDomain,
-               $mEmail,                        // Entered user email ??
-               $mLoginattempt,
-               $mMailmypassword,
-               $mName,                         // Entered username
-               $mPassword,                     // Entered user password
-               $mPosted,
-               $mRemember,                     // bool, if user want to be remembered
-               $mReturnTo,                     // article to return to once logged in
-               $mRetype ;
+       var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
+       var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
+       var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
 
        /**
         * Constructor
@@ -65,6 +53,7 @@ class LoginForm {
                $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
                $this->mAction = $request->getVal( 'action' );
                $this->mRemember = $request->getCheck( 'wpRemember' );
+               $this->mLanguage = $request->getText( 'uselang' );
 
                if( $wgEnableEmail ) {
                        $this->mEmail = $request->getText( 'wpEmail' );
@@ -153,6 +142,12 @@ class LoginForm {
                if( $u == NULL )
                        return;
                        
+               # If we showed up language selection links, and one was in use, be
+               # smart (and sensible) and save that language as the user's preference
+               global $wgLoginLanguageSelector;
+               if( $wgLoginLanguageSelector && $this->mLanguage )
+                       $u->setOption( 'language', $this->mLanguage );
+               
                # Save user settings and send out an email authentication message if needed
                $u->saveSettings();
                if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) )
@@ -376,6 +371,14 @@ class LoginForm {
         * @private
         */
        function mailPassword() {
+               global $wgUser, $wgOut;
+               
+               # Check against the rate limiter
+               if( $wgUser->pingLimiter( 'mailpassword' ) ) {
+                       $wgOut->rateLimited();
+                       return;
+               }
+       
                if ( '' == $this->mName ) {
                        $this->mainLoginForm( wfMsg( 'noname' ) );
                        return;
@@ -407,6 +410,7 @@ class LoginForm {
         */
        function mailPasswordInternal( $u ) {
                global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
+               global $wgServer, $wgScript;
 
                if ( '' == $u->getEmail() ) {
                        return wfMsg( 'noemail', $u->getName() );
@@ -422,7 +426,7 @@ class LoginForm {
                $ip = wfGetIP();
                if ( '' == $ip ) { $ip = '(Unknown)'; }
 
-               $m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np );
+               $m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np, $wgServer . $wgScript );
 
                $result = $u->sendMail( wfMsg( 'passwordremindertitle' ), $m );
                return $result;
@@ -475,6 +479,11 @@ class LoginForm {
                global $wgCookiePrefix;
                global $wgAuth;
 
+               if ( $this->mType == 'signup' && !$wgUser->isAllowedToCreateAccount() ) {
+                       $this->userNotPrivilegedMessage();
+                       return;
+               }
+
                if ( '' == $this->mName ) {
                        if ( $wgUser->isLoggedIn() ) {
                                $this->mName = $wgUser->getName();
@@ -527,11 +536,17 @@ class LoginForm {
                $template->set( 'action', $titleObj->getLocalUrl( $q ) );
                $template->set( 'message', $msg );
                $template->set( 'messagetype', $msgtype );
-               $template->set( 'create', $wgUser->isAllowedToCreateAccount() );
                $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
                $template->set( 'userealname', $wgAllowRealName );
                $template->set( 'useemail', $wgEnableEmail );
                $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember  );
+                               
+               global $wgLoginLanguageSelector;
+               if( $wgLoginLanguageSelector ) {
+                       $template->set( 'languages', $this->makeLanguageSelector() );
+                       if( $this->mLanguage )
+                               $template->set( 'uselang', $this->mLanguage );
+               }
                
                // Give authentication and captcha plugins a chance to modify the form
                $wgAuth->modifyUITemplate( $template );
@@ -608,5 +623,47 @@ class LoginForm {
 
                $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );
        }
+       
+       /**
+        * Produce a bar of links which allow the user to select another language
+        * during login/registration but retain "returnto"
+        *
+        * @return string
+        */
+       function makeLanguageSelector() {
+               $msg = wfMsgForContent( 'loginlanguagelinks' );
+               if( $msg != '' && $msg != '<loginlanguagelinks>' ) {
+                       $langs = explode( "\n", $msg );
+                       $links = array();
+                       foreach( $langs as $lang ) {
+                               $lang = trim( $lang, '* ' );
+                               $parts = explode( '|', $lang );
+                               $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
+                       }
+                       return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
+               } else {
+                       return '';
+               }
+       }
+       
+       /**
+        * Create a language selector link for a particular language
+        * Links back to this page preserving type and returnto
+        *
+        * @param $text Link text
+        * @param $lang Language code
+        */
+       function makeLanguageSelectorLink( $text, $lang ) {
+               global $wgUser;
+               $self = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
+               $attr[] = 'uselang=' . $lang;
+               if( $this->mType == 'signup' )
+                       $attr[] = 'type=signup';
+               if( $this->mReturnTo )
+                       $attr[] = 'returnto=' . $this->mReturnTo;
+               $skin =& $wgUser->getSkin();
+               return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );
+       }
+       
 }
 ?>