Page MenuHomePhabricator

Allow functions in $wgGrammarForms
Closed, DeclinedPublic

Description

To make custom grammar settings more flexible, allow callables in the configuration variable $wgGrammarForms, e.g.:

$wgGrammarForms ['ru'] ['plural'] = function (string $singular): string {
    …
    return $plural;
};

P.S. Revoked as `{{grammar}}` has also to work in JavaScript.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 19 2018, 2:01 AM

Why do you want them to be "more flexible"?

alex-mashin added a comment.EditedFeb 19 2018, 3:00 PM

To be able to look up in a dictionary, for example. Or to programmatically implement inflectional paradigms that are more complicated than regular expressions.

Change 412726 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Alexander I. Mashin):
[mediawiki/core@master] Bug T187670: Allow functions in $wgGrammarForms

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

I don't think this is a good idea for two reasons:

  1. There is no way we can support custom PHP code in JavaScript.
  2. In LocalSettings.php, you already know the words that are going to be used (just the sitenames). To accept arbitrary input some other mechanism should be used.
alex-mashin added a comment.EditedFeb 20 2018, 12:22 PM
  1. Who talks about JavaScript? $wgGrammarForms is meant to be set in LocalSettings.php.
  2. How on earth can I know when and where wiki contributors will use {{grammar:}}? They can justifiably do it anywhere; in templates meant for the main namespace, for example.
  1. Who talks about JavaScript? $wgGrammarForms is meant to be set in LocalSettings.php.

{{GRAMMAR}} is used both in JavaScript and PHP when parsing messages.

  1. How on earth can I know when and where wiki contributors will use {{grammar:}}? They can justifiably do it anywhere; in templates meant for the main namespace, for example.

It is not forbidden, but like many other things, that is not the intended use case and not supported by us.

alex-mashin added a comment.EditedFeb 21 2018, 3:16 PM

If {{GRAMMAR}} is indeed called client-side, then it's pointless.

P.S. Cannot figure out how to abandon the patch.

alex-mashin closed this task as Declined.Feb 22 2018, 3:37 PM
alex-mashin updated the task description. (Show Details)