Create PostLoginRedirect Hook for changing the redirect behavior
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 4006e49..abb32ce 100644 (file)
@@ -193,7 +193,10 @@ class LoginForm extends SpecialPage {
                                'title' => null,
                        ) + $this->mRequest->getQueryValues();
                        $url = $title->getFullURL( $query, false, PROTO_HTTPS );
-                       if ( $wgSecureLogin && wfCanIPUseHTTPS( $this->getRequest()->getIP() ) ) {
+                       if ( $wgSecureLogin
+                               && wfCanIPUseHTTPS( $this->getRequest()->getIP() )
+                               && !$this->mFromHTTP ) // Avoid infinite redirect
+                       {
                                $url = wfAppendQuery( $url, 'fromhttp=1' );
                                $this->getOutput()->redirect( $url );
                                // Since we only do this redir to change proto, always vary
@@ -435,7 +438,11 @@ class LoginForm extends SpecialPage {
 
                // Normalize the name so that silly things don't cause "invalid username"
                // errors. User::newFromName does some rather strict checking, rejecting
-               // e.g. leading/trailing/multiple spaces.
+               // e.g. leading/trailing/multiple spaces. But first we need to reject
+               // usernames that would be treated as titles with a fragment part.
+               if ( strpos( $this->mUsername, '#' ) !== false ) {
+                       return Status::newFatal( 'noname' );
+               }
                $title = Title::makeTitleSafe( NS_USER, $this->mUsername );
                if ( !is_object( $title ) ) {
                        return Status::newFatal( 'noname' );
@@ -1002,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' );
@@ -1030,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 ) {
@@ -1050,7 +1061,7 @@ class LoginForm extends SpecialPage {
 
                $out->addHTML( $injected_html );
 
-               $this->executeReturnTo( 'success' );
+               $this->executeReturnTo( $type );
        }
 
        /**
@@ -1096,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
@@ -1117,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
         */
@@ -1131,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();