r70632 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70631‎ | r70632 | r70633 >
Date:16:08, 7 August 2010
Author:catrope
Status:ok
Tags:
Comment:
Hack up UserRightsProxy to support setting preferences of remote users, needed for a feature in PrefSwitch I'm about to commit. The way this hacks around UserRightsProxy's 'helpful' behavior of refusing to work with wikis not in $wgLoclDatabases is kinda ugly (I'm open to alternative suggestions), but then this entire class is an ugly hack and should be replaced by something more sane (even brion, its author, agrees with this :P)
Modified paths:
  • /trunk/phase3/includes/UserRightsProxy.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/UserRightsProxy.php
@@ -21,6 +21,7 @@
2222 $this->database = $database;
2323 $this->name = $name;
2424 $this->id = intval( $id );
 25+ $this->newOptions = array();
2526 }
2627
2728 /**
@@ -48,10 +49,11 @@
4950 *
5051 * @param $database String: database name
5152 * @param $id Integer: user ID
 53+ * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases
5254 * @return String: user name or false if the user doesn't exist
5355 */
54 - public static function whoIs( $database, $id ) {
55 - $user = self::newFromId( $database, $id );
 56+ public static function whoIs( $database, $id, $ignoreInvalidDB = false ) {
 57+ $user = self::newFromId( $database, $id, $ignoreInvalidDB );
5658 if( $user ) {
5759 return $user->name;
5860 } else {
@@ -64,10 +66,11 @@
6567 *
6668 * @param $database String: database name
6769 * @param $id Integer: user ID
 70+ * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases
6871 * @return UserRightsProxy or null if doesn't exist
6972 */
70 - public static function newFromId( $database, $id ) {
71 - return self::newFromLookup( $database, 'user_id', intval( $id ) );
 73+ public static function newFromId( $database, $id, $ignoreInvalidDB = false ) {
 74+ return self::newFromLookup( $database, 'user_id', intval( $id ), $ignoreInvalidDB );
7275 }
7376
7477 /**
@@ -75,14 +78,15 @@
7679 *
7780 * @param $database String: database name
7881 * @param $name String: user name
 82+ * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases
7983 * @return UserRightsProxy or null if doesn't exist
8084 */
81 - public static function newFromName( $database, $name ) {
82 - return self::newFromLookup( $database, 'user_name', $name );
 85+ public static function newFromName( $database, $name, $ignoreInvalidDB = false ) {
 86+ return self::newFromLookup( $database, 'user_name', $name, $ignoreInvalidDB );
8387 }
8488
85 - private static function newFromLookup( $database, $field, $value ) {
86 - $db = self::getDB( $database );
 89+ private static function newFromLookup( $database, $field, $value, $ignoreInvalidDB = false ) {
 90+ $db = self::getDB( $database, $ignoreInvalidDB );
8791 if( $db ) {
8892 $row = $db->selectRow( 'user',
8993 array( 'user_id', 'user_name' ),
@@ -102,9 +106,10 @@
103107 * This may be a new connection to another database for remote users.
104108 *
105109 * @param $database String
 110+ * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases
106111 * @return DatabaseBase or null if invalid selection
107112 */
108 - public static function getDB( $database ) {
 113+ public static function getDB( $database, $ignoreInvalidDB = false ) {
109114 global $wgDBname;
110115 if( self::validDatabase( $database ) ) {
111116 if( $database == $wgDBname ) {
@@ -182,6 +187,29 @@
183188 ),
184189 __METHOD__ );
185190 }
 191+
 192+ /**
 193+ * Replaces User::setOption()
 194+ */
 195+ public function setOption( $option, $value ) {
 196+ $this->newOptions[$option] = $value;
 197+ }
 198+
 199+ public function saveSettings() {
 200+ $rows = array();
 201+ foreach ( $this->newOptions as $option => $value ) {
 202+ $rows[] = array(
 203+ 'up_user' => $this->id,
 204+ 'up_property' => $option,
 205+ 'up_value' => $value,
 206+ );
 207+ }
 208+ $this->db->replace( 'user_properties',
 209+ array( array( 'up_user', 'up_property' ) ),
 210+ $rows, __METHOD__
 211+ );
 212+ $this->invalidateCache();
 213+ }
186214
187215 /**
188216 * Replaces User::touchUser()

Follow-up revisions

RevisionCommit summaryAuthorDate
r721321.16wmf4: MFT r70632catrope18:09, 1 September 2010

Status & tagging log