== Background
As spiked in T237561, add a Vector skin user preference:
[] Add a configuration for controlling whether to display the new Vector preferences section or not, something like `$wgVectorShowPreferences`. This flag will initially be used to prevent the legacy option from being presented until some new user visible functionality is actually available in Vector. The initial rollout to test wikis is planned to coincide with the header and logo changes. The default skin value should be `true` so that third-parties get the functionality by default. A patch to mediawiki-config should be made to set the default to `false` on all projects and all wikis.
[] Add a configuration for controlling the default Vector version preference, something like `$wgVectorDefaultSkinVersion`. When determining whether to display legacy Vector (version `'1'`) or modern Vector (version `'2'`), the value of `$wgVectorDefaultSkinVersion` will be used when the user has not made a preference selection. The default skin value should be `2` so that third-parties get the modern functionality by default. A patch to mediawiki-config should be made to set the default to `1` on all projects and all wikis.
[] Add a configuration for controlling the default Vector version preference for new accounts, something like `$wgVectorDefaultSkinVersionForNewAccounts`. This configuration will be used to control the skin version set for newly created accounts. The default skin value should be `2` so that third-parties get the modern functionality by default. A patch to mediawiki-config should be made to set the default to `1` on all projects and all wikis.
[] Add hooks:
- [] `onGetPreferences()`: This hook will actually show (or not show) the preference. The preference should appear in a new section below the skins section. The whole section should be shown when the Vector skin is selected under skin preferences and `$wgVectorShowPreferences` is `true`, and be hidden otherwise. An example showing / hiding just a single checkbox:
```lang=php,lines=15,name=onGetPreferences()
private const SKIN_PREFERENCES_SECTION = 'rendering/vector';
/**
* Add Vector preferences to the user's Special:Preferences page directly underneath skins.
*
* @param User $user User whose preferences are being modified.
* @param array[] &$prefs Preferences description array, to be fed to a HTMLForm object.
*/
public static function onGetPreferences( User $user, array &$prefs ) {
// [todo] early exit if not configured to show Vector preferences.
$pref = [
'type' => 'toggle',
'label-message' => 'skinname-vector-1',
'help-message' => 'vector-1-skin-desc',
'section' => self::SKIN_PREFERENCES_SECTION,
'hide-if' => [ '!==', 'wpskin', 'vector' ]
];
$skinPosition = array_search( 'skin', array_keys( $prefs ) );
$vectorPrefs = [
Constants::PREF_KEY_SKIN_VERSION => $pref,
];
if ( $skinPosition !== false ) {
$prefs = array_splice( $prefs, $skinPosition + 1, 0, $vectorPrefs );
} else {
$prefs += $vectorPrefs;
}
}
```
Which looks like:
Shown (Vector skin selected):
{F31503930 width=512}
Hidden (Non-Vector skin selected):
{F31503931 width=512}
- [] `onUserGetDefaultOptions()`. Something like:
```lang=php,lines=15,name=onUserGetDefaultOptions()
/**
* Called whenever a user wants to reset their preferences.
*
* @param array &$defaultOptions
*/
public static function onUserGetDefaultOptions( array &$defaultOptions ) {
/** @var Config $config */
$config = MediaWikiServices::getInstance()->getService( Constants::SERVICE_CONFIG );
$default = $config->get( Constants::CONFIG_KEY_SKIN_VERSION ); // [todo] actually use the configuration for user default value here.
$defaultOptions[ Constants::PREF_KEY_SKIN_VERSION ] = $default;
}
```
- [] `onLocalUserCreated()`: E.g.:
```lang=php,lines=15,name=onLocalUserCreated()
/**
* Called one time when initializing a users preferences for a newly created account.
*
* @param User $user Newly created user object.
* @param bool $isAutoCreated
*/
public static function onLocalUserCreated( User $user, $isAutoCreated ) {
$user->setOption( Constants::PREF_KEY_SKIN_VERSION, Constants::SKIN_VERSION_MASTER ); // [todo] use config for new account default value here.
}
```
- [] `onResourceLoaderGetConfigVars()`: Present the configs as needed to the client. At least `$wgVectorSkinVersion` will be needed. See PopupHooks.php for an example. `onMakeGlobalVariablesScript()` may also be needed.
As an aside and not a requirement, additional modern Vector-only options may appear here. That is, these are options that would only appear if legacy mode was disabled. These could use something like `'hide-if' => [ '!==', 'wpskinVersion', '1' ]` to control whether they appear in this section or not.
=== AC
todo: get copy and confirm mediawiki-config default values with Olga. Do we want to note under the checkbox that skin preview uses the stored / default value of skin version?
todo: other AC
[] Preference should apply in an identical way to skin preference
[] Copy
Button: Use Legacy Vector
Text: Over the next few years, we will be gradually updating the Vector skin. Legacy Vector will allow you to view the old version of Vector (as of December 2019). To learn more about the updates, go to our project page.
=== QA
todo
=== Signoff criteria
[] Make a task for identifying and adding global preference behavior