Index: trunk/phase3/includes/User.php |
— | — | @@ -3578,7 +3578,7 @@ |
3579 | 3579 | protected function loadOptions() { |
3580 | 3580 | global $wgCookiePrefix; |
3581 | 3581 | $this->load(); |
3582 | | - if ( $this->mOptionsLoaded ) |
| 3582 | + if ( $this->mOptionsLoaded || !$this->getId() ) |
3583 | 3583 | return; |
3584 | 3584 | |
3585 | 3585 | $this->mOptions = self::getDefaultOptions(); |
— | — | @@ -3590,11 +3590,20 @@ |
3591 | 3591 | $this->mOptions[$key] = $value; |
3592 | 3592 | } |
3593 | 3593 | } else { |
3594 | | - $this->mOptionOverrides = array(); |
3595 | | - if ( $this->getId() ) { |
3596 | | - $this->loadOptionsFromDatabase(); |
3597 | | - } else { |
3598 | | - $this->loadOptionsFromCookie(); |
| 3594 | + wfDebug( "Loading options for user " . $this->getId() . " from database.\n" ); |
| 3595 | + // Load from database |
| 3596 | + $dbr = wfGetDB( DB_SLAVE ); |
| 3597 | + |
| 3598 | + $res = $dbr->select( |
| 3599 | + 'user_properties', |
| 3600 | + '*', |
| 3601 | + array( 'up_user' => $this->getId() ), |
| 3602 | + __METHOD__ |
| 3603 | + ); |
| 3604 | + |
| 3605 | + while( $row = $dbr->fetchObject( $res ) ) { |
| 3606 | + $this->mOptionOverrides[$row->up_property] = $row->up_value; |
| 3607 | + $this->mOptions[$row->up_property] = $row->up_value; |
3599 | 3608 | } |
3600 | 3609 | |
3601 | 3610 | //null skin if User::mId is loaded out of session data without persistant credentials |
— | — | @@ -3608,73 +3617,23 @@ |
3609 | 3618 | wfRunHooks( 'UserLoadOptions', array( $this, &$this->mOptions ) ); |
3610 | 3619 | } |
3611 | 3620 | |
3612 | | - protected function loadOptionsFromDatabase() { |
3613 | | - wfDebug( "Loading options for user ".$this->getId()." from database.\n" ); |
3614 | | - // Load from database |
3615 | | - $dbr = wfGetDB( DB_SLAVE ); |
3616 | | - |
3617 | | - $res = $dbr->select( |
3618 | | - 'user_properties', |
3619 | | - '*', |
3620 | | - array('up_user' => $this->getId()), |
3621 | | - __METHOD__ |
3622 | | - ); |
3623 | | - |
3624 | | - while( $row = $dbr->fetchObject( $res ) ) { |
3625 | | - $this->mOptionOverrides[$row->up_property] = $row->up_value; |
3626 | | - $this->mOptions[$row->up_property] = $row->up_value; |
3627 | | - } |
3628 | | - } |
3629 | | - |
3630 | | - protected function loadOptionsFromCookie() { |
3631 | | - global $wgCookiePrefix; |
3632 | | - $cookie = $_COOKIE[$wgCookiePrefix."Options"]; |
3633 | | - |
3634 | | - $overrides = json_decode($cookie, true); // Load assoc array from cookie |
3635 | | - |
3636 | | - foreach( $overrides as $key => $value ) { |
3637 | | - $this->mOptions[$key] = $value; |
3638 | | - $this->mOptionOverrides[$key] = $value; |
3639 | | - } |
3640 | | - } |
3641 | | - |
3642 | 3621 | protected function saveOptions() { |
3643 | 3622 | global $wgAllowPrefChange; |
3644 | 3623 | |
| 3624 | + $extuser = ExternalUser::newFromUser( $this ); |
| 3625 | + |
3645 | 3626 | $this->loadOptions(); |
| 3627 | + $dbw = wfGetDB( DB_MASTER ); |
3646 | 3628 | |
| 3629 | + $insert_rows = array(); |
| 3630 | + |
3647 | 3631 | $saveOptions = $this->mOptions; |
3648 | 3632 | |
3649 | | - $extuser = ExternalUser::newFromUser( $this ); |
3650 | | - foreach( $saveOptions as $key => $value ) { |
3651 | | - if ( $extuser && isset( $wgAllowPrefChange[$key] ) ) { |
3652 | | - switch ( $wgAllowPrefChange[$key] ) { |
3653 | | - case 'local': |
3654 | | - case 'message': |
3655 | | - break; |
3656 | | - case 'semiglobal': |
3657 | | - case 'global': |
3658 | | - $extuser->setPref( $key, $value ); |
3659 | | - } |
3660 | | - } |
3661 | | - } |
3662 | | - |
3663 | 3633 | // Allow hooks to abort, for instance to save to a global profile. |
3664 | 3634 | // Reset options to default state before saving. |
3665 | 3635 | if( !wfRunHooks( 'UserSaveOptions', array( $this, &$saveOptions ) ) ) |
3666 | 3636 | return; |
3667 | 3637 | |
3668 | | - if ( $this->getId() ) { |
3669 | | - $this->saveOptionsToDatabase( $saveOptions ); |
3670 | | - } else { |
3671 | | - $this->saveOptionsToCookie( $saveOptions ); |
3672 | | - } |
3673 | | - } |
3674 | | - |
3675 | | - protected function saveOptionsToDatabase( $saveOptions ) { |
3676 | | - $dbw = wfGetDB( DB_MASTER ); |
3677 | | - $insert_rows = array(); |
3678 | | - |
3679 | 3638 | foreach( $saveOptions as $key => $value ) { |
3680 | 3639 | # Don't bother storing default values |
3681 | 3640 | if ( ( is_null( self::getDefaultOption( $key ) ) && |
— | — | @@ -3686,6 +3645,16 @@ |
3687 | 3646 | 'up_value' => $value, |
3688 | 3647 | ); |
3689 | 3648 | } |
| 3649 | + if ( $extuser && isset( $wgAllowPrefChange[$key] ) ) { |
| 3650 | + switch ( $wgAllowPrefChange[$key] ) { |
| 3651 | + case 'local': |
| 3652 | + case 'message': |
| 3653 | + break; |
| 3654 | + case 'semiglobal': |
| 3655 | + case 'global': |
| 3656 | + $extuser->setPref( $key, $value ); |
| 3657 | + } |
| 3658 | + } |
3690 | 3659 | } |
3691 | 3660 | |
3692 | 3661 | $dbw->begin(); |
— | — | @@ -3694,12 +3663,6 @@ |
3695 | 3664 | $dbw->commit(); |
3696 | 3665 | } |
3697 | 3666 | |
3698 | | - protected function saveOptionsToCookie( $saveOptions ) { |
3699 | | - global $wgRequest; |
3700 | | - |
3701 | | - $data = json_encode( $saveOptions ); |
3702 | | - $wgRequest->response()->setCookie( 'Options', $data, 86400 * 360 ); |
3703 | | - } |
3704 | 3667 | /** |
3705 | 3668 | * Provide an array of HTML 5 attributes to put on an input element |
3706 | 3669 | * intended for the user to enter a new password. This may include |