Reduce message parse in GadgetHooks::getPreferences

Multiselect can build by message keys only

This reverts fix for T32182, there is no way to handle the dir on each
item/checkbox at the moment

Bug: T58633
Bug: T278650
Depends-On: Ie983757081dc39f3685ba5b01b02bd124880e1af
Change-Id: Iccd6202c443bd699aa3a911c8ba36a2b7bcdcfed
This commit is contained in:
Umherirrender 2021-04-20 01:13:27 +02:00
parent 8c3115fd86
commit 662c63882c
3 changed files with 20 additions and 15 deletions

View file

@ -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();
}
/**

View file

@ -109,21 +109,19 @@ class GadgetHooks {
&& $gadget->isSkinSupported( $skin )
) {
$gname = $gadget->getName();
# bug 30182: dir="auto" because it's often not translated
$desc = '<span dir="auto">' . $gadget->getDescription() . '</span>';
$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' => '&#160;',
'prefix' => 'gadget-',

View file

@ -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 );
}
}