refactor: move theme preference underneath skin preferences

This commit is contained in:
alistair3149 2021-01-10 17:38:11 -05:00
parent 88ecd756e2
commit 5a8c15f3c2
No known key found for this signature in database
GPG key ID: 94D081060FD3DD9C
4 changed files with 50 additions and 33 deletions

View file

@ -10,8 +10,8 @@
"citizen-footer-desc": "Bearbeiten Sie diesen Text auf MediaWiki:Citizen-footer-desc", "citizen-footer-desc": "Bearbeiten Sie diesen Text auf MediaWiki:Citizen-footer-desc",
"citizen-footer-tagline": "Bearbeiten Sie diesen Text auf MediaWiki:Citizen-footer-tagline", "citizen-footer-tagline": "Bearbeiten Sie diesen Text auf MediaWiki:Citizen-footer-tagline",
"citizen-upo-style": "Skin Citizen Farbschema", "prefs-citizen-theme-label": "Thema",
"citizen-upo-style-auto": "Automatisch", "prefs-citizen-theme-option-auto": "Automatisch",
"citizen-upo-style-light": "Hell", "prefs-citizen-theme-option-light": "Hell",
"citizen-upo-style-dark": "Dunkel" "prefs-citizen-theme-option-dark": "Dunkel"
} }

View file

@ -19,8 +19,8 @@
"citizen-search-fulltext": "Search pages containing", "citizen-search-fulltext": "Search pages containing",
"citizen-upo-style": "Skin Citizen Color Scheme", "prefs-citizen-theme-label": "Theme",
"citizen-upo-style-auto": "Auto", "prefs-citizen-theme-option-auto": "Auto",
"citizen-upo-style-light": "Light", "prefs-citizen-theme-option-light": "Light",
"citizen-upo-style-dark": "Dark" "prefs-citizen-theme-option-dark": "Dark"
} }

View file

@ -16,8 +16,8 @@
"citizen-footer-tagline": "Edit this text on MediaWiki:Citizen-footer-tagline", "citizen-footer-tagline": "Edit this text on MediaWiki:Citizen-footer-tagline",
"citizen-search-fulltext": "Fulltext search suggestion", "citizen-search-fulltext": "Fulltext search suggestion",
"citizen-upo-style": "Skin Citizen Color Scheme", "prefs-citizen-theme-label": "Label for the theme dropdown in Special:Preferences",
"citizen-upo-style-auto": "Auto", "prefs-citizen-theme-option-auto": "Auto",
"citizen-upo-style-light": "Light", "prefs-citizen-theme-option-light": "Light",
"citizen-upo-style-dark": "Dark" "prefs-citizen-theme-option-dark": "Dark"
} }

View file

@ -154,29 +154,46 @@ class CitizenHooks {
} }
/** /**
* @param User $user * Add Citizen preferences to the user's Special:Preferences page directly underneath skins.
* @param array &$preferences * Based on Vector's implementation
*
* @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, &$preferences ) { public static function onGetPreferences( $user, &$prefs ) {
$options = MediaWikiServices::getInstance() // Preferences to add.
->getUserOptionsLookup() $citizenPrefs = [
->getOptions( $user ); 'CitizenThemeUser' => [
'type' => 'select',
if ( $options['skin'] !== 'citizen' ) { // Droptown title
return; 'label-message' => 'prefs-citizen-theme-label',
} // The tab location and title of the section to insert the checkbox. The bit after the slash
// indicates that a prefs-skin-prefs string will be provided.
// A checkbox 'section' => 'rendering/skin/skin-prefs',
$preferences['CitizenThemeUser'] = [ 'options' => [
'type' => 'select', wfMessage( 'prefs-citizen-theme-option-auto' )->escaped() => 'auto',
'label-message' => 'citizen-upo-style', wfMessage( 'prefs-citizen-theme-option-light' )->escaped() => 'light',
'section' => 'rendering/skin', wfMessage( 'prefs-citizen-theme-option-dark' )->escaped() => 'dark',
'options' => [ ],
wfMessage( 'citizen-upo-style-auto' )->escaped() => 'auto', 'default' => 'auto',
wfMessage( 'citizen-upo-style-light' )->escaped() => 'light', // Only show this section when the Citizen skin is checked. The JavaScript client also uses
wfMessage( 'citizen-upo-style-dark' )->escaped() => 'dark', // this state to determine whether to show or hide the whole section.
'hide-if' => [ '!==', 'wpskin', 'citizen' ],
], ],
'default' => $options['CitizenThemeUser'] ?? 'auto'
]; ];
// Seek the skin preference section to add Citizen preferences just below it.
$skinSectionIndex = array_search( 'skin', array_keys( $prefs ) );
if ( $skinSectionIndex !== false ) {
// Skin preference section found. Inject Citizen skin-specific preferences just below it.
// This pattern can be found in Popups too. See T246162.
$citizenSectionIndex = $skinSectionIndex + 1;
$prefs = array_slice( $prefs, 0, $citizenSectionIndex, true )
+ $citizenPrefs
+ array_slice( $prefs, $citizenSectionIndex, null, true );
} else {
// Skin preference section not found. Just append Citizen skin-specific preferences.
$prefs += $citizenPrefs;
}
} }
} }