diff options
Diffstat (limited to 'includes/UserRightsProxy.php')
-rw-r--r-- | includes/UserRightsProxy.php | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/includes/UserRightsProxy.php b/includes/UserRightsProxy.php index a8a22be7..53c69d81 100644 --- a/includes/UserRightsProxy.php +++ b/includes/UserRightsProxy.php @@ -31,10 +31,10 @@ class UserRightsProxy { * * @see newFromId() * @see newFromName() - * @param $db DatabaseBase: db connection - * @param string $database database name - * @param string $name user name - * @param $id Integer: user ID + * @param DatabaseBase $db Db connection + * @param string $database Database name + * @param string $name User name + * @param int $id User ID */ private function __construct( $db, $database, $name, $id ) { $this->db = $db; @@ -47,7 +47,7 @@ class UserRightsProxy { /** * Accessor for $this->database * - * @return String: database name + * @return string Database name */ public function getDBName() { return $this->database; @@ -56,8 +56,8 @@ class UserRightsProxy { /** * Confirm the selected database name is a valid local interwiki database name. * - * @param string $database database name - * @return Boolean + * @param string $database Database name + * @return bool */ public static function validDatabase( $database ) { global $wgLocalDatabases; @@ -67,10 +67,10 @@ class UserRightsProxy { /** * Same as User::whoIs() * - * @param string $database database name - * @param $id Integer: user ID - * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases - * @return String: user name or false if the user doesn't exist + * @param string $database Database name + * @param int $id User ID + * @param bool $ignoreInvalidDB If true, don't check if $database is in $wgLocalDatabases + * @return string User name or false if the user doesn't exist */ public static function whoIs( $database, $id, $ignoreInvalidDB = false ) { $user = self::newFromId( $database, $id, $ignoreInvalidDB ); @@ -84,10 +84,10 @@ class UserRightsProxy { /** * Factory function; get a remote user entry by ID number. * - * @param string $database database name - * @param $id Integer: user ID - * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases - * @return UserRightsProxy or null if doesn't exist + * @param string $database Database name + * @param int $id User ID + * @param bool $ignoreInvalidDB If true, don't check if $database is in $wgLocalDatabases + * @return UserRightsProxy|null If doesn't exist */ public static function newFromId( $database, $id, $ignoreInvalidDB = false ) { return self::newFromLookup( $database, 'user_id', intval( $id ), $ignoreInvalidDB ); @@ -96,29 +96,40 @@ class UserRightsProxy { /** * Factory function; get a remote user entry by name. * - * @param string $database database name - * @param string $name user name - * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases - * @return UserRightsProxy or null if doesn't exist + * @param string $database Database name + * @param string $name User name + * @param bool $ignoreInvalidDB If true, don't check if $database is in $wgLocalDatabases + * @return UserRightsProxy|null If doesn't exist */ public static function newFromName( $database, $name, $ignoreInvalidDB = false ) { return self::newFromLookup( $database, 'user_name', $name, $ignoreInvalidDB ); } /** - * @param $database - * @param $field - * @param $value - * @param $ignoreInvalidDB bool + * @param string $database + * @param string $field + * @param string $value + * @param bool $ignoreInvalidDB * @return null|UserRightsProxy */ private static function newFromLookup( $database, $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, + // as user rights are normally not shared. + if ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) { + $userdb = self::getDB( $wgSharedDB, $ignoreInvalidDB ); + } else { + $userdb = self::getDB( $database, $ignoreInvalidDB ); + } + $db = self::getDB( $database, $ignoreInvalidDB ); - if ( $db ) { - $row = $db->selectRow( 'user', + + if ( $db && $userdb ) { + $row = $userdb->selectRow( 'user', array( 'user_id', 'user_name' ), array( $field => $value ), __METHOD__ ); + if ( $row !== false ) { return new UserRightsProxy( $db, $database, $row->user_name, @@ -132,9 +143,9 @@ 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 $database String - * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases - * @return DatabaseBase or null if invalid selection + * @param string $database + * @param bool $ignoreInvalidDB If true, don't check if $database is in $wgLocalDatabases + * @return DatabaseBase|null If invalid selection */ public static function getDB( $database, $ignoreInvalidDB = false ) { global $wgDBname; @@ -166,7 +177,7 @@ class UserRightsProxy { /** * Same as User::getName() * - * @return String + * @return string */ public function getName() { return $this->name . '@' . $this->database; @@ -175,7 +186,7 @@ class UserRightsProxy { /** * Same as User::getUserPage() * - * @return Title object + * @return Title */ public function getUserPage() { return Title::makeTitle( NS_USER, $this->getName() ); @@ -199,6 +210,7 @@ class UserRightsProxy { /** * Replaces User::addUserGroup() + * @param string $group */ function addGroup( $group ) { $this->db->insert( 'user_groups', @@ -212,6 +224,7 @@ class UserRightsProxy { /** * Replaces User::removeUserGroup() + * @param string $group */ function removeGroup( $group ) { $this->db->delete( 'user_groups', @@ -224,6 +237,8 @@ class UserRightsProxy { /** * Replaces User::setOption() + * @param string $option + * @param mixed $value */ public function setOption( $option, $value ) { $this->newOptions[$option] = $value; |