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",
"UserGetDefaultOptions": "GadgetHooks::userGetDefaultOptions",
"GetPreferences": "GadgetHooks::getPreferences",
"PreferencesGetLegend": "GadgetHooks::onPreferencesGetLegend",
"ResourceLoaderRegisterModules": "GadgetHooks::registerModules",
"wgQueryPages": "GadgetHooks::onwgQueryPages",
"DeleteUnknownPreferences": "GadgetHooks::onDeleteUnknownPreferences"

View file

@ -93,13 +93,8 @@ class GadgetHooks {
return;
}
$preferences['gadgets-intro'] = [
'type' => 'info',
'default' => wfMessage( 'gadgets-prefstext' )->parseAsBlock(),
'section' => 'gadgets',
'raw' => true,
];
$options = [];
$default = [];
$skin = RequestContext::getMain()->getSkin();
foreach ( $gadgets as $section => $thisSection ) {
$available = [];
@ -114,37 +109,43 @@ class GadgetHooks {
&& $gadget->isSkinSupported( $skin )
) {
$gname = $gadget->getName();
$sectionLabelMsg = "gadget-section-$section";
$preferences["gadget-$gname"] = [
'type' => 'check',
'label-message' => $gadget->getDescriptionMessageKey(),
'section' => $section !== '' ? "gadgets/$sectionLabelMsg" : 'gadgets',
'default' => $gadget->isEnabled( $user ),
'noglobal' => true,
];
$available[$gadget->getDescriptionMessageKey()] = $gname;
if ( $gadget->isEnabled( $user ) ) {
$default[] = $gname;
}
}
}
}
}
/**
* PreferencesGetLegend hook handler.
*
* 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
* that would have to be moved if the message keys changed.
*
* @param HTMLForm $form the HTMLForm object. This is a ContextSource as well
* @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() );
if ( $available === [] ) {
continue;
}
if ( $section !== '' ) {
$options["gadget-section-$section"] = $available;
} else {
$options = array_merge( $options, $available );
}
}
$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;
GadgetHooks::getPreferences( $this->user, $prefs );
$this->assertArrayHasKey( 'gadget-bar', $prefs );
$this->assertArrayNotHasKey( 'gadget-baz', $prefs,
'Must not show unavailable gadgets' );
$this->assertEquals( 'gadgets/gadget-section-keep-section2', $prefs['gadget-quux']['section'] );
$options = $prefs['gadgets']['options-messages'];
$this->assertArrayNotHasKey( 'gadget-section-remove-section', $options,
'Must not show empty sections' );
$this->assertArrayHasKey( 'gadget-section-keep-section1', $options );
$this->assertArrayHasKey( 'gadget-section-keep-section2', $options );
}
}