merged master
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 19af852..6c9be85 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;
@@ -106,13 +106,8 @@ class LoginForm extends SpecialPage {
                $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 +202,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 +261,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 +861,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 +903,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 +937,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 );
+               }
        }
 
        /**