Reduce message parse in GadgetHooks::getPreferences (second time)

Multiselect can build by message keys only and allows to parse them.

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

Reintroduce Iccd6202c443bd699aa3a911c8ba36a2b7bcdcfed (reverted by
I1cf3c7c61e9e90567587350639590691add1af34)

Bug: T58633
Bug: T278650
Depends-On: I8f52f21ae2641ddcad1aa85ce6bf14de1a09ab4b
Change-Id: If71008195f58faff9f302f7ea2bf9dbb1a527844
This commit is contained in:
Umherirrender 2021-05-28 20:00:46 +02:00
parent 70579af3fe
commit e9f6ea3492
4 changed files with 22 additions and 16 deletions

View file

@ -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": [

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 ( count( $available ) ) {
$options[$section] = $available;
if ( $available === [] ) {
continue;
}
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' => '&#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 );
}
}