Page MenuHomePhabricator

Replace initial colon in (hash-prefixed) parser function invocation with vertical bar
Open, Needs TriagePublic

Description

AFAIK there's no good reason why the first (unnamed) argument in a parser function invocation is separated from the parser function name with a colon, rather than a vertical bar. We should try to make this uniform, at least when considering invocations with heredoc syntax T114432: [RFC] Heredoc arguments for templates (aka "hygienic" or "long" arguments).

Probably we just need to split on colon OR vertical bar during the initial parser function argument parsing, so that {{#tag:ext}} and {{#tag|ext}} are equivalent. Might require some linting to make sure this doesn't inadvertently break anything.

This will *only* work for hash-prefixed parser functions; a separate task (T204370) tries to ensure that there are hash-prefixed alternatives for all the otherwise "magic" parser functions.

Related to T204370: Behavior switch/magic word uniformity and T204307: Parser Functions should support named parameters.

Event Timeline

cscott renamed this task from Replace initial colons in parser function invocation with vertical bar to Replace initial colon in parser function invocation with vertical bar.Sep 14 2018, 5:29 PM
cscott updated the task description. (Show Details)

For hash-prefixed parser functions this should be fine. For those that can be used without the prefix though, doing this would hide a template with the same name.

That may or may not make a difference. For example, enwiki tends to create wrapper templates at the name that will invoke the parser function or magic word, but there are some cases where a template doesn't match the magic word such as Template:Subst, Template:Lc, Template:Uc, Template:Ns, Template:Plural, and Template:Gender. I have no idea what the situation might be on other wikis.

You might also have to be careful that you don't turn {{Project:Example}} from a transclusion of Project:Example into a transclusion of Template:Project passing "Example" as parameter 1.

Yeah, there's a separate issue (T204370) which I think you've already seen which tries to ensure there is an equivalent hash-prefixed and pipe-separated form for each of the oddball magic words/parser functions. So I don't think I can/should/want to touch the "legacy" forms, if you want uniform syntax use the hash-prefixed alternatives.

cscott renamed this task from Replace initial colon in parser function invocation with vertical bar to Replace initial colon in (hash-prefiexed) parser function invocation with vertical bar.Sep 14 2018, 6:19 PM
cscott renamed this task from Replace initial colon in (hash-prefiexed) parser function invocation with vertical bar to Replace initial colon in (hash-prefixed) parser function invocation with vertical bar.

Note that there are some parser functions where the : makes sense, ex.: #invoke: or int:, because #invoke: and int: can be thought of as magic namespaces for specially accessing the Module: and MediaWiki: namespaces respectively.

Change 819147 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/core@master] Allow vertical bar to separate first argument of parser functions

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

Here's some historical context. The first things that used the colon separator were MSG and MSGNW, which were kind of like namespaces, so it made sense to separate them with a colon. By the time parser functions were introduced as an extensible concept, we had ad-hoc implementations of INT, RAW, NS, LCFIRST, UCFIRST, LC, UC, LOCALURL, FULLURL, GRAMMAR and PLURAL using a colon separator by analogy with MSG. All-caps with case sensitivity was used to avoid conflicts.

When I introduced parser functions, I wanted to get rid of case sensitivity. I thought it made sense to continue to use a colon separator, since it meant that parser function names would only conflict with namespaces, not pages, and there weren't so many namespaces. I think MZMcBride suggested adding the hash prefix so that they wouldn't collide with namespaces either.

I think merging the linked change alone would be potentially confusing for users, since there are many parser functions which don't have a hash, and using those parser functions with a pipe separator will subtly fail. I'm not sure the proposed SFH_OPT_HASH feature goes far enough towards solving this problem. I think I would prefer SFH_NO_HASH to automatically register case-insensitive hash-prefixed aliases, i.e. migrate everything right away. Maybe there could be an opt out (SFH_REALLY_NO_HASH), but I doubt there is a need for it.