Page MenuHomePhabricator

TemplateData should support ordered unnamed parameters
Closed, DeclinedPublic

Description

Currently, if you edit {{my_list|one|two|three|four}} with VisualEditor in order to remove element “two”, it will generate the following code: {{my_list|1=one|3=three|4=four}}.

Another example is templates which look for last parameter: {{word_list|word1|word2|word3|lang code}}. There is no way to write in TemplateData that lang code may be the the 2nd, the 4th, or the 7th parameter (according to number of other parameters the user has given).

I think a good implementation could use paramOrder which would be mandatory when any parameter would be tagged as anonymous.

Related: T54582: TemplateData: Allow hinting to specify auto-numbered parameter names in some fashion


Example: {{word_list|word1|word2|word3|…|lang code}} would be represented like this:

<templatedata>
{
    "description": "This template is a list of anonymous parameters. The last parameter is a language code",
    "params": {
        "1": {
            "anonymous": true,
            "label": "First list element",
            "required": true
        },
        "2": {
            "anonymous": true,
            "label": "Second list element",
            "suggested": true
        }
        "3": {
            "anonymous": true,
            "label": "Third list element"
        },
        "4": {
            "anonymous": true,
            "label": "Fourth list element"
        },
        "lang": {
            "anonymous": true,
            "label": "Language code",
            "required": true
        },
    },
    "paramOrder": ["1", "2", "3", "4", "lang"]
}
</templatedata>

Event Timeline

thiemowmde subscribed.

The way I understand the first example the numbered parameters should behave as one sequence and never have a gap. This is covered by T54582.

While I understand the second example I'm afraid it doesn't make much sense when the solution is as simple as naming the parameter lang=, or making it the first. This is easier to understand as well. The main problem I see is that the proposed addition is not just an optional power-user feature. It's essential to be able to even read a template. The complexity this adds to each and every tool that does something with templates (e.g. ContentTranslation) really isn't worth it.

I agree this is mainly a specific case of T54582 which should solve the issue for anonymous parameters too.

For the second case, I’m pretty sure some templates expect some parameters to be the last parameter, or the second to last parameter… However, since I’m not able to provide a real use case link, I suppose this use case is enough rare to be declined.

I know such templates exist. The language allows bending the rules any way we want, even without Lua. I can, for example, create a template where one parameter does entirely different things depending on another parameter. No problem. How to document this?

The same problem exists in most programming languages. Especially in languages that don't allow to name parameters. It's effectively impossible to document such a function.

The solution is not to make the documentation as complicated as the code. The solution is to make the code readable. Many programming languages made this much easier the past years, including PHP. Luckily we never had this problem in wikitext. Naming parameters was always possible.