diff --git a/extension.json b/extension.json index d4cf7e80..6b5016c9 100644 --- a/extension.json +++ b/extension.json @@ -8,7 +8,7 @@ "descriptionmsg": "gadgets-desc", "license-name": "GPL-2.0-or-later", "requires": { - "MediaWiki": ">= 1.35.0" + "MediaWiki": ">= 1.37.0" }, "type": "other", "namespaces": [ diff --git a/includes/Gadget.php b/includes/Gadget.php index 938d4a01..78c98005 100644 --- a/includes/Gadget.php +++ b/includes/Gadget.php @@ -137,18 +137,25 @@ class Gadget { return $this->name; } + /** + * @return string Message key + */ + public function getDescriptionMessageKey() { + return "gadget-{$this->getName()}"; + } + /** * @return string Gadget description parsed into HTML */ public function getDescription() { - return wfMessage( "gadget-{$this->getName()}" )->parse(); + return wfMessage( $this->getDescriptionMessageKey() )->parse(); } /** * @return string Wikitext of gadget description */ public function getRawDescription() { - return wfMessage( "gadget-{$this->getName()}" )->plain(); + return wfMessage( $this->getDescriptionMessageKey() )->plain(); } /** diff --git a/includes/GadgetHooks.php b/includes/GadgetHooks.php index 2e2d9eba..2f501e3e 100644 --- a/includes/GadgetHooks.php +++ b/includes/GadgetHooks.php @@ -109,21 +109,19 @@ class GadgetHooks { && $gadget->isSkinSupported( $skin ) ) { $gname = $gadget->getName(); - # bug 30182: dir="auto" because it's often not translated - $desc = '' . $gadget->getDescription() . ''; - $available[$desc] = $gname; + $available[$gadget->getDescriptionMessageKey()] = $gname; if ( $gadget->isEnabled( $user ) ) { $default[] = $gname; } } } - if ( $section !== '' ) { - $section = wfMessage( "gadget-section-$section" )->parse(); + if ( $available === [] ) { + continue; + } - if ( count( $available ) ) { - $options[$section] = $available; - } + if ( $section !== '' ) { + $options["gadget-section-$section"] = $available; } else { $options = array_merge( $options, $available ); } @@ -140,7 +138,8 @@ class GadgetHooks { $preferences['gadgets'] = [ 'type' => 'multiselect', - 'options' => $options, + 'options-messages' => $options, + 'options-messages-parse' => true, 'section' => 'gadgets', 'label' => ' ', 'prefix' => 'gadget-', diff --git a/tests/phpunit/integration/GadgetHooksTest.php b/tests/phpunit/integration/GadgetHooksTest.php index 7e2f14df..8b034b18 100644 --- a/tests/phpunit/integration/GadgetHooksTest.php +++ b/tests/phpunit/integration/GadgetHooksTest.php @@ -52,10 +52,10 @@ class GadgetHooksTest extends MediaWikiIntegrationTestCase { $repo->definitionCache = $gadgets; GadgetHooks::getPreferences( $this->user, $prefs ); - $options = $prefs['gadgets']['options']; - $this->assertArrayNotHasKey( '⧼gadget-section-remove-section⧽', $options, + $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 ); + $this->assertArrayHasKey( 'gadget-section-keep-section1', $options ); + $this->assertArrayHasKey( 'gadget-section-keep-section2', $options ); } }