切换搜索
搜索
切换菜单
notifications
切换个人菜单
查看“模块:Format TemplateData/doc”的源代码
来自决策链云智库
更多操作
←
模块:Format TemplateData/doc
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{Lua|Module:Multilingual | Module:Text| Module:WLink}} ''<code>Format TemplateData</code>'' – Module with auxilary functions for template documentation, especially by TemplateData. Core functionality is improved presentation on documentation pages. __TOC__ == {{Anker|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. * That involved, that on many template documentation pages two separated parameter documentation tables are needed and required to be maintained simultaneously: One plain text version for VisualEditor, and a useful one for complex circumstances, with links and markup and lists and tables. – BTW, VisualEditor has not only tooltips, but also a static GUI view, where the lack of deepening links in parameter description is painful. This state is indefensible. === {{Anker|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. '''Wikilinks''' (internal format) * Using double square brackets pages can be linked as common. * In VisualEditor, only link title is visible, as it is displayed otherwise. '''External links''' ([[Uniform Resource Locator|URL]] format) * Open URL are linked as usual by themselves. In VisualEditor they appear as normal text. * External links enclosed in simple square brackets are displayed normally on the template documentation page. In VisualEditor the title is omitted and the URL is displayed so that the users can c&p it and transfer it to the address field of the browser. There is no other way. '''Apostrophs''' <code>'</code> for italic and bold * They can be used to emphasize on the documentation page and are missing in VisualEditor (regular script). '''HTML entities''' * The following entities can be used: <code style="white-space: nowrap">&lt; &gt; &amp; &quot; &nbsp;</code> and all numeric formats. '''HTML tags''' * HTML tags (and the MediaWiki elements that are not replaced in advance) are removed for the VisualEditor. Otherwise, they remain effective. * Attributes are often included in <code>"</code>, which conflicts with the JSON syntax. It is important to make sure that <code>'</code> is used, which can be a problem with template transclusions. <code><noexport></code> … <code></noexport></code> * The enclosed areas are not exported to the VisualEditor. * More complex wiki syntax and extensive explanations can be restricted to the documentation page. * Within a ''noexport'' area, the line structure of the source text is considered. Otherwise everything is running in a single line, as it would also be represented in the VisualEditor. '''Templates''' * In particular when the template parameter <code>JSON=</code> is used, templates can be distributed anywhere in the JSON code. However, the expanded syntax might collide with the JSON syntax. '''More effects''' * According to the state (required, suggested, optional, deprecated) the table rows are highlighted in light blue, white, gray and pale red. * When sorting by state, this importance is taken into account and not the alphabetical sequence of the keywords. * Each parameter can be addressed as a jump destination. The fragment is <code>#templatedata:</code>''parameter-name''. * Missing labels are highlighted as errors. * A maintenance category is triggered if errors occur. * If there are no parameters, the element <code>params:{}</code> is not required. === Eliminate disadvantages === 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|Task=T125333}} has been solved by a community originated patch. == General workflow == * An attempt is made to read the JSON object (string) from passed template parameters. * If this failed, the source code of the current and the documentation page is searched for <code><templatedata></code> elements. * Two representations are obtained from the JSON object input: *# A localized version, markup etc. stripped off, in JSON format. *# An HTML structure, basically similar to the MediaWiki representation, possibly with table of the parameters, with enhanced features. * The result of the template is a visible documentation with markup, followed by a hidden <code><templatedata></code> element. This is done for the export and corresponds to the MediaWiki guidelines. ** If current page has been identified as documentation page the hidden <code><templatedata></code> is suppressed, and those pages do not appear separately in [[Special:PagesWithProp/templatedata]]. == {{Anker|template}} Functions for templates == === Details === ; f {{Anker|f}} : Improve TemplateData-presentation; used in [[Template:Format TemplateData]] : ''Parameters of template transclusion environment (all optional):''<section begin="templatePar" /> ::; 1 ::: JSON string or <code><templatedata></code> object ::; JSON ::: JSON string ::: (precedes '''1''') ::: Transition from <code><templatedata></code> objects with pipe symbols needs special attention: Pipes are to be represented as <code><nowiki>{{!}}</nowiki></code>, on double curly brackets one should be encoded by HTML entity. ::; 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 ::; 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):'' ::; lang ::: Language code according to [[ISO 639]] 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 {{Anker|failsafe}} : Version management == {{Anker|Lua}} Functions for Lua modules (API) == Some functions described above can be used by other modules: <syntaxhighlight lang="lua"> local lucky, TemplateData = pcall( require, "Module:Format TemplateData" ) if type( TemplateData ) == "table" then TemplateData = TemplateData.TemplateData() else -- failure; TemplateData is the error message return "<span class='error'>" .. TemplateData .. "</span>" end </syntaxhighlight> ; TemplateData.[[#failsafe|failsafe]](atleast) :# atleast<br />''optional''<br />''nil'' or minimal version request or <code>"wikidata"</code> : Returns: ''string'' or ''false'' ; TemplateData.getPlainJSON(adapt) : Reduce enhanced JSON information to MediaWiki JSON :# adapt<br /> ''string'', with JSON (enhanced) : Returns: ''string'', with JSON (MediaWiki ) ; TemplateData.test(adapt, arglist) : Simulation of template functionality :# adapt<br /> ''table'', <code>#invoke</code> parameters :# arglist<br /> ''table'', template parameters : Returns: ''string'' == Usage == Currently focussing on one template only: * [[Template:Format TemplateData]] == Dependencies == * [[Module:Multilingual|Multilingual]] * [[Module:Text|Text]] * [[Module:WLink|WLink]] == {{Anker|config}} Configuration == A local module [[Module:Format TemplateData/config]], if present, facilitates adaptions to the local project. A ''table'' is expected via <code>mw.loadData</code>. The following entries are optional components: ; 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>
本页使用的模板:
模板:Anchor
(
查看源代码
)
模板:Anchor
(
查看源代码
)
模板:Lua
(
查看源代码
)
模板:Phab
(
查看源代码
)
模块:Anchor
(
查看源代码
)
模块:Arguments
(
查看源代码
)
模块:List
(
查看源代码
)
模块:Lua banner
(
查看源代码
)
模块:Message box
(
查看源代码
)
模块:Message box/configuration
(
查看源代码
)
模块:Message box/ombox.css
(
查看源代码
)
模块:TableTools
(
查看源代码
)
模块:Yesno
(
查看源代码
)
返回
模块:Format TemplateData/doc
。