From 5c88c989328b38b7c2127af83f890d06bbe134af Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 27 Jun 2019 18:23:18 -0700 Subject: [PATCH] Rename various $wikiId fields/parameters to $dbDomain in user classes Change-Id: I0d4455ff4a693de41b8985b1421b18d93527acd6 --- includes/specials/SpecialUserrights.php | 20 ++++---- includes/user/User.php | 12 ++--- includes/user/UserRightsProxy.php | 62 ++++++++++++------------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index 1c87f7a395..a8ff32fa90 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -507,18 +507,18 @@ class UserrightsPage extends SpecialPage { $parts = explode( $this->getConfig()->get( 'UserrightsInterwikiDelimiter' ), $username ); if ( count( $parts ) < 2 ) { $name = trim( $username ); - $wikiId = ''; + $dbDomain = ''; } else { - list( $name, $wikiId ) = array_map( 'trim', $parts ); + list( $name, $dbDomain ) = array_map( 'trim', $parts ); - if ( WikiMap::isCurrentWikiId( $wikiId ) ) { - $wikiId = ''; + if ( WikiMap::isCurrentWikiId( $dbDomain ) ) { + $dbDomain = ''; } else { if ( $writing && !$this->getUser()->isAllowed( 'userrights-interwiki' ) ) { return Status::newFatal( 'userrights-no-interwiki' ); } - if ( !UserRightsProxy::validDatabase( $wikiId ) ) { - return Status::newFatal( 'userrights-nodatabase', $wikiId ); + if ( !UserRightsProxy::validDatabase( $dbDomain ) ) { + return Status::newFatal( 'userrights-nodatabase', $dbDomain ); } } } @@ -532,10 +532,10 @@ class UserrightsPage extends SpecialPage { // We'll do a lookup for the name internally. $id = intval( substr( $name, 1 ) ); - if ( $wikiId == '' ) { + if ( $dbDomain == '' ) { $name = User::whoIs( $id ); } else { - $name = UserRightsProxy::whoIs( $wikiId, $id ); + $name = UserRightsProxy::whoIs( $dbDomain, $id ); } if ( !$name ) { @@ -549,10 +549,10 @@ class UserrightsPage extends SpecialPage { } } - if ( $wikiId == '' ) { + if ( $dbDomain == '' ) { $user = User::newFromName( $name ); } else { - $user = UserRightsProxy::newFromName( $wikiId, $name ); + $user = UserRightsProxy::newFromName( $dbDomain, $name ); } if ( !$user || $user->isAnon() ) { diff --git a/includes/user/User.php b/includes/user/User.php index 6025d3cf1a..2e97580940 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -491,12 +491,12 @@ class User implements IDBAccessObject, UserIdentity { /** * @since 1.27 - * @param string $wikiId + * @param string $dbDomain * @param int $userId */ - public static function purge( $wikiId, $userId ) { + public static function purge( $dbDomain, $userId ) { $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); - $key = $cache->makeGlobalKey( 'user', 'id', $wikiId, $userId ); + $key = $cache->makeGlobalKey( 'user', 'id', $dbDomain, $userId ); $cache->delete( $key ); } @@ -680,16 +680,16 @@ class User implements IDBAccessObject, UserIdentity { * @param int|null $userId User ID, if known * @param string|null $userName User name, if known * @param int|null $actorId Actor ID, if known - * @param bool|string $wikiId remote wiki to which the User/Actor ID applies, or false if none + * @param bool|string $dbDomain remote wiki to which the User/Actor ID applies, or false if none * @return User */ - public static function newFromAnyId( $userId, $userName, $actorId, $wikiId = false ) { + public static function newFromAnyId( $userId, $userName, $actorId, $dbDomain = false ) { global $wgActorTableSchemaMigrationStage; // Stop-gap solution for the problem described in T222212. // Force the User ID and Actor ID to zero for users loaded from the database // of another wiki, to prevent subtle data corruption and confusing failure modes. - if ( $wikiId !== false ) { + if ( $dbDomain !== false ) { $userId = 0; $actorId = 0; } diff --git a/includes/user/UserRightsProxy.php b/includes/user/UserRightsProxy.php index 0b7a7200f9..603d3339a8 100644 --- a/includes/user/UserRightsProxy.php +++ b/includes/user/UserRightsProxy.php @@ -30,7 +30,7 @@ class UserRightsProxy { /** @var IDatabase */ private $db; /** @var string */ - private $wikiId; + private $dbDomain; /** @var string */ private $name; /** @var int */ @@ -42,13 +42,13 @@ class UserRightsProxy { * @see newFromId() * @see newFromName() * @param IDatabase $db Db connection - * @param string $wikiId Database name + * @param string $dbDomain Database name * @param string $name User name * @param int $id User ID */ - private function __construct( $db, $wikiId, $name, $id ) { + private function __construct( $db, $dbDomain, $name, $id ) { $this->db = $db; - $this->wikiId = $wikiId; + $this->dbDomain = $dbDomain; $this->name = $name; $this->id = intval( $id ); $this->newOptions = []; @@ -57,24 +57,24 @@ class UserRightsProxy { /** * Confirm the selected database name is a valid local interwiki database name. * - * @param string $wikiId Database name + * @param string $dbDomain Database name * @return bool */ - public static function validDatabase( $wikiId ) { + public static function validDatabase( $dbDomain ) { global $wgLocalDatabases; - return in_array( $wikiId, $wgLocalDatabases ); + return in_array( $dbDomain, $wgLocalDatabases ); } /** * Same as User::whoIs() * - * @param string $wikiId Database name + * @param string $dbDomain Database name * @param int $id User ID - * @param bool $ignoreInvalidDB If true, don't check if $wikiId is in $wgLocalDatabases + * @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases * @return string User name or false if the user doesn't exist */ - public static function whoIs( $wikiId, $id, $ignoreInvalidDB = false ) { - $user = self::newFromId( $wikiId, $id, $ignoreInvalidDB ); + public static function whoIs( $dbDomain, $id, $ignoreInvalidDB = false ) { + $user = self::newFromId( $dbDomain, $id, $ignoreInvalidDB ); if ( $user ) { return $user->name; } else { @@ -85,35 +85,35 @@ class UserRightsProxy { /** * Factory function; get a remote user entry by ID number. * - * @param string $wikiId Database name + * @param string $dbDomain Database name * @param int $id User ID - * @param bool $ignoreInvalidDB If true, don't check if $wikiId is in $wgLocalDatabases + * @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases * @return UserRightsProxy|null If doesn't exist */ - public static function newFromId( $wikiId, $id, $ignoreInvalidDB = false ) { - return self::newFromLookup( $wikiId, 'user_id', intval( $id ), $ignoreInvalidDB ); + public static function newFromId( $dbDomain, $id, $ignoreInvalidDB = false ) { + return self::newFromLookup( $dbDomain, 'user_id', intval( $id ), $ignoreInvalidDB ); } /** * Factory function; get a remote user entry by name. * - * @param string $wikiId Database name + * @param string $dbDomain Database name * @param string $name User name - * @param bool $ignoreInvalidDB If true, don't check if $wikiId is in $wgLocalDatabases + * @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases * @return UserRightsProxy|null If doesn't exist */ - public static function newFromName( $wikiId, $name, $ignoreInvalidDB = false ) { - return self::newFromLookup( $wikiId, 'user_name', $name, $ignoreInvalidDB ); + public static function newFromName( $dbDomain, $name, $ignoreInvalidDB = false ) { + return self::newFromLookup( $dbDomain, 'user_name', $name, $ignoreInvalidDB ); } /** - * @param string $wikiId + * @param string $dbDomain * @param string $field * @param string $value * @param bool $ignoreInvalidDB * @return null|UserRightsProxy */ - private static function newFromLookup( $wikiId, $field, $value, $ignoreInvalidDB = false ) { + private static function newFromLookup( $dbDomain, $field, $value, $ignoreInvalidDB = false ) { global $wgSharedDB, $wgSharedTables; // If the user table is shared, perform the user query on it, // but don't pass it to the UserRightsProxy, @@ -121,10 +121,10 @@ class UserRightsProxy { if ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) { $userdb = self::getDB( $wgSharedDB, $ignoreInvalidDB ); } else { - $userdb = self::getDB( $wikiId, $ignoreInvalidDB ); + $userdb = self::getDB( $dbDomain, $ignoreInvalidDB ); } - $db = self::getDB( $wikiId, $ignoreInvalidDB ); + $db = self::getDB( $dbDomain, $ignoreInvalidDB ); if ( $db && $userdb ) { $row = $userdb->selectRow( 'user', @@ -134,7 +134,7 @@ class UserRightsProxy { if ( $row !== false ) { return new UserRightsProxy( - $db, $wikiId, $row->user_name, intval( $row->user_id ) ); + $db, $dbDomain, $row->user_name, intval( $row->user_id ) ); } } return null; @@ -144,17 +144,17 @@ class UserRightsProxy { * Open a database connection to work on for the requested user. * This may be a new connection to another database for remote users. * - * @param string $wikiId - * @param bool $ignoreInvalidDB If true, don't check if $wikiId is in $wgLocalDatabases + * @param string $dbDomain + * @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases * @return IDatabase|null If invalid selection */ - public static function getDB( $wikiId, $ignoreInvalidDB = false ) { - if ( $ignoreInvalidDB || self::validDatabase( $wikiId ) ) { - if ( WikiMap::isCurrentWikiId( $wikiId ) ) { + public static function getDB( $dbDomain, $ignoreInvalidDB = false ) { + if ( $ignoreInvalidDB || self::validDatabase( $dbDomain ) ) { + if ( WikiMap::isCurrentWikiId( $dbDomain ) ) { // Hmm... this shouldn't happen though. :) return wfGetDB( DB_MASTER ); } else { - return wfGetDB( DB_MASTER, [], $wikiId ); + return wfGetDB( DB_MASTER, [], $dbDomain ); } } return null; @@ -180,7 +180,7 @@ class UserRightsProxy { * @return string */ public function getName() { - return $this->name . '@' . $this->wikiId; + return $this->name . '@' . $this->dbDomain; } /** -- 2.20.1