Index: branches/preferences-work/phase3/includes/User.php |
— | — | @@ -109,7 +109,6 @@ |
110 | 110 | 'mNewpassword', |
111 | 111 | 'mNewpassTime', |
112 | 112 | 'mEmail', |
113 | | - 'mOptions', |
114 | 113 | 'mTouched', |
115 | 114 | 'mToken', |
116 | 115 | 'mEmailAuthenticated', |
— | — | @@ -119,6 +118,8 @@ |
120 | 119 | 'mEditCount', |
121 | 120 | // user_group table |
122 | 121 | 'mGroups', |
| 122 | + // user_properties table |
| 123 | + 'mOptions', |
123 | 124 | ); |
124 | 125 | |
125 | 126 | /** |
— | — | @@ -195,7 +196,7 @@ |
196 | 197 | /** |
197 | 198 | * \bool Whether the cache variables have been loaded. |
198 | 199 | */ |
199 | | - var $mDataLoaded, $mAuthLoaded; |
| 200 | + var $mDataLoaded, $mAuthLoaded, $mOptionsLoaded; |
200 | 201 | |
201 | 202 | /** |
202 | 203 | * \string Initialization data source if mDataLoaded==false. May be one of: |
— | — | @@ -311,6 +312,7 @@ |
312 | 313 | function saveToCache() { |
313 | 314 | $this->load(); |
314 | 315 | $this->loadGroups(); |
| 316 | + $this->loadOptions(); |
315 | 317 | if ( $this->isAnon() ) { |
316 | 318 | // Anonymous users are uncached |
317 | 319 | return; |
— | — | @@ -1867,7 +1869,7 @@ |
1868 | 1870 | * @see getIntOption() |
1869 | 1871 | */ |
1870 | 1872 | function getOption( $oname, $defaultOverride = '' ) { |
1871 | | - $this->load(); |
| 1873 | + $this->loadOptions(); |
1872 | 1874 | |
1873 | 1875 | if ( is_null( $this->mOptions ) ) { |
1874 | 1876 | if($defaultOverride != '') { |
— | — | @@ -2309,6 +2311,11 @@ |
2310 | 2312 | * @private |
2311 | 2313 | */ |
2312 | 2314 | function decodeOptions( $str ) { |
| 2315 | + if ($str) |
| 2316 | + $this->mOptionsLoaded = true; |
| 2317 | + else |
| 2318 | + return; |
| 2319 | + |
2313 | 2320 | $this->mOptions = array(); |
2314 | 2321 | $a = explode( "\n", $str ); |
2315 | 2322 | foreach ( $a as $s ) { |
— | — | @@ -2423,7 +2430,7 @@ |
2424 | 2431 | 'user_real_name' => $this->mRealName, |
2425 | 2432 | 'user_email' => $this->mEmail, |
2426 | 2433 | 'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ), |
2427 | | - 'user_options' => $this->encodeOptions(), |
| 2434 | + 'user_options' => '', |
2428 | 2435 | 'user_touched' => $dbw->timestamp($this->mTouched), |
2429 | 2436 | 'user_token' => $this->mToken, |
2430 | 2437 | 'user_email_token' => $this->mEmailToken, |
— | — | @@ -2432,6 +2439,9 @@ |
2433 | 2440 | 'user_id' => $this->mId |
2434 | 2441 | ), __METHOD__ |
2435 | 2442 | ); |
| 2443 | + |
| 2444 | + $this->saveOptions(); |
| 2445 | + |
2436 | 2446 | wfRunHooks( 'UserSaveSettings', array( $this ) ); |
2437 | 2447 | $this->clearSharedCache(); |
2438 | 2448 | $this->getUserPage()->invalidateCache(); |
— | — | @@ -3400,5 +3410,49 @@ |
3401 | 3411 | $log->addEntry( 'autocreate', $this->getUserPage(), '', array( $this->getId() ) ); |
3402 | 3412 | return true; |
3403 | 3413 | } |
| 3414 | + |
| 3415 | + protected function loadOptions() { |
| 3416 | + $this->load(); |
| 3417 | + if ($this->mOptionsLoaded || !$this->getId() ) |
| 3418 | + return; |
| 3419 | + |
| 3420 | + // Load from database |
| 3421 | + $dbr = wfGetDB( DB_SLAVE ); |
| 3422 | + |
| 3423 | + $res = $dbr->select( 'user_properties', |
| 3424 | + '*', |
| 3425 | + array('up_user' => $this->getId()), |
| 3426 | + __METHOD__ |
| 3427 | + ); |
| 3428 | + |
| 3429 | + while( $row = $dbr->fetchObject( $res ) ) { |
| 3430 | + $this->mOptions[$row->up_property] = unserialize( $row->up_value ); |
| 3431 | + } |
| 3432 | + } |
| 3433 | + |
| 3434 | + protected function saveOptions() { |
| 3435 | + global $wgDefaultUserOptions; |
| 3436 | + $dbw = wfGetDB( DB_MASTER ); |
| 3437 | + |
| 3438 | + $insert_rows = array(); |
| 3439 | + |
| 3440 | + foreach( $this->mOptions as $key => $value ) { |
| 3441 | + $ser = serialize($value); |
| 3442 | + |
| 3443 | + if ( isset($wgDefaultUserOptions[$key]) && |
| 3444 | + $value != $wgDefaultUserOptions[$key] ) { |
| 3445 | + $insert_rows[] = array( |
| 3446 | + 'up_user' => $this->getId(), |
| 3447 | + 'up_property' => $key, |
| 3448 | + 'up_value' => $ser, |
| 3449 | + ); |
| 3450 | + } |
| 3451 | + } |
| 3452 | + |
| 3453 | + $dbw->begin(); |
| 3454 | + $dbw->delete( 'user_properties', array( 'up_user' => $this->getId() ), __METHOD__ ); |
| 3455 | + $dbw->insert( 'user_properties', $insert_rows, __METHOD__ ); |
| 3456 | + $dbw->commit(); |
| 3457 | + } |
3404 | 3458 | |
3405 | 3459 | } |