From e9f6ea3492ab337b3479d00cf18c43f0ce27701b Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Fri, 28 May 2021 20:00:46 +0200 Subject: [PATCH] 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 --- extension.json | 2 +- includes/Gadget.php | 11 +++++++++-- includes/GadgetHooks.php | 17 ++++++++--------- tests/phpunit/integration/GadgetHooksTest.php | 8 ++++---- 4 files changed, 22 insertions(+), 16 deletions(-) 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 ); } }