Page MenuHomePhabricator

TemplateData: Implement inferred templatedata as fallback based on the contents of the template
Closed, DuplicatePublic

Description

if the template does not contain explicit "templatedata", the API call should return auto-generated "templatedata" structure, distilled from the template itself.

it's trivial to do - basically parse the template, extract parameter names (including order based, aka 1,2,3), and return "default" templatedata where every param is of type string, without any special attributes (default, required, etc.)

this 15-line enhancement will make VE suddenly useful for templates, without detracting anything from current functionality.

we did this in hewiki with "template param wizard" (the equivalent of VE template editor, for the old wikitext editor), and it enhanced the wizard's functionality tenfold.

regretfully i can't submit a patch - hopefully someone else will be able to do so.

peace.


See Also:
T54135: VisualEditor: Template dialog should make use of guessed/inferred TemplateData for templates without it / https://bugzilla.wikimedia.org/show_bug.cgi?id=52135

Details

Reference
bz52581

Event Timeline

bzimport raised the priority of this task from to Low.
bzimport set Reference to bz52581.
Kipod created this task.Aug 6 2013, 4:00 PM

I very much look forward to a link to the part of the hewiki wizard that implements this logic. I very much doubt it can be done (or done well) in 15 lines of code, and I very much doubt it's trivial or even easy to do it well.

Kipod added a comment.Aug 8 2013, 6:09 AM

https://he.wikipedia.org/wiki/Mediawiki:Gadget-TemplateParamWizard.js

the function is called buildParamsRaw() ("data" is the raw template page).

i cannot guarantee that it always works flawlessly, but the wizard works on hewiki for a while now (more than a year), and i did not get any bug reports (i did have some bug reports for previous versions).

i think it is possible to intentionally create a legal template that will give bad results there: specifically, this function does not take "nowiki" and "noinclude" tags into account.

OTOH, it uses only 9 out of the budget of 15, so you have 6 lines to augment those shortcomings...

more seriously: i assumed the codebase already have non-negligible amount of logic that can be used to distill the parameter list of a template.

(full disclosure: i too did not believe it can be done without tons of code - Eran Roz showed me the light)

Hi kipod. I can't understand Hebrew language and I have some trouble to test it in Hebrew Wikipedia. Can you translate the gadget to English Wikipedia under your own userspace? Thank you.

Kipod added a comment.Aug 8 2013, 1:40 PM

