Page MenuHomePhabricator

Add 'date', 'time' and 'dateTime' param types to Message class
Open, LowPublic

Description

We currently have already some date/time related message parameter types such as durationParams, timeperiodParams and more. Often, we have time stamps that need to be inserted into messages in parts or as a whole. They are formatted via Language::timeAndDate(...), Language::date(...) and Language::time(...). At the moment that happens individually before each invocation of wfMessage(...). Such repetitions are tedious, unnecessary and add to code clutter. So, let us introduce:

  • wfMessage(...)->dateParams(...)
  • wfMessage(...)->timeParams(...)

appending date and time parametes to the list of message parameters, and

  • wfMessage(...)->dateTimeParams(...)

which appends three message parameters per function parameter, which are date/time, date, and time, respectively.

The latter follows the advice https://www.mediawiki.org/wiki/Localisation#Separate_times_from_dates_in_sentences saying:

Some languages have to insert something between a date and a time which grammatically depends on other words in a sentence. Thus, they will not be able to use date/time combined. Others may find the combination convenient. Thus it is usually the best choice to supply three parameter values (date/time, date, time) in such cases, and in each translation leave either the first one or last two unused as needed.

Details

Event Timeline

Purodha claimed this task.
Purodha raised the priority of this task from to Needs Triage.
Purodha updated the task description. (Show Details)
Purodha subscribed.

Change 267669 had a related patch set uploaded (by Purodha):
Message class: add date/time parameter methods

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

Various reviewers have expressed doubts on the usefulness/scope of the patch, can we get some clarity on what we want to achieve here?

I generally prefer explicit parameter addition. Having to call multiple param() methods makes it harder to know which parameter is where. They currently allow variadic parameters, as well.

This would probably get worse if we get a method that adds multiple parameter for 1 input. The proposed datetimeParams(x, y) would define 6 parameters ($1, $2, $3, $4, $5, $6).

Usage would look like this:

wfMessage( .. )
 ->params( .., .. ) // $1, $2
 ->timeperiodParams( .. ) // $3
 ->rawParams( .. ) // $4

I'd prefer the following instead, which is imho less fragile in maintenance and easier to understand when mapping parameters to placeholder numbers (one parameter for each):

wfMessage( .. )->params(
  ..,
  ..,
  Message::timeperiodParam( .. ),
  Message::rawParam( .. )
);

Note that the static methods timeperiodParam and rawParam already exist in the current API. We just haven't used them much.

You may wonder what the benefit is to this compared to calling Language methods directly, because we merely swap one method for another method. Here is the same without the static Message methods:

wfMessage( .. )->params(
  ..,
  ..,
  $lang->formatTimePeriod( .. ),
  Message::rawParam( .. )
);

The problem is that it requires the caller to obtain their own Language object. I support the static methods in the Message class as they keep the interaction with the message's Language object in one place. It also avoids accidentally using the wrong language object.

However, I'm not sure we should add more instance methods for adding parameters. We already have two ways (variadic to the constructor and calling params()).

I completely agree with what Krinkle said above. Adding more non-static methods does not seem a good idea to me.

Krinkle renamed this task from Extend Message class by methods dateParams(), timeParams(), and dateTimeParams() to Add 'date', 'time' and 'dateTime' param types to Message class.Jul 9 2019, 8:00 PM

Change 267669 abandoned by Krinkle:
Message class: add date/time parameter methods

Reason:
Closing due to inactivity and to clear review dashboards. See comments on the task for additional suggestions. Feel free to re-open at anytime.

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