http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70632

Revision: 70632
Author:   catrope
Date:     2010-08-07 16:08:22 +0000 (Sat, 07 Aug 2010)

Log Message:
-----------
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: trunk/phase3/includes/UserRightsProxy.php
===================================================================
--- trunk/phase3/includes/UserRightsProxy.php   2010-08-07 14:58:18 UTC (rev 
70631)
+++ trunk/phase3/includes/UserRightsProxy.php   2010-08-07 16:08:22 UTC (rev 
70632)
@@ -21,6 +21,7 @@
                $this->database = $database;
                $this->name = $name;
                $this->id = intval( $id );
+               $this->newOptions = array();
        }
 
        /**
@@ -48,10 +49,11 @@
         *
         * @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 ) {
-               $user = self::newFromId( $database, $id );
+       public static function whoIs( $database, $id, $ignoreInvalidDB = false 
) {
+               $user = self::newFromId( $database, $id, $ignoreInvalidDB );
                if( $user ) {
                        return $user->name;
                } else {
@@ -64,10 +66,11 @@
         *
         * @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 );
        }
 
        /**
@@ -75,14 +78,15 @@
         *
         * @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 ) {
-               return self::newFromLookup( $database, 'user_name', $name );
+       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' ),
@@ -102,9 +106,10 @@
         * 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
         */
-       public static function getDB( $database ) {
+       public static function getDB( $database, $ignoreInvalidDB = false ) {
                global $wgDBname;
                if( self::validDatabase( $database ) ) {
                        if( $database == $wgDBname ) {
@@ -182,6 +187,29 @@
                        ),
                        __METHOD__ );
        }
+       
+       /**
+        * 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()



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to