'mNewpassword',
'mNewpassTime',
'mEmail',
- 'mOptions',
'mTouched',
'mToken',
'mEmailAuthenticated',
'mEditCount',
// user_group table
'mGroups',
+ // user_properties table
+ 'mOptions',
);
/**
/**
* \bool Whether the cache variables have been loaded.
*/
- var $mDataLoaded, $mAuthLoaded;
+ var $mDataLoaded, $mAuthLoaded, $mOptionsLoaded;
/**
* \string Initialization data source if mDataLoaded==false. May be one of:
function saveToCache() {
$this->load();
$this->loadGroups();
+ $this->loadOptions();
if ( $this->isAnon() ) {
// Anonymous users are uncached
return;
/**
* Site defaults will override the global/language defaults
*/
- global $wgDefaultUserOptions, $wgContLang;
+ global $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin;
$defOpt = $wgDefaultUserOptions + $wgContLang->getDefaultUserOptionOverrides();
/**
$variant = $wgContLang->getPreferredVariant( false );
$defOpt['variant'] = $variant;
$defOpt['language'] = $variant;
-
- foreach( $wgNamespacesToBeSearchedDefault as $nsnum => $val ) {
- $defOpt['searchNs'.$nsnum] = $val;
+ foreach( SearchEngine::searchableNamespaces() as $nsnum => $nsname ) {
+ $defOpt['searchNs'.$nsnum] = !empty($wgNamespacesToBeSearchedDefault[$nsnum]);
}
+ $defOpt['skin'] = $wgDefaultSkin;
+
return $defOpt;
}
if( isset( $defOpts[$opt] ) ) {
return $defOpts[$opt];
} else {
- return '';
+ return null;
}
}
* @see getBoolOption()
* @see getIntOption()
*/
- function getOption( $oname, $defaultOverride = '' ) {
- $this->load();
+ function getOption( $oname, $defaultOverride = null ) {
+ $this->loadOptions();
if ( is_null( $this->mOptions ) ) {
if($defaultOverride != '') {
}
if ( array_key_exists( $oname, $this->mOptions ) ) {
- return trim( $this->mOptions[$oname] );
+ return $this->mOptions[$oname];
} else {
return $defaultOverride;
}
*/
function setOption( $oname, $val ) {
$this->load();
- if ( is_null( $this->mOptions ) ) {
- $this->mOptions = User::getDefaultOptions();
- }
+ $this->loadOptions();
+
if ( $oname == 'skin' ) {
# Clear cached skin, so the new one displays immediately in Special:Preferences
unset( $this->mSkin );
}
- // Filter out any newlines that may have passed through input validation.
- // Newlines are used to separate items in the options blob.
- if( $val ) {
- $val = str_replace( "\r\n", "\n", $val );
- $val = str_replace( "\r", "\n", $val );
- $val = str_replace( "\n", " ", $val );
- }
+
// Explicitly NULL values should refer to defaults
global $wgDefaultUserOptions;
if( is_null($val) && isset($wgDefaultUserOptions[$oname]) ) {
$val = $wgDefaultUserOptions[$oname];
}
+
$this->mOptions[$oname] = $val;
}
/**
* Reset all options to the site defaults
*/
- function restoreOptions() {
+ function resetOptions() {
$this->mOptions = User::getDefaultOptions();
}
}
}
- /**
- * Encode this user's options as a string
- * @return \string Encoded options
- * @private
- */
- function encodeOptions() {
- $this->load();
- if ( is_null( $this->mOptions ) ) {
- $this->mOptions = User::getDefaultOptions();
- }
- $a = array();
- foreach ( $this->mOptions as $oname => $oval ) {
- array_push( $a, $oname.'='.$oval );
- }
- $s = implode( "\n", $a );
- return $s;
- }
-
/**
* Set this user's options from an encoded string
* @param $str \string Encoded options to import
* @private
*/
function decodeOptions( $str ) {
+ if ($str)
+ $this->mOptionsLoaded = true;
+ else
+ return;
+
$this->mOptions = array();
$a = explode( "\n", $str );
foreach ( $a as $s ) {
'user_real_name' => $this->mRealName,
'user_email' => $this->mEmail,
'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
- 'user_options' => $this->encodeOptions(),
+ 'user_options' => '',
'user_touched' => $dbw->timestamp($this->mTouched),
'user_token' => $this->mToken,
'user_email_token' => $this->mEmailToken,
'user_id' => $this->mId
), __METHOD__
);
+
+ $this->saveOptions();
+
wfRunHooks( 'UserSaveSettings', array( $this ) );
$this->clearSharedCache();
$this->getUserPage()->invalidateCache();
'user_email' => $this->mEmail,
'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
'user_real_name' => $this->mRealName,
- 'user_options' => $this->encodeOptions(),
+ 'user_options' => '',
'user_token' => $this->mToken,
'user_registration' => $dbw->timestamp( $this->mRegistration ),
'user_editcount' => 0,
// Clear instance cache other than user table data, which is already accurate
$this->clearInstanceCache();
+
+ $this->saveOptions();
}
/**
$log->addEntry( 'autocreate', $this->getUserPage(), '', array( $this->getId() ) );
return true;
}
+
+ protected function loadOptions() {
+ $this->load();
+ if ($this->mOptionsLoaded || !$this->getId() )
+ return;
+
+ $this->mOptions = self::getDefaultOptions();
+
+ // Load from database
+ $dbr = wfGetDB( DB_SLAVE );
+
+ $res = $dbr->select( 'user_properties',
+ '*',
+ array('up_user' => $this->getId()),
+ __METHOD__
+ );
+
+ while( $row = $dbr->fetchObject( $res ) ) {
+ $this->mOptions[$row->up_property] = $row->up_value;
+ }
+
+ $this->mOptionsLoaded = true;
+
+ wfRunHooks( 'UserLoadOptions', array( $this, &$this->mOptions ) );
+ }
+
+ protected function saveOptions() {
+ $this->loadOptions();
+ $dbw = wfGetDB( DB_MASTER );
+
+ $insert_rows = array();
+
+ $saveOptions = $this->mOptions;
+
+ // Allow hooks to abort, for instance to save to a global profile.
+ // Reset options to default state before saving.
+ if (!wfRunHooks( 'UserSaveOptions', array($this, &$saveOptions) ) )
+ return;
+
+ foreach( $saveOptions as $key => $value ) {
+ if ( is_null(self::getDefaultOption($key)) ||
+ $value != self::getDefaultOption( $key ) ) {
+ $insert_rows[] = array(
+ 'up_user' => $this->getId(),
+ 'up_property' => $key,
+ 'up_value' => $value,
+ );
+ }
+ }
+
+ $dbw->begin();
+ $dbw->delete( 'user_properties', array( 'up_user' => $this->getId() ), __METHOD__ );
+ $dbw->insert( 'user_properties', $insert_rows, __METHOD__ );
+ $dbw->commit();
+ }
+
}