From eaa1fea8906b759eb39e11006ae5792ed6145a9b Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Fri, 28 Jun 2024 11:41:53 +0200 Subject: [PATCH] Fix incomplete gender support for user group changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This affects primarily the message "notification-header-user-rights-add-only" which is very priminently seen by every new editor that made their first few edits and gets promoted to the next user group a few days later. Turns out the code was just incomplete. All the information about the user and their gender is already there, it was just not forwarded correctly. Notice there are two messages: * "group-…" messages don't have gender support. This is the (ideally) gender neutral name of the group. Meant to be used as e.g. section heading for a list of users. * "group-…-member" is the same with gender support. To be used in all contexts that are about a single, specific user with known gender. Which is exactly what's happening here. Turns out we can even use a neat convenience function from the Language class that does exactly what we need. I can't tell why but the array_values is apparently critical. Originally added via I49b5fe5. It can't hurt so I keep it. Bug: T368249 Change-Id: I53c028375d77c93f399538fd38aa8f8af30934b0 --- .../EchoUserRightsPresentationModel.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/includes/Formatters/EchoUserRightsPresentationModel.php b/includes/Formatters/EchoUserRightsPresentationModel.php index 7338ea258..3398cb4e9 100644 --- a/includes/Formatters/EchoUserRightsPresentationModel.php +++ b/includes/Formatters/EchoUserRightsPresentationModel.php @@ -20,15 +20,15 @@ class EchoUserRightsPresentationModel extends EchoEventPresentationModel { [ $formattedName, $genderName ] = $this->getAgentForOutput(); $add = array_map( [ $this->language, 'embedBidi' ], - $this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'add', [] ) ) ) + $this->getLocalizedGroupNames( $this->event->getExtraParam( 'add', [] ), $genderName ) ); $remove = array_map( [ $this->language, 'embedBidi' ], - $this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'remove', [] ) ) ) + $this->getLocalizedGroupNames( $this->event->getExtraParam( 'remove', [] ), $genderName ) ); $expiryChanged = array_map( [ $this->language, 'embedBidi' ], - $this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'expiry-changed', [] ) ) ) + $this->getLocalizedGroupNames( $this->event->getExtraParam( 'expiry-changed', [] ), $genderName ) ); if ( $expiryChanged ) { $msg = $this->msg( 'notification-header-user-rights-expiry-change' ); @@ -72,11 +72,16 @@ class EchoUserRightsPresentationModel extends EchoEventPresentationModel { return false; } - private function getLocalizedGroupNames( array $names ) { - return array_map( function ( $name ) { - $msg = $this->msg( 'group-' . $name ); - return $msg->isBlank() ? $name : $msg->text(); - }, $names ); + /** + * @param string[] $names + * @param string $genderName + * @return string[] + */ + private function getLocalizedGroupNames( array $names, string $genderName ) { + return array_map( + fn ( $name ) => $this->language->getGroupMemberName( $name, $genderName ), + array_values( $names ) + ); } public function getPrimaryLink() {