From 0659e174c9eb2bfdbcce767d5aa83079ab5c1bf9 Mon Sep 17 00:00:00 2001 From: Jon Robson Date: Wed, 16 Feb 2022 09:42:32 -0800 Subject: [PATCH] Allow msg key to be overridable Minerva already overrides the text label for the Home menu item. To allow other extensions to override it again, we can also consult the msg key. Bug: T291568 Change-Id: I3107a6d1e6ace26c7ab9c49c49768d2adcda8792 --- includes/Menu/Definitions.php | 3 ++- includes/Menu/Main/BuilderUtil.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/includes/Menu/Definitions.php b/includes/Menu/Definitions.php index 1f2f70202..e21d6ef49 100644 --- a/includes/Menu/Definitions.php +++ b/includes/Menu/Definitions.php @@ -26,6 +26,7 @@ use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry; use MediaWiki\Special\SpecialPageFactory; use MediaWiki\User\UserIdentity; use MediaWiki\User\UserOptionsLookup; +use Message; use MWException; use SpecialPage; use Title; @@ -90,7 +91,7 @@ final class Definitions { /** * Perform message localization * @param string $key to localize - * @return string + * @return Message */ public function msg( string $key ) { return $this->context->msg( $key ); diff --git a/includes/Menu/Main/BuilderUtil.php b/includes/Menu/Main/BuilderUtil.php index e17460428..ce295168a 100644 --- a/includes/Menu/Main/BuilderUtil.php +++ b/includes/Menu/Main/BuilderUtil.php @@ -85,7 +85,7 @@ final class BuilderUtil { foreach ( $navigationTools as $item ) { $id = $item['id'] ?? null; if ( $id && isset( $entryDefinitions[ $id ] ) ) { - foreach ( [ 'icon', 'class', 'href' ] as $overridableKey ) { + foreach ( [ 'icon', 'class', 'href', 'msg' ] as $overridableKey ) { $override = $item[ $overridableKey ] ?? null; if ( $override ) { $entryDefinitions[$id][$overridableKey] = $override; @@ -95,9 +95,19 @@ final class BuilderUtil { } // Build the menu foreach ( $entryDefinitions as $definition ) { + $msgKey = $definition['msg'] ?? null; + $text = null; + if ( $msgKey ) { + $msg = $definitions->msg( $msgKey ); + $text = $msg->exists() ? $msg->text() : null; + } + if ( !$text ) { + $text = $definition['text']; + } + $entry = SingleMenuEntry::create( $definition['name'], - $definition['text'], + $text, $definition['href'], $definition['class'], $definition['icon']