Merge "Remove adittional type hinting stuff because PHP will die if its there >_>"
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index fa1713f..7d91096 100644 (file)
@@ -125,11 +125,7 @@ class LoginForm extends SpecialPage {
                }
 
                if( !$wgAuth->validDomain( $this->mDomain ) ) {
-                       if ( isset( $_SESSION['wsDomain'] ) ) {
-                               $this->mDomain = $_SESSION['wsDomain'];
-                       } else {
-                               $this->mDomain = 'invaliddomain';
-                       }
+                       $this->mDomain = $wgAuth->getDomain();
                }
                $wgAuth->setDomain( $this->mDomain );
 
@@ -167,11 +163,14 @@ class LoginForm extends SpecialPage {
                        return;
                } elseif( $this->mPosted ) {
                        if( $this->mCreateaccount ) {
-                               return $this->addNewAccount();
+                               $this->addNewAccount();
+                               return;
                        } elseif ( $this->mCreateaccountMail ) {
-                               return $this->addNewAccountMailPassword();
+                               $this->addNewAccountMailPassword();
+                               return;
                        } elseif ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
-                               return $this->processLogin();
+                               $this->processLogin();
+                               return;
                        }
                }
                $this->mainLoginForm( '' );
@@ -213,7 +212,7 @@ class LoginForm extends SpecialPage {
 
        /**
         * @private
-        * @return bool|void
+        * @return bool
         */
        function addNewAccount() {
                global $wgUser, $wgEmailAuthentication, $wgLoginLanguageSelector;
@@ -221,7 +220,7 @@ class LoginForm extends SpecialPage {
                # Create the account and abort if there's a problem doing so
                $u = $this->addNewAccountInternal();
                if( $u == null ) {
-                       return;
+                       return false;
                }
 
                # If we showed up language selection links, and one was in use, be
@@ -258,9 +257,9 @@ class LoginForm extends SpecialPage {
                        wfRunHooks( 'AddNewAccount', array( $u, false ) );
                        $u->addNewUserLogEntry();
                        if( $this->hasSessionCookie() ) {
-                               return $this->successfulCreation();
+                               $this->successfulCreation();
                        } else {
-                               return $this->cookieRedirectCheck( 'new' );
+                               $this->cookieRedirectCheck( 'new' );
                        }
                } else {
                        # Confirm that the account was created
@@ -269,8 +268,8 @@ class LoginForm extends SpecialPage {
                        $out->returnToMain( false, $this->getTitle() );
                        wfRunHooks( 'AddNewAccount', array( $u, false ) );
                        $u->addNewUserLogEntry( false, $this->mReason );
-                       return true;
                }
+               return true;
        }
 
        /**
@@ -334,7 +333,7 @@ class LoginForm extends SpecialPage {
 
                $ip = $this->getRequest()->getIP();
                if ( $currentUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
-                       $this->mainLoginForm( $this->msg( 'sorbs_create_account_reason' )->text() . ' ' . $this->msg( 'parentheses' )->rawParams( htmlspecialchars( $ip ) )->escaped() );
+                       $this->mainLoginForm( $this->msg( 'sorbs_create_account_reason' )->text() . ' ' . $this->msg( 'parentheses', $ip )->escaped() );
                        return false;
                }
 
@@ -746,9 +745,9 @@ class LoginForm extends SpecialPage {
                                        $userLang = Language::factory( $code );
                                        $wgLang = $userLang;
                                        $this->getContext()->setLanguage( $userLang );
-                                       return $this->successfulLogin();
+                                       $this->successfulLogin();
                                } else {
-                                       return $this->cookieRedirectCheck( 'login' );
+                                       $this->cookieRedirectCheck( 'login' );
                                }
                                break;
 
@@ -768,7 +767,7 @@ class LoginForm extends SpecialPage {
                        case self::NOT_EXISTS:
                                if( $this->getUser()->isAllowed( 'createaccount' ) ) {
                                        $this->mainLoginForm( $this->msg( 'nosuchuser',
-                                          wfEscapeWikiText( $this->mUsername ) )->parse() );
+                                               wfEscapeWikiText( $this->mUsername ) )->parse() );
                                } else {
                                        $this->mainLoginForm( $this->msg( 'nosuchusershort',
                                                wfEscapeWikiText( $this->mUsername ) )->text() );
@@ -804,7 +803,7 @@ class LoginForm extends SpecialPage {
        function resetLoginForm( $error ) {
                $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) );
                $reset = new SpecialChangePassword();
-               $reset->setContext( $this );
+               $reset->setContext( $this->getContext() );
                $reset->execute( null );
        }
 
@@ -899,6 +898,8 @@ class LoginForm extends SpecialPage {
 
        /**
         * Display a "login successful" page.
+        * @param $msgname string
+        * @param $injected_html string
         */
        private function displaySuccessfulLogin( $msgname, $injected_html ) {
                $out = $this->getOutput();
@@ -1145,9 +1146,9 @@ class LoginForm extends SpecialPage {
         */
        public static function setLoginToken() {
                global $wgRequest;
-               // Use User::generateToken() instead of $user->editToken()
+               // Generate a token directly instead of using $user->editToken()
                // because the latter reuses $_SESSION['wsEditToken']
-               $wgRequest->setSessionData( 'wsLoginToken', User::generateToken() );
+               $wgRequest->setSessionData( 'wsLoginToken', MWCryptRand::generateHex( 32 ) );
        }
 
        /**
@@ -1172,7 +1173,7 @@ class LoginForm extends SpecialPage {
         */
        public static function setCreateaccountToken() {
                global $wgRequest;
-               $wgRequest->setSessionData( 'wsCreateaccountToken', User::generateToken() );
+               $wgRequest->setSessionData( 'wsCreateaccountToken', MWCryptRand::generateHex( 32 ) );
        }
 
        /**
@@ -1185,7 +1186,6 @@ class LoginForm extends SpecialPage {
 
        /**
         * @private
-        * @return void
         */
        function cookieRedirectCheck( $type ) {
                $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
@@ -1195,7 +1195,7 @@ class LoginForm extends SpecialPage {
                }
                $check = $titleObj->getFullURL( $query );
 
-               return $this->getOutput()->redirect( $check );
+               $this->getOutput()->redirect( $check );
        }
 
        /**
@@ -1204,15 +1204,15 @@ class LoginForm extends SpecialPage {
        function onCookieRedirectCheck( $type ) {
                if ( !$this->hasSessionCookie() ) {
                        if ( $type == 'new' ) {
-                               return $this->mainLoginForm( $this->msg( 'nocookiesnew' )->parse() );
+                               $this->mainLoginForm( $this->msg( 'nocookiesnew' )->parse() );
                        } elseif ( $type == 'login' ) {
-                               return $this->mainLoginForm( $this->msg( 'nocookieslogin' )->parse() );
+                               $this->mainLoginForm( $this->msg( 'nocookieslogin' )->parse() );
                        } else {
                                # shouldn't happen
-                               return $this->mainLoginForm( $this->msg( 'error' )->text() );
+                               $this->mainLoginForm( $this->msg( 'error' )->text() );
                        }
                } else {
-                       return $this->successfulLogin();
+                       $this->successfulLogin();
                }
        }
 
@@ -1257,6 +1257,10 @@ class LoginForm extends SpecialPage {
         * @return string
         */
        function makeLanguageSelectorLink( $text, $lang ) {
+               if( $this->getLanguage()->getCode() == $lang ) {
+                       // no link for currently used language
+                       return htmlspecialchars( $text );
+               }
                $attr = array( 'uselang' => $lang );
                if( $this->mType == 'signup' ) {
                        $attr['type'] = 'signup';