Page MenuHomePhabricator

Add support for actual format strings to TemplateData's "format" parameter
Closed, ResolvedPublic8 Estimated Story Points

Description

I suggest to extend the existing "format": "…" parameter of <templatedata> to not only accept inline and block but an actual format string (or add a new parameter for that). Typical format strings would look like these:

  • |_=_ is the same as inline.
  • | _ = _\n is the same as block.
  • |_ = _\n does not add a space before the parameter name.
  • |_ = _\n indents each parameter.
  • |_______________ = _\n aligns all parameter names to that length. Or more if the parameter name is longer (it can not be cut, obviously), but will always have spaces before and after the equal sign.
  • |\n_ = _ is a format with the pipe characters at the end of the previous line.
  • |_ = _ is an inline style with much more spaces.

I'm currently using this format in my Auto-Formatter wikitext cleaner, see de:User:TMg/autoFormatter #Vorlagenformatierung for the documentation and de:User:TMg/autoFormatter.js for the (ugly) code. More examples can be found at the bottom of my de:User:TMg/common.js.

There are "magic" edge cases my tool considers:

  • |_=_ is the minimum that must be in the format string. My tool adds missing elements. TemplateData should output an error if something is missing.
  • If the format string ends with a newline, an extra newline is added between the template name and the first parameter.
  • If there is a newline somewhere in the format string, the closing }} is always put on an extra line, no matter what the format string says. My tool makes sure to never create duplicate newlines.
  • Spaces on line endings are allowed. For example, |_ = _\n means there will be a space at the end of the line when the parameter is empty.
  • A single _ does not create an extra space when the parameter is empty.

Event Timeline

Change 295741 had a related patch set uploaded (by Cscott):
Use improved format specifier for TemplateData.

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

This probably needs to specify whether the template has to sit on its own line or inline (e.g. nlwiki's {{largethumb}} breaks if on its own line, and enwiki's {{s-bef}} breaks if not), and possibly as the same state or as its own whether it should (e.g. {{Use American English}}\n{{Use MDY dates}}\nContent here.)

Jdforrester-WMF removed a project: Proposal.
Jdforrester-WMF set the point value for this task to 8.

This probably needs to specify whether the template has to sit on its own line or inline (e.g. nlwiki's {{largethumb}} breaks if on its own line, and enwiki's {{s-bef}} breaks if not), and possibly as the same state or as its own whether it should (e.g. {{Use American English}}\n{{Use MDY dates}}\nContent here.)

Specifically, that would be T135667: Please put templates on separate lines (when it won't break things) and don't (when it will).

@thiemowmde : could you look at @Jdforrester-WMF's request (T135667: Please put templates on separate lines (when it won't break things) and don't (when it will)) and perhaps suggest some way of doing this with your "format" parameter? Perhaps we just need a new parameter to <templatedata>, but if there's some way of doing this with the format string, it would avoid inventing more parameters...

Change 303431 had a related patch set uploaded (by Cscott):
WIP: Extend 'format' spec to include format strings.

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

Change 306975 had a related patch set uploaded (by Cscott):
Extend 'format' spec to include custom format strings.

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

Change 303431 abandoned by Cscott:
Extend 'format' spec to include custom format strings.

Reason:
Abandoned in favor of https://gerrit.wikimedia.org/r/306975

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

Change 306975 merged by jenkins-bot:
Extend 'format' spec to include custom format strings.

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

The change to add this to TemplateData is now merged; I'll wait to mark this Resolved once the use of the new support is merged in Parsoid (https://gerrit.wikimedia.org/r/#/c/295741/).

Change 295741 merged by jenkins-bot:
[mediawiki/services/parsoid@master] Use improved format specifier for TemplateData.

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

This has been complete in TD for 10 months, and Parsoid support is rolling out very soon. Declaring this Resolved.