Merge "Fix separated login link so that create account and login are always next...
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index f0b15db..c101897 100644 (file)
@@ -74,7 +74,7 @@ class LoginForm extends SpecialPage {
         * Loader
         */
        function load() {
-               global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
+               global $wgAuth, $wgHiddenPrefs, $wgEnableEmail;
 
                if ( $this->mLoaded ) {
                        return;
@@ -105,14 +105,8 @@ class LoginForm extends SpecialPage {
                $this->mLanguage = $request->getText( 'uselang' );
                $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
                $this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
-
-               if ( $wgRedirectOnLogin ) {
-                       $this->mReturnTo = $wgRedirectOnLogin;
-                       $this->mReturnToQuery = '';
-               } else {
-                       $this->mReturnTo = $request->getVal( 'returnto', '' );
-                       $this->mReturnToQuery = $request->getVal( 'returntoquery', '' );
-               }
+               $this->mReturnTo = $request->getVal( 'returnto', '' );
+               $this->mReturnToQuery = $request->getVal( 'returntoquery', '' );
 
                if( $wgEnableEmail ) {
                        $this->mEmail = $request->getText( 'wpEmail' );
@@ -207,7 +201,7 @@ class LoginForm extends SpecialPage {
                        $this->mainLoginForm( $this->msg( 'mailerror', $result->getWikiText() )->text() );
                } else {
                        $out->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
-                       $out->returnToMain( false );
+                       $this->executeReturnTo( 'success' );
                }
        }
 
@@ -266,7 +260,7 @@ class LoginForm extends SpecialPage {
                        # Confirm that the account was created
                        $out->setPageTitle( $this->msg( 'accountcreated' ) );
                        $out->addWikiMsg( 'accountcreatedtext', $u->getName() );
-                       $out->returnToMain( false, $this->getTitle() );
+                       $out->addReturnTo( $this->getTitle() );
                        wfRunHooks( 'AddNewAccount', array( $u, false ) );
                        $u->addNewUserLogEntry( false, $this->mReason );
                }
@@ -866,16 +860,7 @@ class LoginForm extends SpecialPage {
                if( $injected_html !== '' ) {
                        $this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
                } else {
-                       $titleObj = Title::newFromText( $this->mReturnTo );
-                       if ( !$titleObj instanceof Title ) {
-                               $titleObj = Title::newMainPage();
-                       }
-                       $redirectUrl = $titleObj->getFullURL( $this->mReturnToQuery );
-                       global $wgSecureLogin;
-                       if( $wgSecureLogin && !$this->mStickHTTPS ) {
-                               $redirectUrl = preg_replace( '/^https:/', 'http:', $redirectUrl );
-                       }
-                       $this->getOutput()->redirect( $redirectUrl );
+                       $this->executeReturnTo( 'successredirect' );
                }
        }
 
@@ -917,11 +902,7 @@ class LoginForm extends SpecialPage {
 
                $out->addHTML( $injected_html );
 
-               if ( $this->mReturnTo !== '' ) {
-                       $out->returnToMain( null, $this->mReturnTo, $this->mReturnToQuery );
-               } else {
-                       $out->returnToMain( null );
-               }
+               $this->executeReturnTo( 'success' );
        }
 
        /**
@@ -955,7 +936,42 @@ class LoginForm extends SpecialPage {
                        $block->getByName()
                );
 
-               $out->returnToMain( false );
+               $this->executeReturnTo( 'error' );
+       }
+
+       /**
+        * Add a "return to" link or redirect to it.
+        *
+        * @param $type string, one of the following:
+        *    - error: display a return to link ignoring $wgRedirectOnLogin
+        *    - success: display a return to link using $wgRedirectOnLogin if needed
+        *    - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
+        */
+       private function executeReturnTo( $type ) {
+               global $wgRedirectOnLogin, $wgSecureLogin;
+
+               if ( $type != 'error' && $wgRedirectOnLogin !== null ) {
+                       $returnTo = $wgRedirectOnLogin;
+                       $returnToQuery = array();
+               } else {
+                       $returnTo = $this->mReturnTo;
+                       $returnToQuery = wfCgiToArray( $this->mReturnToQuery );
+               }
+
+               $returnToTitle = Title::newFromText( $returnTo );
+               if ( !$returnToTitle ) {
+                       $returnToTitle = Title::newMainPage();
+               }
+
+               if ( $type == 'successredirect' ) {
+                       $redirectUrl = $returnToTitle->getFullURL( $returnToQuery );
+                       if( $wgSecureLogin && !$this->mStickHTTPS ) {
+                               $redirectUrl = preg_replace( '/^https:/', 'http:', $redirectUrl );
+                       }
+                       $this->getOutput()->redirect( $redirectUrl );
+               } else {
+                       $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery );
+               }
        }
 
        /**
@@ -1269,19 +1285,24 @@ class LoginForm extends SpecialPage {
                        // no link for currently used language
                        return htmlspecialchars( $text );
                }
-               $attr = array( 'uselang' => $lang );
+               $query = array( 'uselang' => $lang );
                if( $this->mType == 'signup' ) {
-                       $attr['type'] = 'signup';
+                       $query['type'] = 'signup';
                }
                if( $this->mReturnTo !== '' ) {
-                       $attr['returnto'] = $this->mReturnTo;
-                       $attr['returntoquery'] = $this->mReturnToQuery;
+                       $query['returnto'] = $this->mReturnTo;
+                       $query['returntoquery'] = $this->mReturnToQuery;
                }
+
+               $attr = array();
+               $targetLanguage = Language::factory( $lang );
+               $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
+
                return Linker::linkKnown(
                        $this->getTitle(),
                        htmlspecialchars( $text ),
-                       array(),
-                       $attr
+                       $attr,
+                       $query
                );
        }
 }