i did it long ago, and published it on [[en:Wikipedia:WikiProject_User_scripts/Scripts#Scripts]]. the script page on enwiki is [[en:User:קיפודנחש/TemplateParamWizard]]. the script source itself is practically identical to the hewiki one, except maybe some recent enhancement(s) to the hewiki script (for instance, by default, the wizard does not leave empty parameters on the page, but some users asked for this as an option, so now the hewiki script learned to support on more option).

the wizard uses a similar construct to "templatedata", but instead of having this information on the template page, it uses a subpage with a fixed name (in enwiki, this fixed name is "Parameters", so for Template:Foo, the templatedata equivalent will be in Template:Foo/Parameters).

when the subpage does not exist, the wizard extracts the list of parameter names from the template itself, with some fixed attributes (for instance, in this case it assumes that each parameter is "multiline")

i believe there are several people on enwiki who actually use this (at least there were) - you probably want to ask them about their experience (something like

https://en.wikipedia.org/w/index.php?title=Special%3ASearch&profile=advanced&search=TemplateParamWizard+intitle%3Ajs&fulltext=Search&ns2=1&redirs=1&profile=advanced

the wizard supports some attributes that, to the best of my knowledge, "templatedata"/VE do not support yet, which i think would be good ideas:

  • "Extended": this allows the designer to designate some fields as "secondary", which means they are not visible when the form opens. if there is at least one "Extended" parameter, the form will grow a new checkbox "Show all fields", which allows the user to show/hide the "Extended" fields.
  • "Choices": this allows the designer to declare that a certain parameter has a fixed set of "legal" values. very useful when the template uses a parameter as an input for {{#switch:
  • "Depends on": only expose this field if some other field is not empty. very useful for templates with many repetitions (e.g., [[en:Template:Track listing]]: you make "title4" depend on "title3", and then "note4", "writer4", "lyrics4", "music4", "extra4", "length4", and finally "title5" all depend on "title4"). without this feature, the wizard is much less useful for templates of this type.

peace.

Thank you so much. It works beautifully. I couldn't test it in Hebrew WP because it is situated in the edit toolbar which was disabled by me because I feel more comfortable to type everything with my keyboard. But anyway, the gadget's performance is smooth even while editing large article like "United States" in English WP. The only few issues I can think of right now after tried it a bit are, I don't feel the toolbar is the proper place for the gadget icon. It deserves a more visible location in the edit page. The other thing I hope to improve is that I need to select the whole markups of existing template from "{{" to "}}" in order to edit it in the Wizard. For large infobox template which has lot of parameters filled, it could be little bit inefficient to trigger. I suggest the end of the selection of the markup extends to the first vertical bar near the template name, so only selecting like this "{{templatename|", works the same way as "{{templatename|foo|bar}}".

Kipod added a comment.Aug 8 2013, 3:50 PM

Thanks so much for the nice words, but...
This entry is about templatedata, not templatewizard.

the information i brought above relating to TW was meant as "what templatedata can learn from TW" - if you'd like to discuss TW and its use on enwiki, it should be discussed on enwiki, not here.

peace.

Kipod added a comment.Aug 29 2013, 3:35 PM

The status was recently changed to "Assigned", but the "Assigned to" field was left as "Nobody".
is Mr. (or Ms.) "Nobody" a new developer on the team?

peace.

He7d3r added a comment.Nov 2 2013, 5:27 PM

(In reply to comment #4)

i did it long ago, and published it on
[[en:Wikipedia:WikiProject_User_scripts/Scripts#Scripts]]. the script page on
enwiki is [[en:User:קיפודנחש/TemplateParamWizard]].

See also
https://en.wikipedia.org/wiki/Wikipedia:Village_pump_(technical)/Archive_103#Template_Parameter_Wizard
(mentioned on bug 39598 comment 1)

  • "Choices": this allows the designer to declare that a certain parameter has a fixed set of "legal" values. very useful when the template uses a parameter as an input for {{#switch:

Bug 51375.

  • "Depends on": only expose this field if some other field is not empty.

Bug 50407.

So this "guess template data" parser would be useful in two cases:

  • Consumers of TemplateData (e.g. VisualEditor)

They could pass a parameter to the API of TemplateData to trigger this parser as fallback. The generated data would presumably be flagged in some way to allow consumers to identify them as such.

  • TemplateDate editor

A button to prefill the template data (e.g. use the default data as a start and edit from there). This should not be misused to populate <templatedata> tags on a bunch of pages, this is only useful if users provide data beyond what is inferred (the inferred data is unlikely to ever be satisfactory as at best it can provide which parameters exist and maybe which are optional).

Kipod added a comment.May 22 2014, 9:35 PM

for many many simple templates, just getting the list of parameter names is enough for even moderately experienced editors.
the editor may even be well familiar with the template, but she does not necessarily remembers the exact name (case sensitive) of every parameters.

regarding your 2nd use case: are you aware that this tool (prepopulate templatedata editor) is already written and working?

written by wmf volunteer (intern? gsoc student? not sure), [[mw:. User:Mooeypoo]], and works on hewiki for quite some time.
this tool already includes "import parameters from template" button - last time i checked, it was working quite well.

see [[mw:MediaWiki:Gadget-templatedata-core.js]], function "importtemplateparams()"

if your comment meant to describe it rather than suggesting to build it, i apologize for the confusion.

bottom line: having templatedata is good, but when it does not exist, just seeing the list of parameters (including unpopulated) is hugely perferrable to not seeing them.

peace.

The TemplateData editor now supports scanning the template source code and inferring a list of parameter names to bootstrap the documentation editor.

We can use the same logic server-side to provide a basic TemplateData object for templates lacking it. Possibly with a warning outputted alongside the object. Similar to how MediaWiki's query api communicates things like "warnings", "normalized", and "badrevids".

Krinkle moved this task from Backlog to Backlog on the TemplateData board.May 8 2015, 4:16 AM
Krinkle moved this task from Backlog to Next-up on the TemplateData board.
Kipod added a comment.May 12 2015, 4:51 PM

.... Possibly with a warning outputted alongside the object. Similar to how MediaWiki's query api communicates things like "warnings", "normalized", and "badrevids".

maybe so, but maybe it should not be "warning".
a new field can be added to the record returned by the API, e.g. "synthetic" or somesuch, to indicate tempaltedata was generated synthetically, and the template itself does not contain "templatedata" tag.

peace.

Jdforrester-WMF moved this task from Next-up to Backlog on the TemplateData board.Sep 17 2015, 6:37 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 17 2015, 6:37 PM

Change 257684 had a related patch set uploaded (by Eranroz):
Guess parameters when templatedata is missing

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

Change 257684 abandoned by Eranroz:
Guess parameters when templatedata is missing

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