diff options
author | Gergő Tisza <tgr.huwiki@gmail.com> | 2024-01-15 19:33:26 -0800 |
---|---|---|
committer | Gergő Tisza <tgr.huwiki@gmail.com> | 2024-01-15 20:25:25 -0800 |
commit | 044910ae71b03f3cde968b663ff98914f02271b4 (patch) | |
tree | 99d60cc0b8e01f5ffea9384e063dd471abca0003 /includes | |
parent | 015811790f4c6e597a6ab17c883a1ef4afaf4981 (diff) | |
download | mediawikicore-044910ae71b03f3cde968b663ff98914f02271b4.tar.gz mediawikicore-044910ae71b03f3cde968b663ff98914f02271b4.zip |
user preferences: Add some information about types to the phpdoc
User options saved to the database and retrieved get converted
to strings, but defaults and set but not yet saved vaues don't.
This behavior can be confusing.
When a value equal to the default is set for a given user, that
value won't be written to the database; defaults are represented
by the lack of a database row. This behavior can also be
confusing.
Update the phpdoc of some user preferences related methods and
variables to make these things clearer.
Change-Id: I32a18b30f007c97015e6d641379ce60ab6ac7ed7
Diffstat (limited to 'includes')
-rw-r--r-- | includes/MainConfigSchema.php | 10 | ||||
-rw-r--r-- | includes/user/Options/UserOptionsLookup.php | 4 | ||||
-rw-r--r-- | includes/user/Options/UserOptionsManager.php | 19 |
3 files changed, 31 insertions, 2 deletions
diff --git a/includes/MainConfigSchema.php b/includes/MainConfigSchema.php index 1a9bd257175f..93183db1203e 100644 --- a/includes/MainConfigSchema.php +++ b/includes/MainConfigSchema.php @@ -7514,6 +7514,15 @@ class MainConfigSchema { * * For instance, to disable editing on double clicks: * $wgDefaultUserOptions ['editondblclick'] = 0; + * + * To save storage space, no user_properties row will be stored for users with the + * default setting for a given option, even if the user manually selects that option. + * This means that a change to the defaults will change the setting for all users who + * have been using the default setting; there is no way for users to opt out of this. + * $wgConditionalUserOptions can be used to change the default value for future users + * only. + * + * @see self::ConditionalUserOptions */ public const DefaultUserOptions = [ 'default' => @@ -7615,6 +7624,7 @@ class MainConfigSchema { * * CUDCOND_AFTER: user registered after given timestamp (args: string $timestamp) * * @since 1.42 + * @see self::DefaultUserOptions */ public const ConditionalUserOptions = [ 'default' => [], diff --git a/includes/user/Options/UserOptionsLookup.php b/includes/user/Options/UserOptionsLookup.php index 24f43b40d7c5..065944b14a9d 100644 --- a/includes/user/Options/UserOptionsLookup.php +++ b/includes/user/Options/UserOptionsLookup.php @@ -68,7 +68,9 @@ abstract class UserOptionsLookup implements IDBAccessObject { * @param mixed|null $defaultOverride A default value returned if the option does not exist * @param bool $ignoreHidden Whether to ignore the effects of $wgHiddenPrefs * @param int $queryFlags A bit field composed of READ_XXX flags - * @return mixed|null User's current value for the option + * @return mixed|null User's current value for the option, + * Note that while option values retrieved from the database are always strings, default + * values and values set within the current request and not yet saved may be of another type. * @see getBoolOption() * @see getIntOption() */ diff --git a/includes/user/Options/UserOptionsManager.php b/includes/user/Options/UserOptionsManager.php index 0c899224ce25..d7d1d4059aa7 100644 --- a/includes/user/Options/UserOptionsManager.php +++ b/includes/user/Options/UserOptionsManager.php @@ -205,9 +205,26 @@ class UserOptionsManager extends UserOptionsLookup { * * You need to call saveOptions() to actually write to the database. * + * $val should be null or a string. Other types are accepted for B/C with legacy + * code but can result in surprising behavior and are discouraged. Values are always + * stored as strings in the database, so if you pass a non-string value, it will be + * eventually converted; but before the call to saveOptions(), getOption() will return + * the passed value from instance cache without any type conversion. + * + * A null value means resetting the option to its default value (removing the user_properties + * row). Passing in the same value as the default value fo the user has the same result. + * This behavior supports some level of type juggling - e.g. if the default value is 1, + * and you pass in '1', the option will be reset to its default value. + * + * When an option is reset to its default value, that means whenever the default value + * is changed in the site configuration, the user preference for this user will also change. + * There is no way to set a user preference to be the same as the default but avoid it + * changing when the default changes. You can instead use $wgConditionalUserOptions to + * split the default based on user registration date. + * * @param UserIdentity $user * @param string $oname The option to set - * @param mixed $val New value to set + * @param mixed $val New value to set. */ public function setOption( UserIdentity $user, string $oname, $val ) { // Explicitly NULL values should refer to defaults |