From c523073ff872a37dc257075e4018b8a63d0e2688 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 8 Sep 2008 21:53:56 +0000 Subject: [PATCH] Redirect on login instead of showing a message 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 | 1 + docs/hooks.txt | 4 ++- includes/specials/SpecialUserlogin.php | 50 +++++++++++++++++++------- languages/messages/MessagesEn.php | 1 - maintenance/language/messages.inc | 1 - 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f80fd75ef5..ab555a8473 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/docs/hooks.txt b/docs/hooks.txt index 9e9dbf9ee7..7e2814ab54 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 82a1ac99fd..c4481c4474 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -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(); } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 11204d8063..d8d6ad3268 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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 "$1". diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 236bfc651e..be0be0f5f8 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -405,7 +405,6 @@ $wgMessageStructure = array( 'nocookieslogin', 'noname', 'loginsuccesstitle', - 'loginsuccess', 'nosuchuser', 'nosuchusershort', 'nouserspecified', -- 2.20.1