Redirect on login instead of showing a message
authorAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 8 Sep 2008 21:53:56 +0000 (21:53 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 8 Sep 2008 21:53:56 +0000 (21:53 +0000)
This saves a click.  A "You have successfully logged in" message adds no extra information, it just gets in the way -- especially if you got to the login page from a permissions error.  The welcome message is still displayed on account creation.

This slightly modifies the semantics of a hook.  It also makes the loginsuccess message unused, so I've deleted it from the maintenance files and also MessagesEn.  I assume it will automatically vanish from the other message files, or at least that there's some tool to remove it that I don't know about that's better than sed.

This was prompted by discussion on bug 15484.

RELEASE-NOTES
docs/hooks.txt
includes/specials/SpecialUserlogin.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index f80fd75..ab555a8 100644 (file)
@@ -115,6 +115,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 2889) MediaWiki:Print.css applies to the printable version
 * Category counts (e.g. from {{PAGESINCATEGORY:}}) should be more accurate for
   small categories
+* After logging in, automatically redirect to wherever you logged in from
 
 === Bug fixes in 1.14 ===
 
index 9e9dbf9..7e2814a 100644 (file)
@@ -1357,7 +1357,9 @@ $user: user object being loaded
 
 'UserLoginComplete': after a user has logged in
 $user: the user object that was created on login
-$inject_html: Any HTML to inject after the "logged in" message.
+$inject_html: Any HTML to inject after the "logged in" message.  As of 1.14,
+  this only applies to new account creations, since simple logins are HTTP re-
+  directs.
                    
 'UserLoginForm': change to manipulate the login form
 $template: SimpleTemplate instance for the form
index 82a1ac9..c4481c4 100644 (file)
@@ -182,7 +182,7 @@ class LoginForm {
                        $wgUser->setCookies();
                        wfRunHooks( 'AddNewAccount', array( $wgUser ) );
                        if( $this->hasSessionCookie() ) {
-                               return $this->successfulLogin( 'welcomecreation', $wgUser->getName(), false );
+                               return $this->successfulCreation();
                        } else {
                                return $this->cookieRedirectCheck( 'new' );
                        }
@@ -532,7 +532,7 @@ class LoginForm {
                                        global $wgLang, $wgRequest;
                                        $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
                                        $wgLang = Language::factory( $code );
-                                       return $this->successfulLogin( 'loginsuccess', $wgUser->getName() );
+                                       return $this->successfulLogin();
                                } else {
                                        return $this->cookieRedirectCheck( 'login' );
                                }
@@ -669,29 +669,53 @@ class LoginForm {
 
 
        /**
-        * @param string $msg Message key that will be shown on success
-        * @param $params String: parameters for the above message
-        * @param bool $auto Toggle auto-redirect to main page; default true
+        * Run any hooks registered for logins, then HTTP redirect to
+        * $this->mReturnTo (or Main Page if that's undefined).  Formerly we had a
+        * nice message here, but that's really not as useful as just being sent to
+        * wherever you logged in from.  It should be clear that the action was
+        * successful, given the lack of error messages plus the appearance of your
+        * name in the upper right.
+        *
         * @private
         */
-       function successfulLogin( $msg, $params, $auto = true ) {
-               global $wgUser;
-               global $wgOut;
+       function successfulLogin() {
+               global $wgUser, $wgOut;
 
-               # Run any hooks; ignore results
+               # Run any hooks; ignore injected HTML since we just redirect
+               $injected_html = '';
+               wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
+
+               $titleObj = Title::newFromText( $this->mReturnTo );
+               if ( !$titleObj instanceof Title ) {
+                       $titleObj = Title::newMainPage();
+               }
 
+               $wgOut->redirect( $titleObj->getFullURL() );
+       }
+
+       /**
+        * Run any hooks registered for logins, then display a message welcoming
+        * the user.
+        *
+        * @private
+        */
+       function successfulCreation() {
+               global $wgUser, $wgOut;
+
+               # Run any hooks; display injected HTML
                $injected_html = '';
                wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
 
                $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
-               $wgOut->addWikiMsgArray( $msg, $params );
+               $wgOut->addWikiMsg( 'welcomecreation', $wgUser->getName() );
                $wgOut->addHtml( $injected_html );
+
                if ( !empty( $this->mReturnTo ) ) {
-                       $wgOut->returnToMain( $auto, $this->mReturnTo );
+                       $wgOut->returnToMain( null, $this->mReturnTo );
                } else {
-                       $wgOut->returnToMain( $auto );
+                       $wgOut->returnToMain( null );
                }
        }
 
@@ -901,7 +925,7 @@ class LoginForm {
                                return $this->mainLoginForm( wfMsg( 'error' ) );
                        }
                } else {
-                       return $this->successfulLogin( 'loginsuccess', $wgUser->getName() );
+                       return $this->successfulLogin();
                }
        }
 
index 11204d8..d8d6ad3 100644 (file)
@@ -928,7 +928,6 @@ You have cookies disabled.
 Please enable them and try again.',
 'noname'                     => 'You have not specified a valid user name.',
 'loginsuccesstitle'          => 'Login successful',
-'loginsuccess'               => "'''You are now logged in to {{SITENAME}} as \"\$1\".'''",
 'nosuchuser'                 => 'There is no user by the name "$1".
 Check your spelling, or create a new account.',
 'nosuchusershort'            => 'There is no user by the name "<nowiki>$1</nowiki>".
index 236bfc6..be0be0f 100644 (file)
@@ -405,7 +405,6 @@ $wgMessageStructure = array(
                'nocookieslogin',
                'noname',
                'loginsuccesstitle',
-               'loginsuccess',
                'nosuchuser',
                'nosuchusershort',
                'nouserspecified',