r58403 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58402‎ | r58403 | r58404 >
Date:19:48, 1 November 2009
Author:catrope
Status:ok
Tags:
Comment:
Revert accidentally committed stuff in r58399
Modified paths:
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -3578,7 +3578,7 @@
35793579 protected function loadOptions() {
35803580 global $wgCookiePrefix;
35813581 $this->load();
3582 - if ( $this->mOptionsLoaded )
 3582+ if ( $this->mOptionsLoaded || !$this->getId() )
35833583 return;
35843584
35853585 $this->mOptions = self::getDefaultOptions();
@@ -3590,11 +3590,20 @@
35913591 $this->mOptions[$key] = $value;
35923592 }
35933593 } 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;
35993608 }
36003609
36013610 //null skin if User::mId is loaded out of session data without persistant credentials
@@ -3608,73 +3617,23 @@
36093618 wfRunHooks( 'UserLoadOptions', array( $this, &$this->mOptions ) );
36103619 }
36113620
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 -
36423621 protected function saveOptions() {
36433622 global $wgAllowPrefChange;
36443623
 3624+ $extuser = ExternalUser::newFromUser( $this );
 3625+
36453626 $this->loadOptions();
 3627+ $dbw = wfGetDB( DB_MASTER );
36463628
 3629+ $insert_rows = array();
 3630+
36473631 $saveOptions = $this->mOptions;
36483632
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 -
36633633 // Allow hooks to abort, for instance to save to a global profile.
36643634 // Reset options to default state before saving.
36653635 if( !wfRunHooks( 'UserSaveOptions', array( $this, &$saveOptions ) ) )
36663636 return;
36673637
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 -
36793638 foreach( $saveOptions as $key => $value ) {
36803639 # Don't bother storing default values
36813640 if ( ( is_null( self::getDefaultOption( $key ) ) &&
@@ -3686,6 +3645,16 @@
36873646 'up_value' => $value,
36883647 );
36893648 }
 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+ }
36903659 }
36913660
36923661 $dbw->begin();
@@ -3694,12 +3663,6 @@
36953664 $dbw->commit();
36963665 }
36973666
3698 - protected function saveOptionsToCookie( $saveOptions ) {
3699 - global $wgRequest;
3700 -
3701 - $data = json_encode( $saveOptions );
3702 - $wgRequest->response()->setCookie( 'Options', $data, 86400 * 360 );
3703 - }
37043667 /**
37053668 * Provide an array of HTML 5 attributes to put on an input element
37063669 * intended for the user to enter a new password. This may include

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r58399API: (bug 19004) Add support for tags. Patch by Matthew Brittoncatrope10:42, 1 November 2009

Status & tagging log