Module:Format TemplateData/doc: Difference between revisions

Content deleted Content added
Examples (test page): Copyedit (minor)
 
(29 intermediate revisions by 12 users not shown)
Line 1:
{{Lua|Module:Format TemplateData/config|Module:Multilingual | Module:Text| Module:WLink}}
{{nutshell|To use this module in a documentation page, use {{tl|Format TemplateData}}.<p>
'''<code>Format TemplateData</code>''' – Module with auxilary functions for template documentation, especially by TemplateData.
 
The below is an essay on the reasons for this module's existence, and documentation of the module itself.}}
 
'''<code>TemplateData</code>''' – Module with auxilary functions for template documentation, especially by TemplateData.
 
Core functionality is improved presentation on documentation pages.
Line 9 ⟶ 6:
__TOC__
 
== {{AnchorAnker|improveMW}} Improve template documentation page – MediaWiki disappointing ==
For presentation of template depiction in VisualEditor agreement was made to abandon all markup and clickable links, permitting all tooltips in all environments. Basically this is reasonable, albeit tooltips with markup and clickable links are supported as HTML application for decades now and JavaScript is present anyway when VisualEditor is used.
* In consequence it was decided, that also presentation on template documentation views never ever is permitted to contain effective links or markup.
Line 15 ⟶ 12:
This state is indefensible.
 
=== {{AnchorAnker|enhancedJSON}} Improved presentation ===
In addition to the simple syntax supported by MediaWiki and presented in the VisualEditor, the following features can be added to the JSON code for the template documentation page. They affect the elements classified as ''InterfaceText'', but are only useful for description fields.
 
Line 55 ⟶ 52:
Two aspects were found to be particularly disturbing in 2013–2017:
# Even if no parameters at all were defined, a table head is always displayed for a table without content. Even more, this is sortable.
#* A reduction was rejected with {{Phab|Task=126150}}. A sortable table of the parameters would be always necessary, even if the table has no rows at all and consists only of the header row.
#* This ridiculous statement led to the development of this module in 2016.
# Even if the context does not permit that default values or even AutoValue specifications will be defined ever, a content-free six-line definition list is output for each individual parameter value.
#* {{Phab|Task=T125333}} / {{Phab|Task=T137443}} / {{Phab|Task=T160254}} / {{Phab|Task=T52512}}<section end="JSONenhanced" />
#* MediaWiki did not even deign to answer the disastrous documentation page situation.
The general comments show that MediaWiki only regards the presentation of TemplateData specifications in the VisualEditor as important. However, someone has to program and maintain the templates and someone needs to generate the template description and make it manageable beside the functionality in the VisualEditor form, but that is beyond ken.
* Two years later the relatively easy task {{Phab|T125333}} has been solved by a community originated patch.
 
== General workflow ==
Line 71 ⟶ 69:
** If current page has been identified as documentation page the hidden <code>&lt;templatedata></code> is suppressed, and those pages do not appear separately in [[Special:PagesWithProp/templatedata]].
 
== {{AnchorAnker|template}} Functions for templates ==
 
=== Details ===
; f {{AnchorAnker|f}}
: Improve TemplateData-presentation; used in [[Template:Format TemplateData]]
: ''Parameters of template transclusion environment (all optional):''<section begin="templatePar" />
::; 1
Line 85 ⟶ 83:
::; TOC
::: <code>1</code> – Insert table of contents after general purpose descriptions; but before parameter list, if present
::: [[:de:Wikipedia:Lua/Modul/TemplateData/TOC|Example]]
::; lang
::: Language code according to [[ISO 639]] etc.
::; lazy
::: <code>1</code> – Presentation only, do not generate an effective data block
::: For general method descriptions.
::; debug
::: <code>1</code> – developer mode<section end="templatePar" />
::; source
::: <code>1</code> – show effective JSON source text (after template expansion) for debugging<section end="templatePar" />
: ''Parameters of'' <code>#invoke</code> ''for particular project adaption (all optional):''
::; catlang
::: Language code according to [[ISO 639]] etc.
::: Title of a maintenance category on invalid parameter value etc.
::; debug
::: Development mode, if provided and not equal <code>0</code>
::; cat
::: Title of a maintenance category on invalid parameter value etc.
::: '''Deprecated''' – use [[#config|configuration module]]
::; docpageCreate
::: Pattern for creation of subpage names; <code>%s/Doku</code>
::: '''Deprecated''' – use [[#config|configuration module]]
::; docpageDetect
::: Pattern for recognition of subpage names; <code>/Doku$</code>
::: '''Deprecated''' – use [[#config|configuration module]]
::; msgDescMiss
::: Localisation: complaint text on missing <code>description</code>
::: '''Deprecated''' – use [[#config|configuration module]]
: ''Returns:'' HTML code; and/or error message, probably with <code>class="error"</code>
; failsafe {{AnchorAnker|failsafe}}
: Version management
: Version identification: <code>{{#invoke:TemplateData|failsafe}}</code>
: Optional additional parameter <code>1</code> – requested minimal version identification
:: ''Returns:'' (empty), if minimal version condition not matched
 
== {{AnchorAnker|Lua}} Functions for Lua modules (API) ==
=== Examples (test page) ===
A [[:de:Wikipedia:Lua/Modul/TemplateData/Test|test page]] illustrates practical use.
 
== {{Anchor|Lua}} Functions for Lua modules (API) ==
 
Some functions described above can be used by other modules:
<syntaxhighlight lang="lua">
local lucky, TemplateData = pcall( require, "ModulModule:Format TemplateData" )
if type( TemplateData ) == "table" then
TemplateData = TemplateData.TemplateData()
Line 125 ⟶ 128:
 
; TemplateData.[[#failsafe|failsafe]](atleast)
:# atleast<br />''optional''<br />''nil'' or minimal version request or <code>"wikidata"</code>
: Returns: ''string'' or ''false''
; TemplateData.getPlainJSON(adapt)
Line 138 ⟶ 141:
 
== Usage ==
Currently focusingfocussing on one template only:
* [[Template:Format TemplateData]]
 
== {{Anker|config}} Configuration ==
== Dependencies ==
A local module [[Module:Format TemplateData/config]], if present, facilitates adaptions to the local project.
* [[Module:Multilingual|Multilingual]]
 
* [[Module:Text|Text]]
A ''table'' is expected via <code>mw.loadData</code>. The following entries are optional components:
* [[Module:WLink|WLink]]
; catProblem
: Title of a maintenance category on invalid parameter value etc.
; classNoNumTOC
: Name of class for the table of contents; especially to suppress numbering.
: <code>nonumtoc</code>
; classTable
: ''table'' with classes for the table of parameters.
: <code>{ "wikitable" }</code>
; cssParams
: ''table'' with CSS assignments for formatting of single parameters
; cssParWrap
: ''table'' with CSS assignments for formatting of the entire parameter table
; docpageCreate
: Pattern for creation of subpage names; <code>%s/Doku</code>
: <code>%s/Doku</code>
; docpageDetect
: Pattern for recognition of subpage names; <code>/Doku$</code>
: <code>/Doku$</code>
; help*********
: Link targets for context sensitive help on details
; helpBoolean
; helpContent
; helpDate
; helpFile
; helpFormat
: Link target on help about wikitext transclusion layout
; helpLine
; helpNumber
; helpPage
; helpString
; helpTemplate
; helpURL
; helpUser
; msgDescMiss
: Localisation: complaint text on missing <code>description</code>
; permit
: ''table'' with specification of properties for a single parameter; components:
:; boole
:: ''table'' with specification for ''boolean'' presentation
:: Two components <code>true</code> and <code>false</code> – each one ''table'':
::; css
::: ''table'' with CSS for this explanation of the value
::; lead
::: <code>true</code> – show explanation for <code>0</code> or <code>1</code> respectively preceding the value
::: <code>false</code> – show explanation for <code>0</code> or <code>1</code> respectively following the value
::; show
::: explanation; ''string'' or <code>false</code> to suppress
:; css
:: ''table'' with specifications for rendering of the parameter table; components:
::; tablehead
::: ''table'' with CSS for table head
::; required
::: ''table'' with CSS for <code>required</code>
::; suggested
::: ''table'' with CSS for <code>suggested</code>
::; optional
::: ''table'' with CSS for <code>optional</code>
::; deprecated
::: ''table'' with CSS for <code>deprecated</code>
<noinclude>
[[Category:Module documentation pages]]
</noinclude>