Page MenuHomePhabricator

Add message parameter types for user groups, PageIdentity, LinkTarget, and UserIdentity.
Open, Needs TriagePublic

Description

We frequently have a need to use UserIdentity, PageIdentity, LinkTarget and user groups as message parameters. But since they are not supported directly, we are converting them to strings first. This conversion requires context (customized namespace names, localized group names, etc).

Code that constructs messages (internationalization) should not do such formatting (localization). This code often lacks the context for correct localization (such as user preferences) and goes to global state to acquire it.

To solve this problem, we should support user groups, PageIdentity, LinkTarget, and UserIdentity as message parameters. Use groups will have to be encoded as an array, in the same way we encode parameters that represent e.g. a duration, with the array key identifying the value type: [ 'user-group' => $groupName ]. We could do the same for PageIdentity, LinkTarget, and UserIdentity, or we could support them directly, and format them based on their type.

The following places will have to be touched to support this:

  • Message::extractParam. This is where the actual formatting logic goes. Message will have to use the global service container instance to access the NamespaceInfo service, but that's no worse than the other things that happen in Message. This will be resolved in a future refactoring when we convert from Message to MessageValue.
  • MediaWiki\Message\Converter and MediaWiki\Message\ParamType will need to know about the new types. Perhaps we need a new MessageParam subclass (or several). MessageValue::params(...) may need to know about these types as well.
  • ApiResult::validateValue() will need to be able to support the types of value we add. user group names are strings, and UserIdentity can be converted to a string without loss. But a TitleFormatter will be needed to turn PageIdentity and LinkTarget into their external representation.

The parameter values should be formatted follows:

  • PageIdentity and LinkTarget: TitleFormatter::getPrefixedText(). We may want to generate links, but let's just do the plain name as a default for now.
  • On UserIdentity we can just call getName. We may want to generate a link to the user page, but let's leave that for later.
  • For user groups, use the static UserGroupMembership::getGroupName( $group ) method. That should become a service object, but we don't have to worry about that right now.

Event Timeline

Change 675919 had a related patch set uploaded (by Ppchelko; author: Ppchelko):

[mediawiki/core@master] Add Message/MessageValue datetime parameter type

https://gerrit.wikimedia.org/r/675919

Change 675919 merged by jenkins-bot:

[mediawiki/core@master] Add Message/MessageValue datetime parameter types

https://gerrit.wikimedia.org/r/675919

Change 730631 had a related patch set uploaded (by TChin; author: TChin):

[mediawiki/core@master] [WIP] Add message parameter type for User Groups

https://gerrit.wikimedia.org/r/730631

Change 730631 merged by jenkins-bot:

[mediawiki/core@master] Add message parameter type for User Groups

https://gerrit.wikimedia.org/r/730631

Change 731163 had a related patch set uploaded (by TChin; author: TChin):

[mediawiki/core@master] [WIP] Add Message/MessageValue user group member parameter type

https://gerrit.wikimedia.org/r/731163

Change 731163 merged by jenkins-bot:

[mediawiki/core@master] Add Message/MessageValue user group member parameter type

https://gerrit.wikimedia.org/r/731163

Aklapper added a subscriber: ArielGlenn.

@ArielGlenn: Per emails from Sep18 and Oct20 and https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup , I am resetting the assignee of this task because there has not been progress lately (please correct me if I am wrong!). Resetting the assignee avoids the impression that somebody is already working on this task. It also allows others to potentially work towards fixing this task. Please claim this task again when you plan to work on it (via Add Action... → Assign / Claim in the dropdown menu) - it would be welcome. Thanks for your understanding!

Change #1036759 had a related patch set uploaded (by C. Scott Ananian; author: Bartosz Dziewoński):

[mediawiki/core@master] Remove Message::objectParams() and related code

https://gerrit.wikimedia.org/r/1036759

We deprecated the 'object' parameter type used by this in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1036758 as it was unused in practice.

Change #1036759 merged by jenkins-bot:

[mediawiki/core@master] Remove Message::objectParams() and related code

https://gerrit.wikimedia.org/r/1036759