Page MenuHomePhabricator

Parser Functions should support named parameters
Open, Needs TriagePublic

Description

To quote https://www.mediawiki.org/wiki/Manual:Parser_functions#Named_parameters :

Parser functions do not support named parameters the way templates and tag extensions do, but it is occasionally useful to fake it.

For uniformity of template syntax parsing, and to prevent continued slightly-incompatible wheel reinvention, we should fix this. When a parser function is registered with SFH_NAMED_ARGS as a flag to [Parser::setFunctionHook](https://www.mediawiki.org/wiki/Manual:Parser_functions#The_setFunctionHook_hook) standardized parsing of named arguments should be done by core. Users should be encouraged to migrate to this.

We should think carefully through the desired behavior for whitespace-stripping of argument values, and ensure it makes sense with T114432: [RFC] Heredoc arguments for templates (aka "hygienic" or "long" arguments).

(Note that argument values for extension tags is whitespace-stripped in core, which is arguably a misfeature: T267974#6625861 )

Related Objects

Event Timeline

I note that the code at that link seems a bit outdated. A parser function that wants named arguments today should probably use SFH_OBJECT_ARGS and use PPNode->splitArg(), more or less like PPFrame_Hash::newChild() does or like Parser::braceSubstitution() does for special page transclusion.

That's not to oppose this task, I think a new SFH_NAMED_ARGS flag to make it even easier for implementers would be a good idea.

When opting in to "standard" named argument parsing, you might want to opt-in to replacing the first colon with a vertical bar to look even more like a "standard" template invocation: T204371: Replace initial colon in (hash-prefixed) parser function invocation with vertical bar.

Removing task assignee due to inactivity, as this open task has been assigned to the same person for more than two years (see the emails sent to the task assignee on Oct27 and Nov23). Please assign this task to yourself again if you still realistically [plan to] work on this task - it would be welcome.
(See https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for tips how to best manage your individual work in Phabricator.)

Change 761494 had a related patch set uploaded (by Subramanya Sastry; author: Subramanya Sastry):

[mediawiki/services/parsoid@master] WIP: Add parser function support to Parsoid

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

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

[mediawiki/services/parsoid@master] WIP: FragmentHandler (new parser function API)

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

Change #1087277 merged by jenkins-bot:

[mediawiki/services/parsoid@master] FragmentHandler: new parser function API

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

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

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.21.0-a24

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

Change #1134218 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.21.0-a24

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

Change #761494 abandoned by Subramanya Sastry:

[mediawiki/services/parsoid@master] WIP: Add parser function support to Parsoid

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

Change #1186634 had a related patch set uploaded (by Arlolra; author: Arlolra):

[mediawiki/services/parsoid@master] Consider all pf arguments as positional

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

Change #1186634 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Consider all pf arguments as positional

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

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

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.22.0-a21

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

Change #1187841 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.22.0-a21

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

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

[mediawiki/services/parsoid@master] Handle deserialization of old parser functions with named arguments

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

Change #1210839 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Handle deserialization of old parser functions with named arguments

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

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

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.23.0-a7

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

Change #1211724 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.23.0-a7

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

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

[mediawiki/vendor@wmf/1.46.0-wmf.4] Bump wikimedia/parsoid to 0.23.0-a7

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

Change #1211759 merged by jenkins-bot:

[mediawiki/vendor@wmf/1.46.0-wmf.4] Bump wikimedia/parsoid to 0.23.0-a7

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

Mentioned in SAL (#wikimedia-operations) [2025-11-26T21:19:45Z] <cscott@deploy2002> Started scap sync-world: Backport for [[gerrit:1211759|Bump wikimedia/parsoid to 0.23.0-a7 (T204307 T373253 T410826 T410960)]], [[gerrit:1211760|Bump wikimedia/parsoid to 0.23.0-a7 (T410960)]]

Mentioned in SAL (#wikimedia-operations) [2025-11-26T21:21:56Z] <cscott@deploy2002> cscott: Backport for [[gerrit:1211759|Bump wikimedia/parsoid to 0.23.0-a7 (T204307 T373253 T410826 T410960)]], [[gerrit:1211760|Bump wikimedia/parsoid to 0.23.0-a7 (T410960)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2025-11-26T21:32:23Z] <cscott@deploy2002> Finished scap sync-world: Backport for [[gerrit:1211759|Bump wikimedia/parsoid to 0.23.0-a7 (T204307 T373253 T410826 T410960)]], [[gerrit:1211760|Bump wikimedia/parsoid to 0.23.0-a7 (T410960)]] (duration: 12m 38s)

Change #1213536 had a related patch set uploaded (by Isabelle Hurbain-Palatin; author: Isabelle Hurbain-Palatin):

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.23.0-a8

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

Change #1213536 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.23.0-a8

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