Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/274043
Change subject: Avoid using "new CentralAuthUser" since it avoids the cache ...................................................................... Avoid using "new CentralAuthUser" since it avoids the cache In the past, caching of CentralAuthUser was on the User object, so anything that lacked a User object couldn't take advantage of caching. Others needed to avoid the cache if they weren't sure the User object wasn't going to be reset to anonymous or to a different name. This was changed in I4199f56 to use a centralized cache keyed on the username and independent of the specific User object. So we can now make use of the caching in all the places where it was avoided before. Maintenance callers and unit tests have not been updated in this patch. Change-Id: Idc87313499c04b894308d4d14a578cc683b477f4 (cherry picked from commit c205530f28294c810fab617ad76842526b8825ff) --- M includes/CentralAuthGroupMembershipProxy.php M includes/CentralAuthHooks.php M includes/CentralAuthPlugin.php M includes/CentralAuthUser.php M includes/GlobalRename/GlobalRenameRequest.php M includes/LocalRenameJob/LocalRenameJob.php M includes/LocalRenameJob/LocalRenameUserJob.php M includes/LocalRenameJob/LocalUserMergeJob.php M includes/SuppressUserJob.php M includes/api/ApiDeleteGlobalAccount.php M includes/api/ApiQueryGlobalUserInfo.php M includes/api/ApiSetGlobalAccountStatus.php M includes/session/CentralAuthSessionCompat.php M includes/session/CentralAuthSessionProvider.php M includes/session/CentralAuthTokenSessionProvider.php M includes/specials/SpecialCentralAuth.php M includes/specials/SpecialCentralAutoLogin.php M includes/specials/SpecialCentralLogin.php M includes/specials/SpecialGlobalGroupPermissions.php M includes/specials/SpecialGlobalRenameProgress.php M includes/specials/SpecialGlobalRenameQueue.php M includes/specials/SpecialGlobalRenameUser.php M includes/specials/SpecialGlobalUserMerge.php M includes/specials/SpecialMergeAccount.php M includes/specials/SpecialMultiLock.php 25 files changed, 97 insertions(+), 86 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth refs/changes/43/274043/1 diff --git a/includes/CentralAuthGroupMembershipProxy.php b/includes/CentralAuthGroupMembershipProxy.php index 793d96f..d19fe73 100644 --- a/includes/CentralAuthGroupMembershipProxy.php +++ b/includes/CentralAuthGroupMembershipProxy.php @@ -37,7 +37,7 @@ */ public static function newFromName( $name ) { $name = User::getCanonicalName( $name ); - $globalUser = new CentralAuthUser( $name ); + $globalUser = CentralAuthUser::getInstanceByName( $name ); return $globalUser->exists() ? new CentralAuthGroupMembershipProxy( $globalUser ) : null; } diff --git a/includes/CentralAuthHooks.php b/includes/CentralAuthHooks.php index 83fdfb9..6e8d9d0 100644 --- a/includes/CentralAuthHooks.php +++ b/includes/CentralAuthHooks.php @@ -376,7 +376,7 @@ // to check one username. $newCAUser = $rename[1] === $user->getName() ? $centralUser - : new CentralAuthUser( $rename[0] ); + : CentralAuthUser::getInstanceByName( $rename[0] ); if ( $newCAUser->isAttached() ) { // If there is an account using that name that exists on this wiki @@ -424,7 +424,7 @@ // If the local and global accounts don't exist, // otherwise wgAuth will handle those. $testName = $user->getName() . '~' . wfWikiID(); - $test = new CentralAuthUser( $testName ); + $test = CentralAuthUser::getInstanceByName( $testName ); if ( $test->exists() && $test->isAttached() ) { $msg = array( 'centralauth-abortlogin-renamed', $testName ); return false; @@ -758,7 +758,7 @@ * @throws ErrorPageError */ static function onRenameUserWarning( $oldName, $newName, &$warnings ) { - $oldCentral = new CentralAuthUser( $oldName, CentralAuthUser::READ_LATEST ); + $oldCentral = CentralAuthUser::getMasterInstanceByName( $oldName ); if ( $oldCentral->exists() && $oldCentral->isAttached() ) { $warnings[] = array( 'centralauth-renameuser-merged', $oldName, $newName ); } @@ -766,7 +766,7 @@ $warnings[] = array( 'centralauth-renameuser-global-inprogress', $oldName ); } - $newCentral = new CentralAuthUser( $newName, CentralAuthUser::READ_LATEST ); + $newCentral = CentralAuthUser::getMasterInstanceByName( $newName ); if ( $newCentral->exists() && !$newCentral->isAttached() ) { $warnings[] = array( 'centralauth-renameuser-reserved', $oldName, $newName ); } @@ -787,7 +787,7 @@ * @return bool */ static function onRenameUserPreRename( $uid, $oldName, $newName ) { - $oldCentral = new CentralAuthUser( $oldName, CentralAuthUser::READ_LATEST ); + $oldCentral = CentralAuthUser::getMasterInstanceByName( $oldName ); // If we're doing a global rename, the account will not get unattached // because the old account no longer exists if ( $oldCentral->exists() && $oldCentral->isAttached() ) { @@ -804,8 +804,8 @@ * @return bool */ static function onRenameUserComplete( $userId, $oldName, $newName ) { - $oldCentral = new CentralAuthUser( $oldName, CentralAuthUser::READ_LATEST ); - $newCentral = new CentralAuthUser( $newName, CentralAuthUser::READ_LATEST ); + $oldCentral = CentralAuthUser::getMasterInstanceByName( $oldName ); + $newCentral = CentralAuthUser::getMasterInstanceByName( $newName ); if ( $newCentral->exists() && $oldCentral->renameInProgressOn( wfWikiID() ) ) { // This is a global rename, just update the row. @@ -1218,7 +1218,7 @@ return true; // Return if it is an IP as only usernames can be locked. } - $caUser = new CentralAuthUser( $user ); + $caUser = CentralAuthUser::getInstanceByName( $user ); if ( $caUser->isLocked() && in_array( wfWikiID(), $caUser->listAttached() ) ) { $msg[] = Html::rawElement( 'span', @@ -1316,7 +1316,7 @@ __METHOD__ ); $namesById[$userid] = $name; - $centralUser = new CentralAuthUser( $name ); + $centralUser = CentralAuthUser::getInstanceByName( $name ); if ( $centralUser->getHiddenLevel() !== CentralAuthUser::HIDDEN_NONE && !( $audience instanceof User && $audience->isAllowed( 'centralauth-oversight' ) ) @@ -1357,7 +1357,7 @@ return false; } - $centralUser = new CentralAuthUser( $user_name ); + $centralUser = CentralAuthUser::getInstanceByName( $user_name ); if ( $centralUser->isLocked() || !$centralUser->isAttached() @@ -1421,7 +1421,7 @@ // We aren't supposed to handle this return true; } - $centralUser = new CentralAuthUser( $username ); + $centralUser = CentralAuthUser::getInstanceByName( $username ); if ( $centralUser->getId() == 0 ) { $id = false; return false; @@ -1672,7 +1672,7 @@ public static function onSessionCheckInfo( &$reason, $info ) { $name = $info->getUserInfo()->getName(); if ( $name !== null ) { - $centralUser = new CentralAuthUser( $name ); + $centralUser = CentralAuthUser::getInstanceByName( $name ); if ( $centralUser->renameInProgress() ) { $reason = 'CentralAuth rename in progress'; return false; diff --git a/includes/CentralAuthPlugin.php b/includes/CentralAuthPlugin.php index b6eb406..e8a959f 100644 --- a/includes/CentralAuthPlugin.php +++ b/includes/CentralAuthPlugin.php @@ -26,7 +26,7 @@ * @public */ function userExists( $username ) { - $central = new CentralAuthUser( $username ); + $central = CentralAuthUser::getInstanceByName( $username ); return $central->exists(); } @@ -46,7 +46,7 @@ global $wgCentralAuthAutoMigrateNonGlobalAccounts; global $wgCentralAuthStrict; - $central = new CentralAuthUser( $username ); + $central = CentralAuthUser::getInstanceByName( $username ); $passwordMatch = self::checkPassword( $central, $password ); if ( !$passwordMatch && $wgCentralAuthCheckSULMigration ) { @@ -54,7 +54,7 @@ // collision during a forced migration to central auth accounts. $renamedUsername = User::getCanonicalName( $username . '~' . str_replace( '_', '-', wfWikiID() ) ); if ( $renamedUsername !== false ) { - $renamed = new CentralAuthUser( $renamedUsername ); + $renamed = CentralAuthUser::getInstanceByName( $renamedUsername ); if ( $renamed->getId() ) { wfDebugLog( 'CentralAuth', @@ -177,7 +177,7 @@ // Authenticate locally if the global account doesn't exist, // or the local account isn't attached // If strict is on, local authentication won't work at all - $central = new CentralAuthUser( $username ); + $central = CentralAuthUser::getInstanceByName( $username ); return $central->exists() && $central->isAttached(); } diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php index cec761d..e1ceb22 100644 --- a/includes/CentralAuthUser.php +++ b/includes/CentralAuthUser.php @@ -61,6 +61,8 @@ const HIDE_CONTRIBLIMIT = 1000; /** + * @note Don't call this directly. Use self::getInstanceByName() or + * self::getMasterInstanceByName() instead. * @param string $username * @param integer $flags Supports CentralAuthUser::READ_LATEST to use the master DB */ @@ -71,6 +73,7 @@ $this->mFromMaster = true; } } + /** * Fetch the cache * @return MapCacheLRU @@ -89,7 +92,16 @@ * @param CentralAuthUser $caUser */ public static function setInstance( User $user, CentralAuthUser $caUser ) { - self::getUserCache()->set( $user->getName(), $caUser ); + self::setInstanceByName( $user->getName(), $caUser ); + } + + /** + * Explicitly set the (cached) CentralAuthUser object corresponding to the supplied User. + * @param string $username Must be validated and canonicalized by the caller + * @param CentralAuthUser $caUser + */ + public static function setInstanceByName( $username, CentralAuthUser $caUser ) { + self::getUserCache()->set( $username, $caUser ); } /** @@ -98,11 +110,20 @@ * @return CentralAuthUser */ public static function getInstance( User $user ) { + return self::getInstanceByName( $user->getName() ); + } + + /** + * Create a (cached) CentralAuthUser object corresponding to the supplied user. + * @param string $username Must be validated and canonicalized by the caller + * @return CentralAuthUser + */ + public static function getInstanceByName( $username ) { $cache = self::getUserCache(); - $ret = $cache->get( $user->getName() ); + $ret = $cache->get( $username ); if ( !$ret ) { - $ret = new self( $user->getName() ); - $cache->set( $user->getName(), $ret ); + $ret = new self( $username ); + $cache->set( $username, $ret ); } return $ret; } @@ -115,15 +136,25 @@ * @since 1.27 */ public static function getMasterInstance( User $user ) { + return self::getMasterInstanceByName( $user->getName() ); + } + + /** + * Create a (cached) CentralAuthUser object corresponding to the supplied User. + * This object will use DB_MASTER. + * @param string $username Must be validated and canonicalized by the caller + * @return CentralAuthUser + * @since 1.27 + */ + public static function getMasterInstanceByName( $username ) { $cache = self::getUserCache(); - $ret = $cache->get( $user->getName() ); + $ret = $cache->get( $username ); if ( !$ret || !$ret->mFromMaster ) { - $ret = new self( $user->getName(), self::READ_LATEST ); - $cache->set( $user->getName(), $ret ); + $ret = new self( $username, self::READ_LATEST ); + $cache->set( $username, $ret ); } return $ret; } - /** * @deprecated use CentralAuthUtils instead @@ -243,7 +274,7 @@ ); if ( $name ) { - return new CentralAuthUser( $name ); + return CentralAuthUser::getInstanceByName( $name ); } else { return false; } diff --git a/includes/GlobalRename/GlobalRenameRequest.php b/includes/GlobalRename/GlobalRenameRequest.php index e3641f0..e096984 100644 --- a/includes/GlobalRename/GlobalRenameRequest.php +++ b/includes/GlobalRename/GlobalRenameRequest.php @@ -428,7 +428,7 @@ // New user creation checks against local wiki only using an API // request, but we need to check against te central user table instead - $centralUser = new CentralAuthUser( $safe, CentralAuthUser::READ_LATEST ); + $centralUser = CentralAuthUser::getMasterInstanceByName( $safe ); if ( $centralUser->exists() || $centralUser->listUnattached() ) { $status->fatal( 'globalrenamerequest-newname-err-taken' ); return $status; diff --git a/includes/LocalRenameJob/LocalRenameJob.php b/includes/LocalRenameJob/LocalRenameJob.php index ff3638f..b915c54 100644 --- a/includes/LocalRenameJob/LocalRenameJob.php +++ b/includes/LocalRenameJob/LocalRenameJob.php @@ -53,7 +53,7 @@ if ( !User::isUsableName( $user->getName() ) ) { return $user; } - $caUser = new CentralAuthUser( $user->getName(), CentralAuthUser::READ_LATEST ); + $caUser = CentralAuthUser::getMasterInstance( $user ); // Race condition where the renamer isn't attached here, but // someone creates an account in the meantime and then bad // stuff could happen... @@ -77,7 +77,7 @@ protected function done() { $this->renameuserStatus->done( wfWikiID() ); - $caNew = new CentralAuthUser( $this->params['to'] ); + $caNew = CentralAuthUser::getInstanceByName( $this->params['to'] ); $caNew->quickInvalidateCache(); } diff --git a/includes/LocalRenameJob/LocalRenameUserJob.php b/includes/LocalRenameJob/LocalRenameUserJob.php index 649481d..85f3fbf 100644 --- a/includes/LocalRenameJob/LocalRenameUserJob.php +++ b/includes/LocalRenameJob/LocalRenameUserJob.php @@ -76,7 +76,7 @@ private function promoteToGlobal() { $newName = $this->params['to']; - $caUser = new CentralAuthUser( $newName, CentralAuthUser::READ_LATEST ); + $caUser = CentralAuthUser::getMasterInstanceByName( $newName ); $status = $caUser->promoteToGlobal( wfWikiID() ); if ( !$status->isOK() ) { if ( $status->hasMessage( 'promote-not-on-wiki' ) ) { @@ -142,7 +142,7 @@ protected function done() { parent::done(); - $caOld = new CentralAuthUser( $this->params['from'] ); + $caOld = CentralAuthUser::getInstanceByName( $this->params['from'] ); $caOld->quickInvalidateCache(); } } diff --git a/includes/LocalRenameJob/LocalUserMergeJob.php b/includes/LocalRenameJob/LocalUserMergeJob.php index e1547fd..5111870 100755 --- a/includes/LocalRenameJob/LocalUserMergeJob.php +++ b/includes/LocalRenameJob/LocalUserMergeJob.php @@ -45,7 +45,7 @@ protected function done() { parent::done(); foreach ( $this->params['from'] as $from ) { - $caOld = new CentralAuthUser( $from ); + $caOld = CentralAuthUser::getInstanceByName( $from ); $caOld->quickInvalidateCache(); } } diff --git a/includes/SuppressUserJob.php b/includes/SuppressUserJob.php index 20160d6..d3844bb 100644 --- a/includes/SuppressUserJob.php +++ b/includes/SuppressUserJob.php @@ -27,7 +27,7 @@ $wikis = $this->params['wikis']; $suppress = $this->params['suppress']; $reason = $this->params['reason']; - $user = new CentralAuthUser( $username, CentralAuthUser::READ_LATEST ); + $user = CentralAuthUser::getMasterInstanceByName( $username ); if ( !$user->exists() ) { wfDebugLog( 'suppressjob', "Requested to suppress non-existent user {$username} by {$by}." ); } diff --git a/includes/api/ApiDeleteGlobalAccount.php b/includes/api/ApiDeleteGlobalAccount.php index a3003f4..9efc399 100644 --- a/includes/api/ApiDeleteGlobalAccount.php +++ b/includes/api/ApiDeleteGlobalAccount.php @@ -37,7 +37,7 @@ $params = $this->extractRequestParams(); - $globalUser = new CentralAuthUser( $params['user'], CentralAuthUser::READ_LATEST ); + $globalUser = CentralAuthUser::getMasterInstanceByName( $params['user'] ); if ( !$globalUser->exists() ) { $this->dieUsageMsg( array( 'nosuchuser', $globalUser->getName() ) ); } elseif ( $globalUser->isOversighted() && !$this->getUser()->isAllowed( 'centralauth-oversight' ) ) { diff --git a/includes/api/ApiQueryGlobalUserInfo.php b/includes/api/ApiQueryGlobalUserInfo.php index 7263210..fbf98d8 100644 --- a/includes/api/ApiQueryGlobalUserInfo.php +++ b/includes/api/ApiQueryGlobalUserInfo.php @@ -39,7 +39,7 @@ if ( is_null( $params['user'] ) ) { $params['user'] = $this->getUser()->getName(); } - $user = new CentralAuthUser( $params['user'] ); + $user = CentralAuthUser::getInstanceByName( $params['user'] ); // Add basic info $result = $this->getResult(); diff --git a/includes/api/ApiSetGlobalAccountStatus.php b/includes/api/ApiSetGlobalAccountStatus.php index 0767cfd..90defac 100644 --- a/includes/api/ApiSetGlobalAccountStatus.php +++ b/includes/api/ApiSetGlobalAccountStatus.php @@ -31,10 +31,7 @@ class ApiSetGlobalAccountStatus extends ApiBase { /* Heavily based on code from SpecialCentralAuth::doSubmit */ public function execute() { - $globalUser = new CentralAuthUser( - $this->getParameter( 'user' ), - CentralAuthUser::READ_LATEST - ); + $globalUser = CentralAuthUser::getMasterInstanceByName( $this->getParameter( 'user' ) ); if ( !$this->getUser()->isAllowed( 'centralauth-lock' ) ) { $this->dieUsageMsg( array( 'badaccess-groups' ) ); } elseif ( !$globalUser->exists() ) { diff --git a/includes/session/CentralAuthSessionCompat.php b/includes/session/CentralAuthSessionCompat.php index 6d97ef6..87e1fc0 100644 --- a/includes/session/CentralAuthSessionCompat.php +++ b/includes/session/CentralAuthSessionCompat.php @@ -237,7 +237,7 @@ } // Try the central user - $centralUser = new CentralAuthUser( $userName ); + $centralUser = CentralAuthUser::getInstanceByName( $userName ); if ( $centralUser->authenticateWithToken( $token ) != 'ok' ) { wfDebug( __METHOD__ . ": token mismatch\n" ); return null; @@ -343,8 +343,7 @@ if ( $name ) { // Log the user out if they're being renamed. We'll give them an error message // when they try logging in - // Also don't use CentralAuthUser::getInstance, we don't want to cache it on failure. - $centralUser = new CentralAuthUser( $name ); + $centralUser = CentralAuthUser::getInstanceByName( $name ); if ( $centralUser->renameInProgress() ) { $result = false; return false; @@ -403,8 +402,7 @@ } // Try the central user - // Don't use CentralAuthUser::getInstance, we don't want to cache it on failure. - $centralUser = new CentralAuthUser( $userName ); + $centralUser = CentralAuthUser::getInstanceByName( $userName ); // Log the user out if they're being renamed if ( $centralUser->renameInProgress() ) { diff --git a/includes/session/CentralAuthSessionProvider.php b/includes/session/CentralAuthSessionProvider.php index f0fb5b7..ac36536 100644 --- a/includes/session/CentralAuthSessionProvider.php +++ b/includes/session/CentralAuthSessionProvider.php @@ -152,8 +152,7 @@ } // Try the central user - // Don't use CentralAuthUser::getInstance, we don't want to cache it on failure. - $centralUser = new CentralAuthUser( $userName ); + $centralUser = CentralAuthUser::getInstanceByName( $userName ); // Skip if they're being renamed if ( $centralUser->renameInProgress() ) { @@ -198,7 +197,7 @@ if ( isset( $metadata['CentralAuthSource'] ) ) { $name = $info->getUserInfo()->getName(); if ( $name !== null ) { - $centralUser = new CentralAuthUser( $name ); + $centralUser = CentralAuthUser::getInstanceByName( $name ); if ( $centralUser->exists() && ( $centralUser->isAttached() || !User::idFromName( $name, User::READ_LATEST ) ) ) { @@ -369,7 +368,7 @@ return; } - $centralUser = new CentralAuthUser( $username ); + $centralUser = CentralAuthUser::getInstanceByName( $username ); if ( !$centralUser->exists() ) { return; } diff --git a/includes/session/CentralAuthTokenSessionProvider.php b/includes/session/CentralAuthTokenSessionProvider.php index f727447..d3da64e 100644 --- a/includes/session/CentralAuthTokenSessionProvider.php +++ b/includes/session/CentralAuthTokenSessionProvider.php @@ -89,8 +89,7 @@ } // Try the central user - // Don't use CentralAuthUser::getInstance, we don't want to cache it on failure. - $centralUser = new CentralAuthUser( $userName ); + $centralUser = CentralAuthUser::getInstanceByName( $userName ); // Skip if they're being renamed if ( $centralUser->renameInProgress() ) { @@ -155,7 +154,7 @@ return; } - $centralUser = new CentralAuthUser( $username ); + $centralUser = CentralAuthUser::getInstanceByName( $username ); if ( !$centralUser->exists() ) { return; } diff --git a/includes/specials/SpecialCentralAuth.php b/includes/specials/SpecialCentralAuth.php index e757df1..5b3b8cb 100644 --- a/includes/specials/SpecialCentralAuth.php +++ b/includes/specials/SpecialCentralAuth.php @@ -81,10 +81,9 @@ )->plain() ) ); - $globalUser = new CentralAuthUser( - $this->mUserName, - $this->getRequest()->wasPosted() ? CentralAuthUser::READ_LATEST : 0 - ); + $globalUser = $this->getRequest()->wasPosted() + ? CentralAuthUser::getMasterInstanceByName( $this->mUserName ) + : CentralAuthUser::getInstanceByName( $this->mUserName ); $this->mGlobalUser = $globalUser; if ( ( $globalUser->isOversighted() || $globalUser->isHidden() ) && !$this->mCanOversight ) { diff --git a/includes/specials/SpecialCentralAutoLogin.php b/includes/specials/SpecialCentralAutoLogin.php index daa1012..1b90ce0 100644 --- a/includes/specials/SpecialCentralAutoLogin.php +++ b/includes/specials/SpecialCentralAutoLogin.php @@ -430,7 +430,7 @@ // Load and check CentralAuthUser. But don't check if it's // attached, because then if the user is missing en.site they // won't be auto logged in to any of the non-en versions either. - $centralUser = new CentralAuthUser( $memcData['userName'] ); + $centralUser = CentralAuthUser::getInstanceByName( $memcData['userName'] ); if ( !$centralUser->getId() || $centralUser->getId() != $memcData['gu_id'] ) { $msg = "Wrong user: expected {$memcData['gu_id']}, got {$centralUser->getId()}"; wfDebug( __METHOD__ . ": $msg\n" ); diff --git a/includes/specials/SpecialCentralLogin.php b/includes/specials/SpecialCentralLogin.php index 3d61abb..45a8ad8 100644 --- a/includes/specials/SpecialCentralLogin.php +++ b/includes/specials/SpecialCentralLogin.php @@ -74,7 +74,7 @@ return; } - $centralUser = new CentralAuthUser( $info['name'] ); + $centralUser = CentralAuthUser::getInstanceByName( $info['name'] ); if ( !$centralUser->exists() ) { // sanity throw new Exception( "Global user '{$info['name']}' does not exist." ); } elseif ( $centralUser->getId() !== $info['guid'] ) { // sanity diff --git a/includes/specials/SpecialGlobalGroupPermissions.php b/includes/specials/SpecialGlobalGroupPermissions.php index 05fe11a..7e3c4b0 100644 --- a/includes/specials/SpecialGlobalGroupPermissions.php +++ b/includes/specials/SpecialGlobalGroupPermissions.php @@ -534,7 +534,7 @@ // Invalidate their rights cache. foreach ( $res as $row ) { // Use READ_LATEST for paranoia, though the DB isn't used in this method - $cu = new CentralAuthUser( $row->gu_name, CentralAuthUser::READ_LATEST ); + $cu = CentralAuthUser::getMasterInstanceByName( $row->gu_name ); $cu->quickInvalidateCache(); } } diff --git a/includes/specials/SpecialGlobalRenameProgress.php b/includes/specials/SpecialGlobalRenameProgress.php index c6697c7..ee7c2c8 100644 --- a/includes/specials/SpecialGlobalRenameProgress.php +++ b/includes/specials/SpecialGlobalRenameProgress.php @@ -45,7 +45,7 @@ * @param string $name */ function checkCachePurge( $name ) { - $ca = new CentralAuthUser( $name ); + $ca = CentralAuthUser::getInstanceByName( $name ); if ( $ca->renameInProgress() ) { $ca->quickInvalidateCache(); } @@ -120,7 +120,7 @@ $this->getForm()->displayForm( false ); // $newname will always be defined since we check // for 0 result rows above - $caUser = new CentralAuthUser( $newName, CentralAuthUser::READ_LATEST ); + $caUser = CentralAuthUser::getMasterInstanceByName( $newName ); $attached = $caUser->listAttached(); foreach ( $attached as $wiki ) { // If it's not in the db table, and there is diff --git a/includes/specials/SpecialGlobalRenameQueue.php b/includes/specials/SpecialGlobalRenameQueue.php index 693230a..af49af9 100644 --- a/includes/specials/SpecialGlobalRenameQueue.php +++ b/includes/specials/SpecialGlobalRenameQueue.php @@ -376,7 +376,7 @@ $form->setId( 'mw-globalrenamequeue-request' ); if ( $req->userIsGlobal() ) { - $globalUser = new CentralAuthUser( $req->getName() ); + $globalUser = CentralAuthUser::getInstanceByName( $req->getName() ); $homeWiki = $globalUser->getHomeWiki(); $infoMsgKey = 'globalrenamequeue-request-userinfo-global'; } else { diff --git a/includes/specials/SpecialGlobalRenameUser.php b/includes/specials/SpecialGlobalRenameUser.php index fc1df10..29a56e9 100644 --- a/includes/specials/SpecialGlobalRenameUser.php +++ b/includes/specials/SpecialGlobalRenameUser.php @@ -96,7 +96,7 @@ // Ask for confirmation if the user has more than 50k edits globally $oldName = trim( $this->getRequest()->getText( 'oldname' ) ); if ( $oldName !== '' ) { - $caUser = new CentralAuthUser( $oldName ); + $caUser = CentralAuthUser::getInstanceByName( $oldName ); if ( $caUser->getGlobalEditCount() > self::EDITCOUNT_THRESHOLD ) { $fields['allowhigheditcount'] = array( 'id' => 'mw-globalrenameuser-allowhigheditcount', @@ -180,7 +180,7 @@ // Not a conflict since the old usage will go away continue; } - $ca = new CentralAuthUser( $name, CentralAuthUser::READ_LATEST ); + $ca = CentralAuthUser::getMasterInstanceByName( $name ); if ( $ca->isHidden() ) { $display[] = $this->msg( 'centralauth-rename-conflict-hidden' )->text(); } else { @@ -232,7 +232,7 @@ function onSuccess() { $lang = $this->getLanguage(); - $caUser = new CentralAuthUser( $this->newUsername ); + $caUser = CentralAuthUser::getInstanceByName( $this->newUsername ); $wikiList = $lang->commaList( $caUser->listAttached() ); $msg = $this->msg( 'centralauth-rename-queued' ) diff --git a/includes/specials/SpecialGlobalUserMerge.php b/includes/specials/SpecialGlobalUserMerge.php index 7d76d8a..d72f72b 100644 --- a/includes/specials/SpecialGlobalUserMerge.php +++ b/includes/specials/SpecialGlobalUserMerge.php @@ -94,7 +94,7 @@ return $this->msg( 'centralauth-usermerge-noself' )->escaped(); } - $caUser = new CentralAuthUser( $name, CentralAuthUser::READ_LATEST ); + $caUser = CentralAuthUser::getMasterInstanceByName( $name ); if ( !$caUser->exists() ) { return $this->msg( 'centralauth-usermerge-invalid', $name )->escaped(); } @@ -149,7 +149,7 @@ // DWIM and ignore it continue; } - $caUser = new CentralAuthUser( $name, CentralAuthUser::READ_LATEST ); + $caUser = CentralAuthUser::getMasterInstanceByName( $name ); $this->oldCAUsers[] = $caUser; } } diff --git a/includes/specials/SpecialMergeAccount.php b/includes/specials/SpecialMergeAccount.php index 42fea78..9149db7 100644 --- a/includes/specials/SpecialMergeAccount.php +++ b/includes/specials/SpecialMergeAccount.php @@ -97,7 +97,7 @@ return; } - $globalUser = new CentralAuthUser( $this->mUserName ); + $globalUser = CentralAuthUser::getInstanceByName( $this->mUserName ); if ( $globalUser->exists() ) { $this->showFormForExistingUsers( $globalUser ); } else { @@ -203,10 +203,7 @@ function doDryRunMerge() { global $wgCentralAuthDryRun; - $globalUser = new CentralAuthUser( - $this->getUser()->getName(), - CentralAuthUser::READ_LATEST - ); + $globalUser = CentralAuthUser::getMasterInstance( $this->getUser() ); if ( $globalUser->exists() ) { // Already exists - race condition @@ -266,10 +263,7 @@ function doInitialMerge() { global $wgCentralAuthDryRun; - $globalUser = new CentralAuthUser( - $this->getUser()->getName(), - CentralAuthUser::READ_LATEST - ); + $globalUser = CentralAuthUser::getMasterInstance( $this->getUser() ); if ( $wgCentralAuthDryRun ) { $this->dryRunError(); @@ -297,10 +291,7 @@ function doCleanupMerge() { global $wgCentralAuthDryRun; - $globalUser = new CentralAuthUser( - $this->getUser()->getName(), - CentralAuthUser::READ_LATEST - ); + $globalUser = CentralAuthUser::getMasterInstance( $this->getUser() ); if ( !$globalUser->exists() ) { throw new Exception( "User doesn't exist -- race condition?" ); @@ -334,10 +325,7 @@ function doAttachMerge() { global $wgCentralAuthDryRun; - $globalUser = new CentralAuthUser( - $this->getUser()->getName(), - CentralAuthUser::READ_LATEST - ); + $globalUser = CentralAuthUser::getMasterInstance( $this->getUser() ); if ( !$globalUser->exists() ) { throw new Exception( "User doesn't exist -- race condition?" ); @@ -387,7 +375,7 @@ } function showCleanupForm() { - $globalUser = new CentralAuthUser( $this->getUser()->getName() ); + $globalUser = CentralAuthUser::getInstance( $this->getUser() ); $merged = $globalUser->listAttached(); $remainder = $globalUser->listUnattached(); @@ -395,7 +383,7 @@ } function showAttachForm() { - $globalUser = new CentralAuthUser( $this->getUser()->getName() ); + $globalUser = CentralAuthUser::getInstance( $this->getUser() ); $merged = $globalUser->listAttached(); $this->getOutput()->addWikiMsg( 'centralauth-attach-list-attached', $this->mUserName ); $this->getOutput()->addHTML( $this->listAttached( $merged ) ); diff --git a/includes/specials/SpecialMultiLock.php b/includes/specials/SpecialMultiLock.php index 6548578..802d289 100644 --- a/includes/specials/SpecialMultiLock.php +++ b/includes/specials/SpecialMultiLock.php @@ -89,7 +89,7 @@ } $username = $this->getLanguage()->ucfirst( $username ); - $globalUser = new CentralAuthUser( $username ); + $globalUser = CentralAuthUser::getInstanceByName( $username ); if ( !$globalUser->exists() || ( !$this->mCanOversight && ( $globalUser->isOversighted() || $globalUser->isHidden() ) ) ) { -- To view, visit https://gerrit.wikimedia.org/r/274043 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idc87313499c04b894308d4d14a578cc683b477f4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CentralAuth Gerrit-Branch: wmf/1.27.0-wmf.14 Gerrit-Owner: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits