Index: branches/wmf/1.16wmf4/extensions/UsabilityInitiative/PrefSwitch/SpecialPrefSwitch.php |
— | — | @@ -85,6 +85,7 @@ |
86 | 86 | $globalUser->getName(), |
87 | 87 | true |
88 | 88 | ); |
| 89 | + |
89 | 90 | if ( $remoteUser ) { |
90 | 91 | self::switchOffUser( $remoteUser ); |
91 | 92 | } |
— | — | @@ -94,10 +95,23 @@ |
95 | 96 | |
96 | 97 | private static function switchOffUser( $user ) { |
97 | 98 | global $wgPrefSwitchPrefs; |
98 | | - foreach ( $wgPrefSwitchPrefs['off'] as $pref => $value ) { |
| 99 | + // HACK check they don't already have a setting |
| 100 | + $dbname = $user instanceof UserRightsProxy ? $user->getDBName() : false; |
| 101 | + $dbw = wfGetDb( DB_MASTER, array(), $dbname ); |
| 102 | + $res = $dbw->select( 'user_properties', 'up_property', array( 'up_user' => $user->getID(), 'up_property' => array_keys( $wgPrefSwitchPrefs['off'] ) ), __METHOD__ ); |
| 103 | + $alreadySet = array(); |
| 104 | + foreach ( $res as $row ) { |
| 105 | + $alreadySet[$row->up_property] = true; |
| 106 | + } |
| 107 | + foreach ( array_diff_key( $wgPrefSwitchPrefs['off'], $alreadySet ) as $pref => $value ) { |
99 | 108 | $user->setOption( $pref, $value ); |
100 | 109 | } |
101 | 110 | $user->saveSettings(); |
| 111 | + // HACK close the connection so s3 doesn't get overloaded |
| 112 | + // but don't close the currnet wiki's connection |
| 113 | + if ( $dbname ) { |
| 114 | + $dbw->close(); |
| 115 | + } |
102 | 116 | } |
103 | 117 | |
104 | 118 | /* Functions */ |