From f663810c6d4565a2682baa997d13efbc30945677 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 18 Aug 2012 12:08:32 +0200 Subject: [PATCH] Fix "return to" display on Special:UserLogin. - Do not use $wgRedirectOnLogin on permissions error message - Added LoginForm::executeReturnTo() to remove code duplication - Changed usage of OutputPage::returnToMain() to OutputPage::addReturnTo() since we already check these parameters ourself Change-Id: Ie80d03f5fca7aa87017f1ad7804dda721a1132de --- includes/specials/SpecialUserlogin.php | 70 ++++++++++++++++---------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 19af85245e..c101897219 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -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 ); + } } /** -- 2.20.1