From 7c4ac597e2ce5ebfb5e17903a9cdac73e086f1e1 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Thu, 7 Oct 2021 19:52:18 +0000 Subject: [PATCH] Revert "Make each gadget a separate preference, instead of one huge multiselect" This reverts commit 82281d82d0898b58dade7c47873bc4b06e237388. Bug: T126962 Bug: T292777 Change-Id: I7c858b8c4bc12626ea1d53374ea4d75862f684ff --- extension.json | 1 - includes/GadgetHooks.php | 69 ++++++++++--------- tests/phpunit/integration/GadgetHooksTest.php | 9 +-- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/extension.json b/extension.json index 0351f9c9..6b5016c9 100644 --- a/extension.json +++ b/extension.json @@ -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" diff --git a/includes/GadgetHooks.php b/includes/GadgetHooks.php index 56147e92..830e06a4 100644 --- a/includes/GadgetHooks.php +++ b/includes/GadgetHooks.php @@ -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, + ]; } /** diff --git a/tests/phpunit/integration/GadgetHooksTest.php b/tests/phpunit/integration/GadgetHooksTest.php index e1924f71..28c1f026 100644 --- a/tests/phpunit/integration/GadgetHooksTest.php +++ b/tests/phpunit/integration/GadgetHooksTest.php @@ -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 ); } }