Commons talk:TemplateData

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Looks good[edit]

Looks good, thanks for the work Rillke. Is there an example of a simple template using the new TemplateBox features, to see what needs to be done? Jean-Fred (talk) 14:49, 18 August 2013 (UTC)[reply]

Added that. Something that was truly missing. -- Rillke(q?) 17:51, 18 August 2013 (UTC)[reply]

Discouraged...?[edit]

"At Wikimedia Commons, we discouraged implantation of JSON-Data into Wiki-markup."

Some things:

  1. When? Where? What community had that discussion? Why did the community members who had this conversation with me multiple times, and knew of projects that were going to rely on sane TD structures, not ping somebody involved in those projects until just tonight a few days ago?
  2. Why? TemplateData is specifically meant to remove parts of the template documentation process so you don't need to maintain things as strenuously anymore, why would you specifically make it more difficult and entangled by adding more template nastiness on top?
  3. How, exactly, will this be implemented in the long term? As above, we have multiple projects that depend on TemplateData in the pipes, and it would be nice to have some concept of whether/how the great Commons Deities intend to limit it, so we can play nicely.

--MarkTraceur (talk) 05:08, 23 August 2013 (UTC)[reply]

  1. If people import templates from other wikis and they ship with templatedata tags and raw JSON, that's fine. What I am more concerned about is that people may start removing Template:TemplateBox and insert TemplateData instead because they did so at Wikipedia. Perhaps it should be re-worded to "It's recommended to use Template:TemplateBox ..." If you think a Request for Comment could clarify the situation, please tell right away.
  2. Creating mixed-type content without any appropriate editor or interface; especially containing such a strict language that JSON is, only creates headaches. It even refuses to save if it finds that something is invalid. Remember that the target audience of templatedata are not programmers. Why did the Wikimedia Foundation Developers choose that way to chase the average user out or having them to spend hours to figure what JSON is, how to efficiently edit it and how to spot errors? Does Template:Information/doc really look difficult? More difficult than the JSON-construct before?
  3. Why should we at Commons suddenly switch away from Template:TemplateBox that has been used for years just because the Wikimedia Foundation Developers created something questionable. No word how TemplateData will be supported in future in its docs. Especially storing TemplateData in the page_props which has a limited size that data already have to be compressed (additional CPU load, what happens if we get a lot of translations in east-asian languages that do not compress that nicely, …) No, I do not trust in this. It will be limited. Bugs won't be fixed for a long time after the VE-hype is over, … Having a switch here at Commons/ the doc itself to disable TemplateData output but still being able to show the documentation can't be wrong. If we, one day discover that we want JSON in wiki markup or something has been improved, it's quite easy to fetch all pages with TemplateData, fetch the templatedata, prettify it (using jsbeautifier, for example) and put it into the wikitext, if it is exposed by Template:TemplateBox. -- Rillke(q?) 06:40, 23 August 2013 (UTC)[reply]
To make everything clear: There was no real community decision; I simply assumed implied consent. If something does not work through TemplateBox or is unneccessary complicated (or does not fit in your philosophy), just use your own approach.. I have started a Request for Comment. -- Rillke(q?) 08:46, 23 August 2013 (UTC)[reply]

How to get TemplateBox to properly generate a “Template data” section?[edit]

Resolvedthe key was to use Scribunto with luasandbox not luastandaloneDan-nl (talk) 03:27, 17 September 2013 (UTC).[reply]
the key was to alter Module:Languages. see section belowDan-nl (talk) 03:36, 20 September 2013 (UTC).
[reply]

