From 750a98bb5625e62dbd611a034700a2c0976a6c82 Mon Sep 17 00:00:00 2001 From: Rob Moen Date: Wed, 28 May 2014 13:29:32 -0700 Subject: [PATCH] Create PostLoginRedirect Hook for changing the redirect behavior Allows for modifying returnTo url, url parameters, and the redirect type. New return to condition 'signup' if redirecting after signup Treated same as 'success', though now explicitly marking as such Part of making GettingStarted not dependent on CentralAuth Bug: 65619 Change-Id: I219353d9825918e22d4772611a38d72c4e674e10 --- docs/hooks.txt | 10 ++++++++++ includes/specials/SpecialUserlogin.php | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 0b072f29c9..87f620d202 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2039,6 +2039,16 @@ $oldtext : the text of the article before editing $subject : subject of the new section &$text : text of the new section +'PostLoginRedirect': Modify the post login redirect behavior. +Occurs after signing up or logging in, allows for interception of redirect. +&$returnTo: The page name to return to, as a string +&$returnToQuery: array of url parameters, mapping parameter names to values +&$type: type of login redirect as string; + error: display a return to link ignoring $wgRedirectOnLogin + signup: display a return to link using $wgRedirectOnLogin if needed + success: display a return to link using $wgRedirectOnLogin if needed + successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed + 'PreferencesGetLegend': Override the text used for the of a preferences section. $form: the PreferencesForm object. This is a ContextSource as well diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index bee94f8d35..abb32ced57 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -1009,7 +1009,7 @@ class LoginForm extends SpecialPage { wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) ); if ( $injected_html !== '' ) { - $this->displaySuccessfulAction( $this->msg( 'loginsuccesstitle' ), + $this->displaySuccessfulAction( 'success', $this->msg( 'loginsuccesstitle' ), 'loginsuccess', $injected_html ); } else { $this->executeReturnTo( 'successredirect' ); @@ -1037,18 +1037,22 @@ class LoginForm extends SpecialPage { */ wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) ); - $this->displaySuccessfulAction( $this->msg( 'welcomeuser', $this->getUser()->getName() ), - $welcome_creation_msg, $injected_html ); + $this->displaySuccessfulAction( + 'signup', + $this->msg( 'welcomeuser', $this->getUser()->getName() ), + $welcome_creation_msg, $injected_html + ); } /** - * Display an "successful action" page. + * Display a "successful action" page. * + * @param string $type condition of return to; see `executeReturnTo` * @param string|Message $title Page's title * @param string $msgname * @param string $injected_html */ - private function displaySuccessfulAction( $title, $msgname, $injected_html ) { + private function displaySuccessfulAction( $type, $title, $msgname, $injected_html ) { $out = $this->getOutput(); $out->setPageTitle( $title ); if ( $msgname ) { @@ -1057,7 +1061,7 @@ class LoginForm extends SpecialPage { $out->addHTML( $injected_html ); - $this->executeReturnTo( 'success' ); + $this->executeReturnTo( $type ); } /** @@ -1103,6 +1107,7 @@ class LoginForm extends SpecialPage { * * @param string $type One of the following: * - error: display a return to link ignoring $wgRedirectOnLogin + * - signup: display a return to link using $wgRedirectOnLogin if needed * - success: display a return to link using $wgRedirectOnLogin if needed * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed * @param string $returnTo @@ -1124,6 +1129,7 @@ class LoginForm extends SpecialPage { * * @param string $type One of the following: * - error: display a return to link ignoring $wgRedirectOnLogin + * - signup: display a return to link using $wgRedirectOnLogin if needed * - success: display a return to link using $wgRedirectOnLogin if needed * - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed */ @@ -1138,6 +1144,9 @@ class LoginForm extends SpecialPage { $returnToQuery = wfCgiToArray( $this->mReturnToQuery ); } + // Allow modification of redirect behavior + wfRunHooks( 'PostLoginRedirect', array( &$returnTo, &$returnToQuery, &$type ) ); + $returnToTitle = Title::newFromText( $returnTo ); if ( !$returnToTitle ) { $returnToTitle = Title::newMainPage(); -- 2.20.1