Index: trunk/phase3/includes/UserRightsProxy.php |
— | — | @@ -21,6 +21,7 @@ |
22 | 22 | $this->database = $database; |
23 | 23 | $this->name = $name; |
24 | 24 | $this->id = intval( $id ); |
| 25 | + $this->newOptions = array(); |
25 | 26 | } |
26 | 27 | |
27 | 28 | /** |
— | — | @@ -48,10 +49,11 @@ |
49 | 50 | * |
50 | 51 | * @param $database String: database name |
51 | 52 | * @param $id Integer: user ID |
| 53 | + * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases |
52 | 54 | * @return String: user name or false if the user doesn't exist |
53 | 55 | */ |
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 ); |
56 | 58 | if( $user ) { |
57 | 59 | return $user->name; |
58 | 60 | } else { |
— | — | @@ -64,10 +66,11 @@ |
65 | 67 | * |
66 | 68 | * @param $database String: database name |
67 | 69 | * @param $id Integer: user ID |
| 70 | + * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases |
68 | 71 | * @return UserRightsProxy or null if doesn't exist |
69 | 72 | */ |
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 ); |
72 | 75 | } |
73 | 76 | |
74 | 77 | /** |
— | — | @@ -75,14 +78,15 @@ |
76 | 79 | * |
77 | 80 | * @param $database String: database name |
78 | 81 | * @param $name String: user name |
| 82 | + * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases |
79 | 83 | * @return UserRightsProxy or null if doesn't exist |
80 | 84 | */ |
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 ); |
83 | 87 | } |
84 | 88 | |
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 ); |
87 | 91 | if( $db ) { |
88 | 92 | $row = $db->selectRow( 'user', |
89 | 93 | array( 'user_id', 'user_name' ), |
— | — | @@ -102,9 +106,10 @@ |
103 | 107 | * This may be a new connection to another database for remote users. |
104 | 108 | * |
105 | 109 | * @param $database String |
| 110 | + * @param $ignoreInvalidDB Boolean: if true, don't check if $database is in $wgLocalDatabases |
106 | 111 | * @return DatabaseBase or null if invalid selection |
107 | 112 | */ |
108 | | - public static function getDB( $database ) { |
| 113 | + public static function getDB( $database, $ignoreInvalidDB = false ) { |
109 | 114 | global $wgDBname; |
110 | 115 | if( self::validDatabase( $database ) ) { |
111 | 116 | if( $database == $wgDBname ) { |
— | — | @@ -182,6 +187,29 @@ |
183 | 188 | ), |
184 | 189 | __METHOD__ ); |
185 | 190 | } |
| 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 | + } |
186 | 214 | |
187 | 215 | /** |
188 | 216 | * Replaces User::touchUser() |