what needs to be set-up in a local wiki to get the {{TemplateBox}} to properly generate a “Template data” section?

  1. install and activate the following Extensions:
    1. ParserFunctions
    2. Scribunto (luasandbox not luastandalone)
      1. is it possible to not require luasandbox?Dan-nl (talk) 03:27, 17 September 2013 (UTC)[reply]
    3. TemplateData
  2. The following templates are required, dependencies are usually installed when you Special:Import the “parent” template:
    1. Template:TemplateBox and its dependencies
    2. Template:LangSwitch and its dependencies (this is a candidate to be substituted with Module:Languages in the near future)
      1. Template:Fallback
      2. Template:GetFallback
      3. Template:GetFallback2
  3. make sure the following Modules are installed. these are usually installed when you Special:Import the Template:LangSwitch:
    1. Module:JSON
    2. Module:TemplateBox
    3. Module:Languages
    4. Module:Languages/List (only used in rare cases)
    5. Module:Date ?

i understand that the “Template data” section on a Template page can be generated using either a {{TemplateBox}} section or a <templatedata/> section, however, if i try to copy the source of https://commons.wikimedia.org/wiki/Template:Artwork/doc and save it in my local wiki it does not work. i get “Syntax error in JSON”. i can use the Special:Export and Special:Import pages to create that doc page, but then the “Template data” section of the page still says “Syntax error in JSON”.

even using a simple TemplateBox example does not work locally, using Special:ExpandTemplates, whereas it does work on commons.

TemplateBox example

{{TemplateBox
  | useTemplateData=1
  | 1 = author
  | 1aliases = Author
  | 1d = For some objects "author" is more appropriate term than "artist". In most cases either "author" or "artist" should be used, not both.
  | 1def =
  | 1stat = optional
    | 1d-td-en = For some objects "author" is more appropriate term than "artist". In most cases either "author" or "artist" should be used, not both.
    | 1label-en = Author
    | 1type = string
}}

Dan-nl (talk) 04:40, 14 September 2013 (UTC)[reply]

You can make Template:TemplateBox output the JSON so you can inspect it: Set useTemplateData=export and it will pretty-print the template including TemplateData in a pre-tag. Tell me the output and I can likely tell you how to fix it. -- Rillke(q?) 11:00, 14 September 2013 (UTC)[reply]
I now attempted to test what's wrong but with a protected wiki this isn't fun. There are 2 possibilities:
  1. Either Module:TemplateBox does not output anything.
  2. The output is not correctly transferred to Template:TemplateBox/layout.
