From accac1dc3198f87cc3e8b9406836d7680052c0ac Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Tue, 19 Jul 2016 17:25:12 -0700 Subject: [PATCH] Add $direct parameter to UserLoginComplete hook This will help to differentiate between actual login and visiting the login page while already logged in. Bug: T140853 Change-Id: If8582ff61aee62b1d424e473b230ca883ddb6d05 --- RELEASE-NOTES-1.28 | 2 ++ docs/hooks.txt | 3 +++ includes/api/ApiLogin.php | 2 +- includes/specials/SpecialCreateAccount.php | 2 +- includes/specials/SpecialUserLogin.php | 2 +- includes/specials/pre-authmanager/SpecialUserlogin.php | 6 ++++-- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.28 b/RELEASE-NOTES-1.28 index 8b00d2efad..adf596f4d8 100644 --- a/RELEASE-NOTES-1.28 +++ b/RELEASE-NOTES-1.28 @@ -68,6 +68,8 @@ changes to languages because of Phabricator reports. * Deprecated APIEditBeforeSave hook in favor of EditFilterMergedContent. * The 'UploadVerification' hook is deprecated. Use 'UploadVerifyFile' instead. * SiteConfiguration::isLocalVHost() was removed (deprecated since 1.25). +* The 'UserLoginComplete' hook has a new parameter to differentiate between actual + login and visiting the login page while already logged in. == Compatibility == diff --git a/docs/hooks.txt b/docs/hooks.txt index 2b3116d7b5..e1b397472d 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -3467,6 +3467,9 @@ $user: User object for the logged-in user For functionality that needs to run after any login (API or web) use UserLoggedIn. &$user: the user object that was created on login &$inject_html: Any HTML to inject after the "logged in" message. +$direct: (bool) The hook is called directly after a successful login. This will only happen once + per login. A UserLoginComplete call with direct=false can happen when the user visits the login + page while already logged in. 'UserLoginForm': DEPRECATED! Create an AuthenticationProvider instead. Manipulate the login form. diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 35722298ba..0e4c6e0c84 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -208,7 +208,7 @@ class ApiLogin extends ApiBase { // Deprecated hook $injected_html = ''; - Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html ] ); + Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html, true ] ); $result['lguserid'] = intval( $user->getId() ); $result['lgusername'] = $user->getName(); diff --git a/includes/specials/SpecialCreateAccount.php b/includes/specials/SpecialCreateAccount.php index d01751e239..f06a19255a 100644 --- a/includes/specials/SpecialCreateAccount.php +++ b/includes/specials/SpecialCreateAccount.php @@ -129,7 +129,7 @@ class SpecialCreateAccount extends LoginSignupSpecialPage { # Run any hooks; display injected HTML $injected_html = ''; $welcome_creation_msg = 'welcomecreation-msg'; - Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html ] ); + Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html, $direct ] ); /** * Let any extensions change what message is shown. diff --git a/includes/specials/SpecialUserLogin.php b/includes/specials/SpecialUserLogin.php index db20d8771f..21f565902b 100644 --- a/includes/specials/SpecialUserLogin.php +++ b/includes/specials/SpecialUserLogin.php @@ -124,7 +124,7 @@ class SpecialUserLogin extends LoginSignupSpecialPage { # Run any hooks; display injected HTML if any, else redirect $injected_html = ''; - Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html ] ); + Hooks::run( 'UserLoginComplete', [ &$user, &$injected_html, $direct ] ); if ( $injected_html !== '' || $extraMessages ) { $this->showSuccessPage( 'success', $this->msg( 'loginsuccesstitle' ), diff --git a/includes/specials/pre-authmanager/SpecialUserlogin.php b/includes/specials/pre-authmanager/SpecialUserlogin.php index 951cb525d9..09132f27ae 100644 --- a/includes/specials/pre-authmanager/SpecialUserlogin.php +++ b/includes/specials/pre-authmanager/SpecialUserlogin.php @@ -1262,7 +1262,8 @@ class LoginFormPreAuthManager extends SpecialPage { # Run any hooks; display injected HTML if any, else redirect $currentUser = $this->getUser(); $injected_html = ''; - Hooks::run( 'UserLoginComplete', [ &$currentUser, &$injected_html ] ); + $direct = RequestContext::getMain()->getRequest()->wasPosted(); + Hooks::run( 'UserLoginComplete', [ &$currentUser, &$injected_html, $direct ] ); if ( $injected_html !== '' ) { $this->displaySuccessfulAction( 'success', $this->msg( 'loginsuccesstitle' ), @@ -1283,8 +1284,9 @@ class LoginFormPreAuthManager extends SpecialPage { $currentUser = $this->getUser(); $injected_html = ''; $welcome_creation_msg = 'welcomecreation-msg'; + $direct = RequestContext::getMain()->getRequest()->wasPosted(); - Hooks::run( 'UserLoginComplete', [ &$currentUser, &$injected_html ] ); + Hooks::run( 'UserLoginComplete', [ &$currentUser, &$injected_html, $direct ] ); /** * Let any extensions change what message is shown. -- 2.20.1