Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/255799
Change subject: Add and use CentralAuthUser::getMasterInstance() method ...................................................................... Add and use CentralAuthUser::getMasterInstance() method * Make onAbortLogin use this method * Converted onAbortNewAccount to using this too * Fix a few IDEA errors too Change-Id: Iac63c577d2dfabb773b5a219185f4a8d90fc9257 --- M includes/CentralAuthHooks.php M includes/CentralAuthUser.php 2 files changed, 32 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth refs/changes/99/255799/1 diff --git a/includes/CentralAuthHooks.php b/includes/CentralAuthHooks.php index 3c8fcfd..926e84e 100644 --- a/includes/CentralAuthHooks.php +++ b/includes/CentralAuthHooks.php @@ -443,11 +443,11 @@ * @param $abortError * @return bool */ - static function onAbortNewAccount( $user, &$abortError ) { + static function onAbortNewAccount( User $user, &$abortError ) { global $wgCentralAuthPreventUnattached; global $wgCentralAuthEnableGlobalRenameRequest; - $centralUser = new CentralAuthUser( $user->getName(), CentralAuthUser::READ_LATEST ); + $centralUser = CentralAuthUser::getMasterInstance( $user ); if ( $centralUser->exists() || $centralUser->renameInProgressOn( wfWikiID() ) ) { $abortError = wfMessage( 'centralauth-account-exists' )->text(); return false; @@ -498,7 +498,7 @@ * @throws Exception */ static function onAbortLogin( User $user, $pass, &$retval, &$msg ) { - $centralUser = CentralAuthUser::getInstance( $user ); + $centralUser = CentralAuthUser::getMasterInstance( $user ); // Since logins are rare, check the actual DB $rename = $centralUser->renameInProgressOn( wfWikiID() ); @@ -579,8 +579,8 @@ /** * Show a nicer error when the user account does not exist on the local wiki, but * does exist globally - * @param $users Array - * @param $data Array + * @param $users User[] + * @param $data array * @param $abortError String * @return bool */ @@ -608,7 +608,7 @@ * @return bool */ static function onUserLoginComplete( &$user, &$inject_html ) { - global $wgCentralAuthLoginWiki, $wgCentralAuthCookies; + global $wgCentralAuthCookies; global $wgCentralAuthCheckSULMigration; if ( $wgCentralAuthCheckSULMigration && @@ -980,7 +980,7 @@ * @param $userName * @return bool */ - static function onUserLogoutComplete( &$user, &$inject_html, $userName ) { + static function onUserLogoutComplete( User &$user, &$inject_html, $userName ) { global $wgCentralAuthCookies, $wgCentralAuthLoginWiki, $wgCentralAuthAutoLoginWikis; if ( !$wgCentralAuthCookies ) { @@ -1356,9 +1356,10 @@ } /** - * @param $id user_id integer + * @param integer $id User ID * @param User $user * @param SpecialPage $sp + * @return bool */ static function onSpecialContributionsBeforeMainOutput( $id, User $user, SpecialPage $sp ) { if ( $user->isAnon() ) { @@ -1910,6 +1911,7 @@ * @param array &$namesById array of userIds=>names to associate * @param bool|User $audience show hidden names based on this user, or false for public * @param string $wgMWOAuthSharedUserSource the authoritative extension + * @return bool */ public static function onOAuthGetUserNamesFromCentralIds( $wgMWOAuthCentralWiki, &$namesById, $audience, $wgMWOAuthSharedUserSource ) { if ( $wgMWOAuthSharedUserSource !== 'CentralAuth' ) { @@ -1944,6 +1946,8 @@ * @param string $wgMWOAuthCentralWiki * @param User &$user the loca user object * @param string $wgMWOAuthSharedUserSource the authoritative extension + * @return bool + * @throws Exception */ public static function onOAuthGetLocalUserFromCentralId( $userId, $wgMWOAuthCentralWiki, &$user, $wgMWOAuthSharedUserSource ) { if ( $wgMWOAuthSharedUserSource !== 'CentralAuth' ) { @@ -1992,6 +1996,7 @@ * @param string $wgMWOAuthCentralWiki * @param int &$id the user_id of the matching name on the central wiki * @param string $wgMWOAuthSharedUserSource the authoritative extension + * @return bool */ public static function onOAuthGetCentralIdFromLocalUser( $user, $wgMWOAuthCentralWiki, &$id, $wgMWOAuthSharedUserSource ) { if ( $wgMWOAuthSharedUserSource !== 'CentralAuth' ) { @@ -2020,6 +2025,7 @@ * @param string $wgMWOAuthCentralWiki * @param int &$id the user_id of the matching name on the central wiki * @param string $wgMWOAuthSharedUserSource the authoritative extension + * @return bool */ public static function onOAuthGetCentralIdFromUserName( $username, $wgMWOAuthCentralWiki, &$id, $wgMWOAuthSharedUserSource ) { if ( $wgMWOAuthSharedUserSource !== 'CentralAuth' ) { @@ -2140,6 +2146,7 @@ * @param string $returnTo The page to return to * @param array $returnToQuery Url parameters * @param string $type Type of login redirect + * @return bool */ public static function onPostLoginRedirect( &$returnTo, &$returnToQuery, &$type @@ -2218,6 +2225,8 @@ * a user. * @param User $user * @param array $effectivePolicy + * @return bool + * @throws Exception */ public static function onPasswordPoliciesForUser( User $user, array &$effectivePolicy ) { global $wgCentralAuthGlobalPasswordPolicies; diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php index cdb3911..bf99d30 100644 --- a/includes/CentralAuthUser.php +++ b/includes/CentralAuthUser.php @@ -84,6 +84,21 @@ } /** + * Create a CentralAuthUser object corresponding to the supplied User, and + * cache it in the User object. This object will use DB_MASTER. + * @param User $user + * + * @return CentralAuthUser + * @since 1.27 + */ + static function getMasterInstance( User $user ) { + if ( !isset( $user->centralAuthMasterObj ) ) { + $user->centralAuthMasterObj = new self( $user->getName(), self::READ_LATEST ); + } + return $user->centralAuthMasterObj; + } + + /** * Gets a master (read/write) database connection to the CentralAuth database * * @return DatabaseBase -- To view, visit https://gerrit.wikimedia.org/r/255799 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iac63c577d2dfabb773b5a219185f4a8d90fc9257 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CentralAuth Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits