X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FUserRightsProxy.php;h=6c2a5f1201fdafda63b77715dbe493e595ecf496;hb=1a69f893509b8cc08c1675655e59d6fe74866f46;hp=9096744e0d41198053744746db59ceb8d43ec50d;hpb=fbfb509df557ca9eef812f6645459c483149f186;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/UserRightsProxy.php b/includes/UserRightsProxy.php index 9096744e0d..6c2a5f1201 100644 --- a/includes/UserRightsProxy.php +++ b/includes/UserRightsProxy.php @@ -1,50 +1,92 @@ db = $db; $this->database = $database; $this->name = $name; $this->id = intval( $id ); + $this->newOptions = array(); } - + + /** + * Accessor for $this->database + * + * @return String: database name + */ + public function getDBName() { + return $this->database; + } + /** * Confirm the selected database name is a valid local interwiki database name. - * @return bool + * + * @param $database String: database name + * @return Boolean */ public static function validDatabase( $database ) { global $wgLocalDatabases; return in_array( $database, $wgLocalDatabases ); } - - public static function whoIs( $database, $id ) { - $user = self::newFromId( $database, $id ); + + /** + * Same as User::whoIs() + * + * @param $database String: 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 + */ + public static function whoIs( $database, $id, $ignoreInvalidDB = false ) { + $user = self::newFromId( $database, $id, $ignoreInvalidDB ); if( $user ) { return $user->name; } else { return false; } } - + /** * Factory function; get a remote user entry by ID number. + * + * @param $database String: 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 */ - public static function newFromId( $database, $id ) { - return self::newFromLookup( $database, 'user_id', intval( $id ) ); + public static function newFromId( $database, $id, $ignoreInvalidDB = false ) { + return self::newFromLookup( $database, 'user_id', intval( $id ), $ignoreInvalidDB ); } - public static function newFromName( $database, $name ) { - return self::newFromLookup( $database, 'user_name', $name ); + /** + * Factory function; get a remote user entry by name. + * + * @param $database String: database name + * @param $name String: user name + * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases + * @return UserRightsProxy or null if doesn't exist + */ + public static function newFromName( $database, $name, $ignoreInvalidDB = false ) { + return self::newFromLookup( $database, 'user_name', $name, $ignoreInvalidDB ); } - - private static function newFromLookup( $database, $field, $value ) { - $db = self::getDB( $database ); + + private static function newFromLookup( $database, $field, $value, $ignoreInvalidDB = false ) { + $db = self::getDB( $database, $ignoreInvalidDB ); if( $db ) { $row = $db->selectRow( 'user', array( 'user_id', 'user_name' ), @@ -62,11 +104,13 @@ 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 $database - * @return Database or null if invalid selection + * + * @param $database String + * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases + * @return DatabaseBase or null if invalid selection */ - public static function getDB( $database ) { - global $wgLocalDatabases, $wgDBname; + public static function getDB( $database, $ignoreInvalidDB = false ) { + global $wgDBname; if( self::validDatabase( $database ) ) { if( $database == $wgDBname ) { // Hmm... this shouldn't happen though. :) @@ -77,37 +121,51 @@ class UserRightsProxy { } return null; } - + public function getId() { return $this->id; } - + public function isAnon() { return $this->getId() == 0; } - + + /** + * Same as User::getName() + * + * @return String + */ public function getName() { return $this->name . '@' . $this->database; } - + + /** + * Same as User::getUserPage() + * + * @return Title object + */ public function getUserPage() { return Title::makeTitle( NS_USER, $this->getName() ); } - - // Replaces getUserGroups() + + /** + * Replaces User::getUserGroups() + */ function getGroups() { $res = $this->db->select( 'user_groups', array( 'ug_group' ), array( 'ug_user' => $this->id ), __METHOD__ ); $groups = array(); - while( $row = $this->db->fetchObject( $res ) ) { + foreach ( $res as $row ) { $groups[] = $row->ug_group; } return $groups; } - - // replaces addUserGroup + + /** + * Replaces User::addUserGroup() + */ function addGroup( $group ) { $this->db->insert( 'user_groups', array( @@ -117,8 +175,10 @@ class UserRightsProxy { __METHOD__, array( 'IGNORE' ) ); } - - // replaces removeUserGroup + + /** + * Replaces User::removeUserGroup() + */ function removeGroup( $group ) { $this->db->delete( 'user_groups', array( @@ -128,7 +188,32 @@ class UserRightsProxy { __METHOD__ ); } - // replaces touchUser + /** + * Replaces User::setOption() + */ + public function setOption( $option, $value ) { + $this->newOptions[$option] = $value; + } + + public function saveSettings() { + $rows = array(); + foreach ( $this->newOptions as $option => $value ) { + $rows[] = array( + 'up_user' => $this->id, + 'up_property' => $option, + 'up_value' => $value, + ); + } + $this->db->replace( 'user_properties', + array( array( 'up_user', 'up_property' ) ), + $rows, __METHOD__ + ); + $this->invalidateCache(); + } + + /** + * Replaces User::touchUser() + */ function invalidateCache() { $this->db->update( 'user', array( 'user_touched' => $this->db->timestamp() ), @@ -136,13 +221,7 @@ class UserRightsProxy { __METHOD__ ); global $wgMemc; - if ( function_exists( 'wfForeignMemcKey' ) ) { - $key = wfForeignMemcKey( $this->database, false, 'user', 'id', $this->id ); - } else { - $key = "$this->database:user:id:" . $this->id; - } + $key = wfForeignMemcKey( $this->database, false, 'user', 'id', $this->id ); $wgMemc->delete( $key ); } } - -?>