Revert "Make each gadget a separate preference, instead of one huge multiselect"

This reverts commit 82281d82d0.

Bug: T126962
Bug: T292777
Change-Id: I7c858b8c4bc12626ea1d53374ea4d75862f684ff
This commit is contained in:
Krinkle 2021-10-07 19:52:18 +00:00
parent 82281d82d0
commit 7c4ac597e2
3 changed files with 40 additions and 39 deletions

View file

@ -90,7 +90,6 @@
"EditFilterMergedContent": "GadgetHooks::onEditFilterMergedContent", "EditFilterMergedContent": "GadgetHooks::onEditFilterMergedContent",
"UserGetDefaultOptions": "GadgetHooks::userGetDefaultOptions", "UserGetDefaultOptions": "GadgetHooks::userGetDefaultOptions",
"GetPreferences": "GadgetHooks::getPreferences", "GetPreferences": "GadgetHooks::getPreferences",
"PreferencesGetLegend": "GadgetHooks::onPreferencesGetLegend",
"ResourceLoaderRegisterModules": "GadgetHooks::registerModules", "ResourceLoaderRegisterModules": "GadgetHooks::registerModules",
"wgQueryPages": "GadgetHooks::onwgQueryPages", "wgQueryPages": "GadgetHooks::onwgQueryPages",
"DeleteUnknownPreferences": "GadgetHooks::onDeleteUnknownPreferences" "DeleteUnknownPreferences": "GadgetHooks::onDeleteUnknownPreferences"

View file

@ -93,13 +93,8 @@ class GadgetHooks {
return; return;
} }
$preferences['gadgets-intro'] = [ $options = [];
'type' => 'info', $default = [];
'default' => wfMessage( 'gadgets-prefstext' )->parseAsBlock(),
'section' => 'gadgets',
'raw' => true,
];
$skin = RequestContext::getMain()->getSkin(); $skin = RequestContext::getMain()->getSkin();
foreach ( $gadgets as $section => $thisSection ) { foreach ( $gadgets as $section => $thisSection ) {
$available = []; $available = [];
@ -114,37 +109,43 @@ class GadgetHooks {
&& $gadget->isSkinSupported( $skin ) && $gadget->isSkinSupported( $skin )
) { ) {
$gname = $gadget->getName(); $gname = $gadget->getName();
$sectionLabelMsg = "gadget-section-$section"; $available[$gadget->getDescriptionMessageKey()] = $gname;
if ( $gadget->isEnabled( $user ) ) {
$preferences["gadget-$gname"] = [ $default[] = $gname;
'type' => 'check', }
'label-message' => $gadget->getDescriptionMessageKey(),
'section' => $section !== '' ? "gadgets/$sectionLabelMsg" : 'gadgets',
'default' => $gadget->isEnabled( $user ),
'noglobal' => true,
];
} }
} }
}
}
/** if ( $available === [] ) {
* PreferencesGetLegend hook handler. continue;
* }
* Used to override the subsection heading labels for the gadget groups. The default message would
* be "prefs-$key", but we've previously used different messages, and they have on-wiki overrides if ( $section !== '' ) {
* that would have to be moved if the message keys changed. $options["gadget-section-$section"] = $available;
* } else {
* @param HTMLForm $form the HTMLForm object. This is a ContextSource as well $options = array_merge( $options, $available );
* @param string $key the section name }
* @param string &$legend the legend text. Defaults to wfMessage( "prefs-$key" )->text() but may
* be overridden
* @return bool|void True or no return value to continue or false to abort
*/
public static function onPreferencesGetLegend( $form, $key, &$legend ) {
if ( str_starts_with( $key, 'gadget-section-' ) ) {
$legend = new OOUI\HtmlSnippet( $form->msg( $key )->parse() );
} }
$preferences['gadgets-intro'] =
[
'type' => 'info',
'default' => wfMessage( 'gadgets-prefstext' )->parseAsBlock(),
'section' => 'gadgets',
'raw' => true,
];
$preferences['gadgets'] =
[
'type' => 'multiselect',
'options-messages' => $options,
'options-messages-parse' => true,
'section' => 'gadgets',
'label' => ' ',
'prefix' => 'gadget-',
'default' => $default,
'noglobal' => true,
];
} }
/** /**

View file

@ -52,9 +52,10 @@ class GadgetHooksTest extends MediaWikiIntegrationTestCase {
$repo->definitionCache = $gadgets; $repo->definitionCache = $gadgets;
GadgetHooks::getPreferences( $this->user, $prefs ); GadgetHooks::getPreferences( $this->user, $prefs );
$this->assertArrayHasKey( 'gadget-bar', $prefs ); $options = $prefs['gadgets']['options-messages'];
$this->assertArrayNotHasKey( 'gadget-baz', $prefs, $this->assertArrayNotHasKey( 'gadget-section-remove-section', $options,
'Must not show unavailable gadgets' ); 'Must not show empty sections' );
$this->assertEquals( 'gadgets/gadget-section-keep-section2', $prefs['gadget-quux']['section'] ); $this->assertArrayHasKey( 'gadget-section-keep-section1', $options );
$this->assertArrayHasKey( 'gadget-section-keep-section2', $options );
} }
} }