To debug this, I suggest you replace Template:TemplateBox with {{#invoke:TemplateBox|templatedata}} and observe at Template:TemplateBox/doc whether JSON was generated. -- Rillke(q?) 13:59, 16 September 2013 (UTC)[reply]

Exported code from Template:TemplateBox/doc
i had to put the useTemplateData=export switch in Template:TemplateBox/doc as that's where it's including the TemplateBox template for the documentation. it looks like not json is generated at all, not even an empty one.

<includeonly>{{#invoke:Languages|autolang
  |base=TemplateBox/i18n
  |useargs=both
  |templateData={{#invoke:TemplateBox|templatedata}}
  |JSONFM={{#invoke:TemplateBox|templatedata|formatting=pretty}}
  |paramTable={{#invoke:TemplateBox|paramtable}}
  |usageSample={{#invoke:TemplateBox|usagesample}}
  |argCount={{#invoke:TemplateBox|argcount}}
  |desc={{#invoke:TemplateBox|description}}
  |templateDataInfo={{TemplateDataInfo/toggler}}
  |i18n-subpage=Template:{{{name|{{BASEPAGENAME}}}}}/{{{i18n-subpage|i18n}}}
  |usergroup={{lc:{{{usergroup|}}}}}
  |name={{{name|{{BASEPAGENAME}}}}}}}</includeonly>__NOEDITSECTION__<noinclude>
{{documentation}}

</noinclude>
<noinclude><templatedata>

</templatedata>
</noinclude>

ExpandTemplates
even though the wiki is closed, you should be able to use this page to test template output http://gwtoolset.wmflabs.org/wiki/Special:ExpandTemplates

Dan-nl (talk) 16:52, 16 September 2013 (UTC)[reply]

Thank you. That's a nice page that I never used. Instead, I used the API (action=parse) ;-) When I've time I will investigate why the standalone did not create JSON. -- Rillke(q?) 06:17, 17 September 2013 (UTC)[reply]

Module:Languages
i contacted User:BJorsch (WMF) and he was able to help troubleshoot this issue further — he found that the core issue was in Module:Languages. line 265 of function p.autolang(frame). mw.clone() is cloning everything, including special accessors, which makes pairs() ignore the content of the table and only return the frame arguments. luasandbox overcomes this issue because it ignores the overridden pairs() when copying those cloned arrays to PHP.

the change below took care of the issue for me and allowed me to use luastandalone. Rillke, can you take a look at this and make the change on Commons if you’re okay with it?

-- changing this
local args, pargs = mw.clone( frame.args ), mw.clone( ( frame:getParent() or {} ).args or {} )

-- to this
local args, pargs = {}, {}
for k,v in pairs( frame.args ) do args[k] = v end
if frame:getParent() then
  for k,v in pairs( frame:getParent().args ) do pargs[k] = v end
end

Dan-nl (talk) 03:36, 20 September 2013 (UTC)[reply]

At "which makes pairs() ignore the content of the table and only return the frame arguments", I get confused. If it returns the frame arguments, I should be also able iterating over them?!
I think I make a function from this.
function cloneArgs(frame)
	local args, pargs = {}, {}
	for k,v in pairs( frame.args ) do args[k] = v end
	if frame:getParent() then
	  for k,v in pairs( frame:getParent().args ) do pargs[k] = v end
	end
	return args, pargs;
end
-- Rillke(q?) 21:02, 20 September 2013 (UTC)[reply]

i’m not that familiar with lua or Scribunto yet, so i’m not sure why your original idea didn’t work. in any case, i added the function as a utility method as you suggested and the call to it. you can test it out here if you’d like — http://gwtoolset.wmflabs.org/wiki/Special:ExpandTemplates with the TemplateBox example above and view the code here — http://gwtoolset.wmflabs.org/wiki/Module:Languages.

function cloneArgs(frame)
    local args, pargs = {}, {}
    for k,v in pairs( frame.args ) do args[k] = v end
    if frame:getParent() then
        for k,v in pairs( frame:getParent().args ) do pargs[k] = v end
    end
    return args, pargs;
end

function p.autolang(frame)
    local args, pargs = cloneArgs( frame )

Dan-nl (talk) 10:01, 21 September 2013 (UTC)[reply]

Localisation[edit]

Is it possible to create a localized version of the project page in another language in the form of Commons:TemplateData/et? If yes, please notify at my talk and expand on what should be done here. -Mardus (talk) 16:43, 30 January 2014 (UTC)[reply]

Format[edit]

@Rillke: I give up, how do you set the TemplateData format parameter using {{TemplateBox}}? In other words, if I want to set "format": "block" in the TemplateData, how do I do that (without resorting to adding TemplateData JSON directly in the page, which apparently is discouraged on Commons)? Kaldari (talk) 00:18, 11 April 2019 (UTC)[reply]

It also says that Another option, especially for imported templates, or for users with JSON experience, is placing raw <templatedata>-tags into the Wikitext of the template, as described in various Wikipediae.
format was added in Nov 2015 to TemplateData, whereas the last edit to TemplateBox was in 2014. When converting an existing template with TB to TD, you may find |useTemplateData=export useful as a start to work with. -- Rillke(q?) 20:27, 3 May 2019 (UTC)[reply]
Maybe |print= (TB) could be mapped to "format": (TD) if anyone would want that feature. -- Rillke(q?) 21:01, 3 May 2019 (UTC)[reply]
Changes to be applied to Module:TemplateBox (without mixed tabs and spaces of course) supporting the mapping. -- Rillke(q?) 22:20, 3 May 2019 (UTC)[reply]
@Rillke: Sorry I didn't notice this until now! I've copied it into the module and it seems to be working as expected. Thank you! Kaldari (talk) 15:35, 20 May 2019 (UTC)[reply]