diff --git a/includes/Gadget.php b/includes/Gadget.php index 52f39f6f..6fc9e9a9 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..07202eed 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,7 @@ class GadgetHooks { $preferences['gadgets'] = [ 'type' => 'multiselect', - 'options' => $options, + 'options-messages' => $options, '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 ); } }