Merge "Create PostLoginRedirect Hook for changing the redirect behavior"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 12 Jun 2014 14:24:50 +0000 (14:24 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 12 Jun 2014 14:24:50 +0000 (14:24 +0000)
docs/hooks.txt
includes/specials/SpecialUserlogin.php

index cb76341..4c2fd89 100644 (file)
@@ -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 <legend> of a
 preferences section.
 $form: the PreferencesForm object. This is a ContextSource as well
index dcc87a0..1ef96c3 100644 (file)
@@ -1010,7 +1010,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' );
@@ -1038,18 +1038,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 ) {
@@ -1058,7 +1062,7 @@ class LoginForm extends SpecialPage {
 
                $out->addHTML( $injected_html );
 
-               $this->executeReturnTo( 'success' );
+               $this->executeReturnTo( $type );
        }
 
        /**
@@ -1104,6 +1108,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
@@ -1125,6 +1130,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
         */
@@ -1139,6 +1145,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();