Modul:TemplateData: Unterschied zwischen den Versionen

K
73 Versionen von wikivoyage:Modul:TemplateData importiert
w>PerfektesChaos
(2018-03-11)
K (73 Versionen von wikivoyage:Modul:TemplateData importiert)
 
(35 dazwischenliegende Versionen von 5 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local TemplateData = { suite  = "TemplateData",
local TemplateData = { suite  = "TemplateData",
                       serial = "2018-03-11",
                       serial = "2021-07-05",
                       item  = 46997995 }
                       item  = 46997995 }
--[=[
--[==[
improve template:TemplateData
improve template:TemplateData
]=]
]==]
local Failsafe = TemplateData




Zeile 12: Zeile 13:
     basicCnf = { catProblem    = "strange",
     basicCnf = { catProblem    = "strange",
                 classNoNumTOC = "suppressTOCnum",
                 classNoNumTOC = "suppressTOCnum",
                classTable    = "classTable",
                 cssParWrap    = "cssTabWrap",
                 cssParWrap    = "cssTabWrap",
                 cssParams    = "cssTable",
                 cssParams    = "cssTable",
Zeile 28: Zeile 30:
                 helpURL      = "support4url",
                 helpURL      = "support4url",
                 helpUser      = "support4wiki-user-name",
                 helpUser      = "support4wiki-user-name",
                 msgDescMiss  = "solo" },
                 msgDescMiss  = "solo",
--  classParams    = "classTable",
                tStylesTOCnum = "stylesTOCnum" },
--  classTable    = false,    -- class for params table
    classTable    = { "wikitable" },    -- classes for params table
     debugmultilang = "C0C0C0",
     debugmultilang = "C0C0C0",
     loudly        = false,    -- show exported element, etc.
     loudly        = false,    -- show exported element, etc.
Zeile 47: Zeile 49:
     got    = false,    -- table, initial templatedata object
     got    = false,    -- table, initial templatedata object
     heirs  = false,    -- table, params that are inherited
     heirs  = false,    -- table, params that are inherited
    jump    = false,    -- source position at end of "params"
     less    = false,    -- main description missing
     less    = false,    -- main description missing
     lasting = false,    -- old syntax encountered
     lasting = false,    -- old syntax encountered
Zeile 55: Zeile 58:
     params  = false,    -- table, exported parameters
     params  = false,    -- table, exported parameters
     scream  = false,    -- error messages
     scream  = false,    -- error messages
     slang  = false,   -- project language code
    sibling = false,    -- TOC juxtaposed
     slang  = nil,     -- project/user language code
     slim    = false,    -- JSON reduced to plain
     slim    = false,    -- JSON reduced to plain
     source  = false,    -- JSON input
     source  = false,    -- JSON input
Zeile 64: Zeile 68:
}
}
local Permit = {
local Permit = {
     builder = { after     = "block",
     builder = { after           = "block",
                 align     = "block",
                 align           = "block",
                 block     = "block",
                 block           = "block",
                 compressed = "block",
                 compressed     = "block",
                 dense     = "block",
                 dense           = "block",
                 grouped   = "inline",
                 grouped         = "inline",
                 half       = "inline",
                 half           = "inline",
                 indent     = "block",
                 indent         = "block",
                 inline     = "inline",
                 inline         = "inline",
                 last       = "block",
                 last           = "block",
                 lead       = "block",
                 lead           = "block",
                 newlines   = "block",
                 newlines       = "*",
                 spaced     = "inline" },
                 spaced         = "inline" },
     colors  = { tableheadbg   = "B3B7FF",
     colors  = { tableheadbg = "B3B7FF",
                 required       = "EAF3FF",
                 required   = "EAF3FF",
                 suggested     = "FFFFFF",
                 suggested   = "FFFFFF",
                 optional       = "EAECF0",
                 optional   = "EAECF0",
                 deprecated     = "FFCBCB" },
                 deprecated = "FFCBCB" },
     params  = { aliases     = "table",
     params  = { aliases         = "table",
                 autovalue   = "string",
                 autovalue       = "string",
                 default     = "string table I18N nowiki",
                 default         = "string table I18N nowiki",
                 deprecated = "boolean string",
                 deprecated     = "boolean string I18N",
                 description = "string table I18N",
                 description     = "string table I18N",
                 example     = "string table I18N nowiki",
                 example         = "string table I18N nowiki",
                 label       = "string table I18N",
                 label           = "string table I18N",
                 inherits   = "string",
                 inherits       = "string",
                 required   = "boolean",
                 required       = "boolean",
                 suggested   = "boolean",
                style          = "string table",
                 type       = "string" },
                 suggested       = "boolean",
                suggestedvalues = "string table number",
                 type           = "string" },
     root    = { description = "string table I18N",
     root    = { description = "string table I18N",
                 format      = "string",
                 format      = "string",
Zeile 133: Zeile 139:




local function Fetch( ask )
local function Fetch( ask, allow )
     -- Fetch module
     -- Fetch module
     -- Parameter:
     -- Parameter:
     --    ask -- string, with name
     --    ask   -- string, with name
     --                     "Multilingual"
     --                       "/global"
     --                     "Text"
    --                      "JSONutil"
     --                     "WLink"
    --                      "Multilingual"
     --                       "Text"
     --                       "WLink"
    --    allow  -- true: no error if unavailable
     -- Returns table of module
     -- Returns table of module
     -- error: Module not available
     -- error: Module not available
     local r
    local sign = ask
     local r, stem
    if sign:sub( 1, 1 ) == "/" then
        sign = TemplateData.frame:getTitle() .. sign
    else
        stem = sign
        sign = "Module:" .. stem
    end
     if TemplateData.extern then
     if TemplateData.extern then
         r = TemplateData.extern[ ask ]
         r = TemplateData.extern[ sign ]
     else
     else
         TemplateData.extern = { }
         TemplateData.extern = { }
     end
     end
     if not r then
     if not r then
         local lucky, g = pcall( require, "Module:" .. ask )
         local lucky, g = pcall( require, sign )
         if type( g ) == "table" then
         if type( g ) == "table" then
             r = g[ ask ]()
             if stem  and  type( g[ stem ] ) == "function" then
             TemplateData.extern[ ask ] = r
                r = g[ stem ]()
         else
            else
             error( string.format( "Fetch(%s) %s", ask, g ) )
                r = g
            end
             TemplateData.extern[ sign ] = r
         elseif not allow then
             error( string.format( "Fetch(%s) %s", sign, g ), 0 )
         end
         end
     end
     end
     return r
     return r
end -- Fetch()
end -- Fetch()
local function Foreign()
    -- Guess human language
    -- Returns slang, or not
    if type( Data.slang ) == "nil" then
        local Multilingual = Fetch( "Multilingual", true )
        if Multilingual  and
          type( Multilingual.userLangCode ) == "function" then
            Data.slang = Multilingual.userLangCode()
        else
            Data.slang = mw.language.getContentLanguage():getCode()
                                                        :lower()
        end
    end
    if Data.slang  and
      mw.ustring.codepoint( Data.slang, 1, 1 ) > 122 then
        Data.slang = false
    end
    return Data.slang
end -- Foreign()




Zeile 172: Zeile 214:
                                   :gsub( "([%-.()+*?^$%[%]])",
                                   :gsub( "([%-.()+*?^$%[%]])",
                                           "%%%1" ) )
                                           "%%%1" ) )
     local i, k = Data.source:find( seek, at )
     local i, k, r, slice, source
     local r, slice, source
    if not Data.jump then
        Data.jump = Data.source:find( "params", 2 )
        if Data.jump then
            Data.jump = Data.jump + 7
        else
            Data.jump = 1
        end
    end
     i, k = Data.source:find( seek, at + Data.jump )
     while i  and  not r do
     while i  and  not r do
         source = Data.source:sub( k + 1 )
         source = Data.source:sub( k + 1 )
Zeile 184: Zeile 234:
             r = k
             r = k
         else
         else
             i, k = Data.source:find( seek, k )
             i, k = Data.source:find( seek, k )
         end
         end
     end    -- while i
     end    -- while i
Zeile 196: Zeile 246:
     -- Parameter:
     -- Parameter:
     --    adapt  -- string, message ID after "templatedata-"
     --    adapt  -- string, message ID after "templatedata-"
     -- Returns string, with localized text  
     -- Returns string, with localized text
     local o = mw.message.new( "templatedata-" .. adapt )
     local o = mw.message.new( "templatedata-" .. adapt )
     if Data.slang then
     if Foreign() then
         o:inLanguage( Data.slang )
         o:inLanguage( Data.slang )
     end
     end
Zeile 252: Zeile 302:
     --    adjust  -- string
     --    adjust  -- string
     -- Returns string, with adjusted text
     -- Returns string, with adjusted text
     local f = function ( a )
     local f   = function ( a )
                  return a:gsub( "%s*\n%s*", " " )
                    return a:gsub( "%s*\n%s*", " " )
                          :gsub( "%s%s+", " " )
                            :gsub( "%s%s+", " " )
              end
                end
     local r
     local tags = { { start = "<noexport>",
    if adjust:find( "<noexport>", 1, true ) then
                    stop  = "</noexport>" },
        local i    = 1
                  { start = "<exportonly>",
        local j, k = adjust:find( "<noexport>", i, true )
                    stop  = "</exportonly>",
        r = ""
                    l    = false }
        while j do
                }
            if j > 1 then
    local r = adjust
                r = r .. f( adjust:sub( i, j - 1 ) )
    local i, j, k, s, tag
             end
    for m = 1, 2 do
             i = k + 1
        tag = tags[ m ]
             j, k = adjust:find( "</noexport>", i, true )
        if r:find( tag.start, 1, true ) then
             if j then
            s    = r
                r   = r .. adjust:sub( i,  j - 1 )
             r    = ""
             i     = 1
            tag.l = true
             j, k = s:find( tag.start, i, true )
             while j do
                if j > 1 then
                    r = r .. f( s:sub( i,  j - 1 ) )
                end
                 i    = k + 1
                 i    = k + 1
                 j, k = adjust:find( "<noexport>", i, true )
                 j, k = s:find( tag.stop, i, true )
            else
                if j then
                Fault( "missing </noexport>" )
                    if m == 1 then
            end
                        r = r .. s:sub( i,  j - 1 )
        end    -- while j
                    end
        r = r .. adjust:sub( i )
                    i    = k + 1
     else
                    j, k = s:find( tag.start, i, true )
         r = f( adjust )
                else
                    Fault( "missing " .. tag.stop )
                end
            end    -- while j
            r = r .. s:sub( i )
        elseif m == 1 then
            r = f( r )
        end
    end -- for m
     if tags[ 2 ].l then
         r = r:gsub( "<exportonly>.*</exportonly>", "" )
     end
     end
     return r
     return r
end -- fair()
end -- fair()




Zeile 330: Zeile 396:


local function faraway( alternatives )
local function faraway( alternatives )
     -- Retrieve project language version from multilingual text
     -- Retrieve best language version from multilingual text
     -- Parameter:
     -- Parameter:
     --    alternatives  -- table, to be evaluated
     --    alternatives  -- table, to be evaluated
Zeile 339: Zeile 405:
     local variants = { }
     local variants = { }
     local r1, r2
     local r1, r2
    if not Data.slang then
        Data.slang = mw.language.getContentLanguage():getCode()
    end
     for k, v in pairs( alternatives ) do
     for k, v in pairs( alternatives ) do
         if type( v ) == "string" then
         if type( v ) == "string" then
             v = mw.text.trim( v )
             v = mw.text.trim( v )
             if v ~= "" then
             if v ~= ""  and  type( k ) == "string" then
                k = k:lower()
                 variants[ k ] = v
                 variants[ k ] = v
                 n            = n + 1
                 n            = n + 1
Zeile 352: Zeile 416:
     end -- for k, v
     end -- for k, v
     if n > 0 then
     if n > 0 then
         for k, v in pairs( variants ) do
         local Multilingual = Fetch( "Multilingual", true )
             if v then
        if Multilingual  and
                 if n == 1 then
          type( Multilingual.i18n ) == "function" then
                    r1 = v
            local show, slang = Multilingual.i18n( variants )
                 elseif k:lower() == Data.slang then
             if show then
                    variants[ k ] = nil
                 r1 = show
                    r1 = v
                 variants[ slang ] = nil
                    r2 = variants
                r2 = variants
                    break -- for k, v
                end
             end
             end
         end -- for k, v
         end
         if not r1 then
         if not r1 then
             local seek = string.format( "^%s-", Data.slang )
             Foreign()
             for k, v in pairs( variants ) do
             for k, v in pairs( variants ) do
                 if v and k:lower():match( seek ) then
                 if n == 1 then
                    r1 = v
                elseif Data.slang == k then
                     variants[ k ] = nil
                     variants[ k ] = nil
                     r1 = v
                     r1 = v
                     r2 = variants
                     r2 = variants
                    break -- for k, v
                 end
                 end
             end -- for k, v
             end -- for k, v
            if not r1 then
                local others = mw.language.getFallbacksFor( slang )
                table.insert( others, "en" )
                for i = 1, #others do
                    seek = others[ i ]
                    if variants[ seek ] then
                        r1              = variants[ seek ]
                        variants[ seek ] = nil
                        r2              = variants
                        break    -- for i
                    end
                end -- i = 1, #others
            end
            if not r1 then
                for k, v in pairs( variants ) do
                    if v then
                        variants[ k ] = nil
                        r1 = v
                        r2 = variants
                        break -- for k, v
                    end
                end -- for k, v
            end
         end
         end
         if r2 then
         if r2 and Multilingual then
            local Multilingual = Fetch( "Multilingual" )
             for k, v in pairs( r2 ) do
             for k, v in pairs( r2 ) do
                 if v  and  not Multilingual.isLang( k ) then
                 if v  and  not Multilingual.isLang( k, true ) then
                     Fault( string.format( "Invalid <code>lang=%s</code>",
                     Fault( string.format( "%s <code>lang=%s</code>",
                                          "Invalid",
                                           k ) )
                                           k ) )
                 end
                 end
Zeile 413: Zeile 453:




local function fathers()
local function fashioned( about, asked, assign )
     -- Merge params with inherited values
     -- Create description head
     local n = 0
     -- Parameter:
     local p = Data.params
     --    about  -- table, supposed to contain description
     local t = Data.tree.params
     --     asked  -- true, if mandatory description
     local p2, t2
     --     assign  -- <block>, if to be equipped
     for k, v in pairs( Data.heirs ) do
     -- Returns <block>, with head, or nil
        n = n + 1
    local para = assign or mw.html.create( "div" )
     end -- for k, v
    local plus, r
     for i = 1, n do
    if about and about.description then
        for k, v in pairs( Data.heirs ) do
        if type( about.description ) == "string" then
            if v  and  not Data.heirs[ v ] then
            para:wikitext( about.description )
                n              = n - 1
        else
                t[ k ].inherits = nil
            para:wikitext( about.description[ 1 ] )
                Data.heirs[ k ] = nil
            plus = mw.html.create( "ul" )
                p2              = { }
            plus:css( "text-align", "left" )
                t2              = { }
            for k, v in pairs( about.description[ 2 ] ) do
                for k2, v2 in pairs( p[ v ] ) do
                plus:node( mw.html.create( "li" )
                    p2[ k2 ] = v2
                                  :node( mw.html.create( "code" )
                end -- for k2, v2
                                                :wikitext( k ) )
                if p[ k ] then
                                  :node( mw.html.create( "br" ) )
                    for k2, v2 in pairs( p[ k ] ) do
                                  :wikitext( fair( v ) ) )
                        if type( v2 ) ~= "nil" then
            end -- for k, v
                            p2[ k2 ] = v2
             if Config.loudly then
                        end
                 plus = mw.html.create( "div" )
                    end -- for k2, v2
                              :css( "background-color",
                end
                                    "#" .. Config.debugmultilang )
                p[ k ] = p2
                              :node( plus )
                for k2, v2 in pairs( t[ v ] ) do
            else
                    t2[ k2 ] = v2
                 plus:addClass( "templatedata-maintain" )
                end -- for k2, v2
                    :css( "display", "none" )
                for k2, v2 in pairs( t[ k ] ) do
                    if type( v2 ) ~= "nil" then
                        t2[ k2 ] = v2
                    end
                end -- for k2, v2
                t[ k ] = t2
            end
        end -- for k, v
    end -- i = 1, n
    if n > 0 then
        local s
        for k, v in pairs( Data.heirs ) do
             if v then
                 if s then
                    s = string.format( "%s &#124; %s", s, k )
                else
                    s = "Circular inherits: " .. k
                 end
             end
             end
         end -- for k, v
         end
         Fault( s )
    elseif Config.solo and asked then
     end
        para:addClass( "error" )
end -- fathers()
            :wikitext( Config.solo )
        Data.less = true
    else
        para = false
    end
    if para then
         if plus then
            r = mw.html.create( "div" )
                      :node( para )
                      :node( plus )
        else
            r = para
        end
     end
    return r
end -- fashioned()






local function favorize()
local function fatten( access )
     -- Local customization issues
     -- Create table row for sub-headline
     local boole  = { ["font-size"] = "125%" }
    -- Parameter:
     local l, cx = pcall( mw.loadData,
    --    access  -- string, with name
                        TemplateData.frame:getTitle() .. "/config" )
    -- Returns <tr>
     local scripting
     local param    = Data.tree.params[ access ]
     TemplateData.ltr = not mw.language.getContentLanguage():isRTL()
    local sub, sort = access:match( "(=+)%s*(%S.*)$" )
     if TemplateData.ltr then
     local headline  = mw.html.create( string.format( "h%d", #sub ) )
         scripting = "left"
    local r        = mw.html.create( "tr" )
    local td        = mw.html.create( "td" )
                            :attr( "colspan", "5" )
                            :attr( "data-sort-value",  "!" .. sort )
     local s
     if param.style then
        s = type( param.style )
        if s == "table" then
            td:css( param.style )
        elseif s == "string" then
            td:cssText( param.style )
        end
    end
    s = fashioned( param, false, headline )
     if s then
         headline = s
     else
     else
         scripting = "right"
         headline:wikitext( sort )
     end
     end
     boole[ "margin-" .. scripting ] = "3em"
     td:node( headline )
    Permit.boole = { [false] = { css  = boole,
    r:node( td )
                                lead = true,
    return r
                                show = "&#x2610;" },
end -- fatten()
                    [true]  = { css  = boole,
 
                                lead = true,
 
                                show = "&#x2611;" } }
 
     Permit.css  = { }
local function fathers()
     for k, v in pairs( Permit.colors ) do
    -- Merge params with inherited values
         if k == "tableheadbg" then
    local n = 0
            k = "tablehead"
    local p = Data.params
        end
    local t = Data.tree.params
        Permit.css[ k ] = { ["background-color"]  =  "#" .. v }
     local p2, t2
     for k, v in pairs( Data.heirs ) do
         n = n + 1
     end -- for k, v
     end -- for k, v
     if type( cx ) == "table" then
     for i = 1, n do
        local c, s
        if Data.heirs then
        if type( cx.permit ) == "table" then
            for k, v in pairs( Data.heirs ) do
            if type( cx.permit.boole ) == "table" then
                if v  and  not Data.heirs[ v ] then
                 if type( cx.permit.boole[ true ] ) == "table" then
                    n              = n - 1
                     Permit.boole[ false ]  = cx.permit.boole[ false ]
                    t[ k ].inherits = nil
                    Data.heirs[ k ] = nil
                    p2              = { }
                    t2              = { }
                    if p[ v ] then
                        for k2, v2 in pairs( p[ v ] ) do
                            p2[ k2 ] = v2
                        end -- for k2, v2
                        if p[ k ] then
                            for k2, v2 in pairs( p[ k ] ) do
                                if type( v2 ) ~= "nil" then
                                    p2[ k2 ] = v2
                                end
                            end -- for k2, v2
                        end
                        p[ k ] = p2
                        for k2, v2 in pairs( t[ v ] ) do
                            t2[ k2 ] = v2
                        end -- for k2, v2
                        for k2, v2 in pairs( t[ k ] ) do
                            if type( v2 ) ~= "nil" then
                                t2[ k2 ] = v2
                            end
                        end -- for k2, v2
                        t[ k ] = t2
                    else
                        Fault( "No params[] inherits " .. v )
                    end
                 end
            end -- for k, v
        end
    end -- i = 1, n
    if n > 0 then
        local s
        for k, v in pairs( Data.heirs ) do
            if v then
                if s then
                    s = string.format( "%s &#124; %s", s, k )
                else
                     s = "Circular inherits: " .. k
                 end
                 end
                if type( cx.permit.boole[ true ] ) == "table" then
                    Permit.boole[ true ]  = cx.permit.boole[ true ]
                end
            end
            if type( cx.permit.css ) == "table" then
                for k, v in pairs( cx.permit.css ) do
                    if type( v ) == "table" then
                        Permit.css[ k ] = v
                    end
                end -- for k, v
            end
        end
        for k, v in pairs( Config.basicCnf ) do
            s = type( cx[ k ] )
            if s == "string"  or  s == "table" then
                Config[ v ] = cx[ k ]
             end
             end
         end -- for k, v
         end -- for k, v
        Fault( s )
     end
     end
end -- favorize()
end -- fathers()






local function feasible( about, asked )
local function favorize()
     -- Create description head
     -- Local customization issues
     -- Parameter:
     local boole = { ["font-size"] = "125%" }
    --    about -- table, supposed to contain description
     local l, cx = pcall( mw.loadData,
     --    asked  -- true, if mandatory description
                        TemplateData.frame:getTitle() .. "/config" )
    -- Returns <block>, with head, or nil
     local scripting
    local para = mw.html.create( "div" )
    TemplateData.ltr = not mw.language.getContentLanguage():isRTL()
     local plus, r
     if TemplateData.ltr then
     if about and about.description then
         scripting = "left"
         if type( about.description ) == "string" then
    else
            para:wikitext( about.description )
         scripting = "right"
         else
    end
            para:wikitext( about.description[ 1 ] )
    boole[ "margin-" .. scripting ] = "3em"
            plus = mw.html.create( "ul" )
    Permit.boole = { [false] = { css  = boole,
            for k, v in pairs( about.description[ 2 ] ) do
                                lead = true,
                plus:node( mw.html.create( "li" )
                                show = "&#x2610;" },
                                  :node( mw.html.create( "code" )
                    [true]  = { css = boole,
                                                :wikitext( k ) )
                                lead = true,
                                  :node( mw.html.create( "br" ) )
                                show = "&#x2611;" } }
                                  :wikitext( fair( v ) ) )
    Permit.css  = { }
            end -- for k, v
    for k, v in pairs( Permit.colors ) do
            if Config.loudly then
        if k == "tableheadbg" then
                plus = mw.html.create( "div" )
            k = "tablehead"
                              :css( "background-color",
                                    "#" .. Config.debugmultilang )
                              :node( plus )
            else
                plus:addClass( "templatedata-maintain" )
                    :css( "display", "none" )
            end
         end
         end
     elseif Config.solo and asked then
        Permit.css[ k ] = { ["background-color"]  =  "#" .. v }
        para:addClass( "error" )
     end -- for k, v
             :wikitext( Config.solo )
    if type( cx ) == "table" then
         Data.less = true
        local c, s
    else
        if type( cx.permit ) == "table" then
         para = false
            if type( cx.permit.boole ) == "table" then
     end
                if type( cx.permit.boole[ true ] ) == "table" then
     if para then
                    Permit.boole[ false ]  = cx.permit.boole[ false ]
         if plus then
                end
            r = mw.html.create( "div" )
                if type( cx.permit.boole[ true ] ) == "table" then
                      :node( para )
                    Permit.boole[ true ]  = cx.permit.boole[ true ]
                      :node( plus )
                end
         else
            end
             r = para
             if type( cx.permit.css ) == "table" then
         end
                for k, v in pairs( cx.permit.css ) do
    end
                    if type( v ) == "table" then
     return r
                        Permit.css[ k ] = v
end -- feasible()
                    end
                end -- for k, v
            end
        end
         for k, v in pairs( Config.basicCnf ) do
            s = type( cx[ k ] )
            if s == "string"  or  s == "table" then
                Config[ v ] = cx[ k ]
            end
         end -- for k, v
     end
     if type( Config.subpage ) ~= "string"  or
      type( Config.suffix ) ~= "string" then
         local got = mw.message.new( "templatedata-doc-subpage" )
        local suffix
        if got:isDisabled() then
            suffix = "doc"
        else
            suffix = got:plain()
         end
        if type( Config.subpage ) ~= "string" then
             Config.subpage = string.format( "/%s$", suffix )
         end
        if type( Config.suffix ) ~= "string" then
            Config.suffix = string.format( "%%s/%s", suffix )
        end
     end
end -- favorize()






local function feat()
local function feasible( about, at )
     -- Check and store parameter sequence
     -- Deal with suggestedvalues within parameter
     if Data.source then
    -- Parameter:
        local i = 0
    --    about  -- parameter details
        local s
    --              .suggestedvalues  -- table|string|number,
         for k, v in pairs( Data.tree.params ) do
    --                                    value and possibly description
            if i == 0 then
    --                                    .code  -- mandatory
                Data.order = { }
    --                                    .label  -- table|string
                 i = 1
    --                                    .icon  -- string
                 s = k
    --                                    .class  -- table|string
            else
    --                                    .css    -- table
                 i = 2
    --                                    .style  -- string
                 break -- for k, v
    --                                    .less  -- true: suppress code
            end
    --              .type
         end -- for k, v
    --    at    -- string, with parameter name
         if i > 1 then
    -- Returns
             local pointers = { }
    --    1: mw.html object
             local points  = { }
    --    2: sequence table with values, or nil
            for k, v in pairs( Data.tree.params ) do
     local p = about.suggestedvalues
                 i = facet( k, 1 )
    local s = type( p )
                if i then
    local e, r1, r2, v
                     table.insert( points, i )
    if s == "table" then
                     pointers[ i ] = k
         if #p > 0 then
                     i = facet( k, i )
            for i = 1, #p do
                     if i then
                e = p[ i ]
                         s = "Parameter '%s' detected twice"
                s = type( e )
                         Fault( string.format( s, k ) )
                if s == "table" then
                    if type( e.code ) == "string" then
                        s = mw.text.trim( e.code )
                        if s == "" then
                            e = nil
                        else
                            e.code = s
                        end
                    else
                        e = nil
                        s = string.format( "params.%s.%s[%d] %s",
                                          at,
                                          "suggestedvalues",
                                          i,
                                          "MISSING 'code:'" )
                    end
                elseif s == "string" then
                    s = mw.text.trim( e )
                    if s == "" then
                        e = nil
                        s = string.format( "params.%s.%s[%d] EMPTY",
                                          at, "suggestedvalues", i )
                        Fault( s )
                    else
                        e = { code = s }
                    end
                 elseif s == "number" then
                    e = { code = tostring( e ) }
                 else
                    s = string.format( "params.%s.%s[%d] INVALID",
                                      at, "suggestedvalues", i )
                    Fault( s )
                    e = false
                end
                 if e then
                    v = v  or  { }
                    table.insert( v, e )
                 end
            end -- for i
        else
            Fault( string.format( "params.%s.suggestedvalues %s",
                  at, "NOT AN ARRAY" ) )
        end
    elseif s == "string" then
         s = mw.text.trim( p )
         if s ~= "" then
             v = { }
             table.insert( v,
                          { code = s } )
        end
    elseif s == "number" then
        v = { }
        table.insert( v,
                      { code = tostring( p ) } )
    end
    if v then
        local d, less, story, swift, t, u
        r1 = mw.html.create( "ul" )
        r2 = { }
        for i = 1, #v do
            u = mw.html.create( "li" )
            e = v[ i ]
            table.insert( r2, e.code )
            story = false
            less  = ( e.less == true )
            if not less then
                swift = e.code
                 if e.support then
                    local scream, support
                    s = type( e.support )
                    if s == "string" then
                        support = e.support
                     elseif s == "table" then
                        support = faraway( e.support )
                     else
                        scream = "INVALID"
                    end
                     if support then
                        s = mw.text.trim( support )
                        if s == "" then
                            scream = "EMPTY"
                        elseif s:find( "[%[%]|%<%>]" ) then
                            scream = "BAD PAGE"
                        else
                            support = s
                        end
                    end
                     if scream then
                         s = string.format( "params.%s.%s[%d].support %s",
                                          at,
                                          "suggestedvalues",
                                          i,
                                          scream )
                         Fault( s )
                    else
                        swift = string.format( "[[:%s|%s]]",
                                              support, swift )
                    end
                end
                if about.type:sub( 1, 5 ) == "wiki-"  and
                  swift == e.code then
                    local rooms = { file = 6,
                                    temp = 10,
                                    user = 2 }
                    local ns = rooms[ about.type:sub( 6, 9 ) ]  or  0
                    t = mw.title.makeTitle( ns, swift )
                    if t and t.exists then
                        swift = string.format( "[[:%s|%s]]",
                                              t.prefixedText, swift )
                     end
                     end
                end
                u:node( mw.html.create( "code" )
                              :css( "white-space", "nowrap" )
                              :wikitext( swift ) )
            end
            if e.class then
                s = type( e.class )
                if s == "string" then
                    u:addClass( e.class )
                elseif s == "table" then
                    for k, s in pairs( e.class ) do
                        u:addClass( s )
                    end -- for k, s
                 else
                 else
                     s = "Parameter '%s' not detected"
                     s = string.format( "params.%s.%s[%d].class INVALID",
                     Fault( string.format( s, k ) )
                                      at, "suggestedvalues", i )
                     Fault( s )
                 end
                 end
             end -- for k, v
             end
             table.sort( points )
             if e.css then
             for i = 1, #points do
                if type( e.css ) == "table" then
                 table.insert( Data.order, pointers[ points[ i ] ] )
                    u:css( e.css )
             end -- i = 1, #points
                else
        elseif s then
                    s = string.format( "params.%s.%s[%d].css INVALID",
            table.insert( Data.order, s )
                                      at, "suggestedvalues", i )
        end
                    Fault( s )
    end
                end
end -- feat()
             end
 
            if e.style then
 
                if type( e.style ) == "string" then
 
                    u:cssText( e.style )
local function feature( access )
                 else
    -- Create table row for parameter, check and display violations
                    s = string.format( "params.%s.%s[%d].style INVALID",
    -- Parameter:
                                      at, "suggestedvalues", i )
    --    access  -- string, with name
                    Fault( s )
    -- Returns <tr>
                end
    local mode, s, status
             end
    local fine    = function ( a )
            if about.type == "wiki-file-name"  and  not e.icon then
                        s = mw.text.trim( a )
                e.icon = e.code
                        return a == s and
            end
                              a ~= "" and
            if e.label then
                              not a:find( "%|=\n" ) and
                s = type( e.label )
                              not a:find( "%s%s" )
                if s == "string" then
                    s = mw.text.trim( e.label )
                    if s == "" then
                        s = string.format( "params.%s.%s[%d].label %s",
                                          at,
                                          "suggestedvalues",
                                          i,
                                          "EMPTY" )
                        Fault( s )
                    else
                        story = s
                    end
                elseif s == "table" then
                    story = faraway( e.label )
                else
                    s = string.format( "params.%s.%s[%d].label INVALID",
                                      at, "suggestedvalues", i )
                    Fault( s )
                end
            end
            s = false
            if type( e.icon ) == "string" then
                t = mw.title.makeTitle( 6, e.icon )
                if t and t.file.exists then
                    local g = mw.html.create( "span" )
                    s = string.format( "[[%s|16px]]", t.prefixedText )
                    g:attr( "role", "presentation" )
                    :wikitext( s )
                    s = tostring( g )
                end
            end
            if not s  and  not less  and  e.label then
                s = mw.ustring.char( 0x2013 )
            end
            if s then
                d = mw.html.create( "span" )
                          :wikitext( s )
                if TemplateData.ltr then
                    if not less then
                        d:css( "margin-left", "0.5em" )
                    end
                    if story then
                        d:css( "margin-right", "0.5em" )
                    end
                else
                    if not less then
                        d:css( "margin-right", "0.5em" )
                    end
                    if story then
                        d:css( "margin-left", "0.5em" )
                     end
                     end
     local begin  = mw.html.create( "td" )
                end
    local code    = mw.html.create( "code" )
                u:node( d )
    local desc    = mw.html.create( "td" )
            end
    local legal  = true
            if story then
     local param  = Data.tree.params[ access ]
                u:wikitext( story )
     local ranking = { "required", "suggested", "optional", "deprecated" }
            end
    local r      = mw.html.create( "tr" )
            r1:newline()
    local sort, typed
              :node( u )
        end -- for i
    end
     if not r1 then
        Fault( string.format( "params.%s.suggestedvalues INVALID", at ) )
        r1 = mw.html.create( "code" )
                    :addClass( "error" )
                    :wikitext( "INVALID" )
     end
     return r1, r2
end -- feasible()


    for k, v in pairs( param ) do
        if v == "" then
            param[ k ] = false
        end
    end -- for k, v


    -- label
    sort = param.label or access
    if sort:match( "^%d+$" ) then
        begin:attr( "data-sort-value",
                    string.format( "%05d", tonumber( sort ) ) )
    end
    begin:css( "font-weight", "bold" )
        :wikitext( sort )


    -- name and aliases
local function feat()
    code:css( "font-size", "92%" )
     -- Check and store parameter sequence
        :css( "white-space", "nowrap" )
     if Data.source then
        :wikitext( access )
         local i = 0
     if not fine( access ) then
         local s
        code:addClass( "error" )
         for k, v in pairs( Data.tree.params ) do
        Fault( string.format( "Bad ID params.<code>%s</code>", access ) )
             if i == 0 then
        legal = false
                 Data.order = { }
        begin:attr( "data-sort-value",  " " .. sort )
                 i = 1
     end
                 s = k
    code = mw.html.create( "td" )
             else
                  :node( code )
                 i = 2
    if access:match( "^%d+$" ) then
                 break -- for k, v
         code:attr( "data-sort-value",
             end
                  string.format( "%05d", tonumber( access ) ) )
    end
    if type( param.aliases ) == "table" then
         local lapsus
         for k, v in pairs( param.aliases ) do
            code:tag( "br" )
             if type( v ) == "string" then
                 if not fine( v ) then
                    lapsus = true
                    code:node( mw.html.create( "span" )
                                      :addClass( "error" )
                                      :css( "font-style", "italic" )
                                      :wikitext( "string" ) )
                 end
                 code:wikitext( s )
             else
                 lapsus = true
                 code:node( mw.html.create( "code" )
                                  :addClass( "error" )
                                  :wikitext( type( v ) ) )
             end
         end -- for k, v
         end -- for k, v
         if lapsus then
         if i > 1 then
            s = string.format( "params.<code>%s</code>.aliases", access )
             local pointers = { }
            Fault(  factory( "invalid-value" ):gsub( "$1", s )  )
            local points  = { }
             legal = false
            local given   = { }
        end
             for k, v in pairs( Data.tree.params ) do
    end
                 i = facet( k, 1 )
 
                 if type( v ) == "table" then
    -- description etc.
                    if type( v.label ) == "string" then
    s = feasible( param )
                        s = mw.text.trim( v.label )
    if s then
                        if s == "" then
        desc:node( s )
                            s = k
    end
                         end
    if param.default or param.example or param.autovalue then
                    else
        local details = { "default", "example", "autovalue" }
                        s = k
        local dl      = mw.html.create( "dl" )
        local dd, section, show
        for i = 1, #details do
            s   = details[ i ]
             show = param[ s ]
            if show then
                dd      = mw.html.create( "dd" )
                 section = factory( "doc-param-" .. s )
                 if param.type == "boolean"   and
                  ( show == "0" or show == "1" ) then
                    local boole = Permit.boole[ ( show == "1" ) ]
                    if boole.lead == true then
                         dd:node( mw.html.create( "code" )
                                        :wikitext( show ) )
                          :wikitext( " " )
                     end
                     end
                     if type( boole.show ) == "string" then
                     if given[ s ] then
                        local v = mw.html.create( "span" )
                        if given[ s ] == 1 then
                                        :wikitext( boole.show )
                            local scream = "Parameter label '%s' detected multiple times"
                        if boole.css then
                            Fault( string.format( scream, s ) )
                             v:css( boole.css )
                             given[ s ] = 2
                         end
                         end
                         dd:node( v )
                    else
                         given[ s ] = 1
                     end
                     end
                     if type( boole.suffix ) == "string" then
                end
                        dd:wikitext( boole.suffix )
                if i then
                    end
                     table.insert( points, i )
                     if boole.lead == false then
                    pointers[ i ] = k
                         dd:wikitext( " " )
                    i = facet( k, i )
                          :node( mw.html.create( "code" )
                     if i then
                                        :wikitext( show ) )
                         s = "Parameter '%s' detected twice"
                        Fault( string.format( s, k ) )
                     end
                     end
                 else
                 else
                     dd:wikitext( show )
                     s = "Parameter '%s' not detected"
                    Fault( string.format( s, k ) )
                 end
                 end
                dl:node( mw.html.create( "dt" )
            end -- for k, v
                                :wikitext( section ) )
            table.sort( points )
                  :node( dd )
            for i = 1, #points do
             end
                table.insert( Data.order,  pointers[ points[ i ] ] )
        end -- i = 1, #details
             end -- i = 1, #points
         desc:node( dl )
         elseif s then
            table.insert( Data.order, s )
        end
     end
     end
end -- feat()


     -- type
local function feature( access )
     if param.type then
    -- Create table row for parameter, check and display violations
        s    = Permit.types[ param.type ]
    -- Parameter:
        typed = mw.html.create( "td" )
    --     access  -- string, with name
        if s then
     -- Returns <tr>
            if s == "string" then
    local mode, s, status
                Data.params[ access ].type = s
     local fine    = function ( a )
                typed:wikitext( factory( "doc-param-type-" .. s ) )
                        s = mw.text.trim( a )
                    :tag( "br" )
                        return a == s and
                typed:node( mw.html.create( "span" )
                              a ~= "" and
                                  :addClass( "error" )
                              not a:find( "%|=\n" ) and
                                  :wikitext( param.type ) )
                              not a:find( "%s%s" )
                Data.lasting = true
                    end
            else
    local begin  = mw.html.create( "td" )
                local support = Config[ "support4" .. param.type ]
    local code    = mw.html.create( "code" )
                s = factory( "doc-param-type-" .. param.type )
    local desc    = mw.html.create( "td" )
                if support then
    local eager  = mw.html.create( "td" )
                    s = string.format( "[[%s|%s]]", support, s )
    local legal  = true
                end
    local param  = Data.tree.params[ access ]
                typed:wikitext( s )
    local ranking = { "required", "suggested", "optional", "deprecated" }
            end
    local r      = mw.html.create( "tr" )
        else
    local styles = "mw-templatedata-doc-param-"
            Data.params[ access ].type = "unknown"
    local sort, typed
            typed:addClass( "error" )
 
                :wikitext( "INVALID" )
    for k, v in pairs( param ) do
            s = string.format( "params.<code>%s</code>.type", access )
        if v == "" then
            Fault( factory( "invalid-value" ):gsub( "$1", s )  )
             param[ k ] = false
             legal = false
         end
         end
     else
     end -- for k, v
        typed = mw.html.create( "td" )
                  :wikitext( factory( "doc-param-type-unknown" ) )
    end


     -- status
     -- label
     if param.required then
     sort = param.label or access
        mode = 1
    if sort:match( "^%d+$" ) then
        if param.deprecated then
        begin:attr( "data-sort-value",
            Fault( string.format( "Required deprecated <code>%s</code>",
                    string.format( "%05d", tonumber( sort ) ) )
                                  access ) )
            legal = false
        end
    elseif param.deprecated then
        mode = 4
    elseif param.suggested then
        mode = 2
    else
        mode = 3
     end
     end
     status = ranking[ mode ]
     begin:css( "font-weight", "bold" )
    ranking = factory( "doc-param-status-" .. status )
        :wikitext( sort )
     if mode == 1  or  mode == 4 then
 
        ranking = mw.html.create( "span" )
     -- name and aliases
                        :css( "font-weight", "bold" )
    code:css( "font-size", "92%" )
                        :wikitext( ranking )
        :css( "white-space", "nowrap" )
         if type( param.deprecated ) == "string" then
        :wikitext( access )
            ranking:tag( "br" )
    if not fine( access ) then
            ranking:wikitext( param.deprecated )
         code:addClass( "error" )
         end
        Fault( string.format( "Bad ID params.<code>%s</code>", access ) )
        legal = false
        begin:attr( "data-sort-value",  " " .. sort )
    end
    code = mw.html.create( "td" )
                  :addClass( styles .. "name" )
                  :node( code )
    if access:match( "^%d+$" ) then
         code:attr( "data-sort-value",
                  string.format( "%05d", tonumber( access ) ) )
     end
     end
 
    if type( param.aliases ) == "table" then
    -- <tr>
        local lapsus, syn
    r:attr( "id""templatedata:" .. mw.uri.anchorEncode( access ) )
        for k, v in pairs( param.aliases ) do
    :css( Permit.css[ status ] )
            code:tag( "br" )
    :node( begin )
            if type( v ) == "string" then
    :node( code )
                if not fine( v ) then
    :node( desc )
                    lapsus = true
    :node( typed )
                    code:node( mw.html.create( "span" )
    :node( mw.html.create( "td" )
                                      :addClass( "error" )
                  :attr( "data-sort-value", tostring( mode ) )
                                      :css( "font-style", "italic" )
                  :node( ranking ) )
                                      :wikitext( "string" ) )
    :newline()
                        :wikitext( s )
    if not legal then
                else
        r:css( "border", "#FF0000 3px solid" )
                    syn = mw.html.create( "span" )
                                :addClass( styles .. "alias" )
                                :css( "white-space", "nowrap" )
                                :wikitext( s )
                    code:node( syn )
                end
            else
                lapsus = true
                code:node( mw.html.create( "code" )
                                  :addClass( "error" )
                                  :wikitext( type( v ) ) )
            end
        end -- for k, v
        if lapsus then
            s = string.format( "params.<code>%s</code>.aliases", access )
            Fault(  factory( "invalid-value" ):gsub( "$1", s )  )
            legal = false
        end
     end
     end
    return r
end -- feature()


 
    -- description etc.
 
    s = fashioned( param )
local function features()
     if s then
     -- Create <table> for parameters
        desc:node( s )
    -- Returns <table>, or nil
     end
     local r
     if param.style then
     if Data.tree and Data.tree.params then
         s = type( param.style )
         local tbl  = mw.html.create( "table" )
        if s == "table" then
                            :addClass( "wikitable" )
            desc:css( param.style )
         local tr    = mw.html.create( "tr" )
         elseif s == "string" then
        feat()
             desc:cssText( param.style )
        if Data.order  and  #Data.order > 1 then
             tbl:addClass( "sortable" )
         end
         end
--      if Config.classTable then
    end
--          tbl:addClass( Config.classTable )
    if param.suggestedvalues or
--      end
      param.default or
        if Config.cssTable then
      param.example or
            if type( Config.cssTable ) == "table" then
      param.autovalue then
                tbl:css( Config.cssTable )
        local details = { "suggestedvalues",
            elseif type( Config.cssTable ) == "string" then
                          "default",
                -- deprecated
                          "example",
                tbl:cssText( Config.cssTable )
                          "autovalue" }
             end
        local dl      = mw.html.create( "dl" )
        end
        local dd, section, show
        tr:node( mw.html.create( "th" )
        for i = 1, #details do
                        :attr( "colspan", "2" )
             s    = details[ i ]
                        :css( Permit.css.tablehead )
            show = param[ s ]
                        :wikitext( factory( "doc-param-name" ) ) )
            if show then
          :node( mw.html.create( "th" )
                dd      = mw.html.create( "dd" )
                        :css( Permit.css.tablehead )
                section = factory( "doc-param-" .. s )
                        :wikitext( factory( "doc-param-desc" ) ) )
                if param.type == "boolean"  and
          :node( mw.html.create( "th" )
                  ( show == "0" or show == "1" ) then
                         :css( Permit.css.tablehead )
                    local boole = Permit.boole[ ( show == "1" ) ]
                         :wikitext( factory( "doc-param-type" ) ) )
                    if boole.lead == true then
          :node( mw.html.create( "th" )
                        dd:node( mw.html.create( "code" )
                         :css( Permit.css.tablehead )
                                        :wikitext( show ) )
                         :wikitext( factory( "doc-param-status" ) ) )
                          :wikitext( " " )
        tbl:newline()
                    end
--        :node( mw.html.create( "thead" )
                    if type( boole.show ) == "string" then
                        :node( tr )
                        local v = mw.html.create( "span" )
--              )
                                        :attr( "aria-hidden", "true" )
          :newline()
                                        :wikitext( boole.show )
        if Data.order then
                         if boole.css then
            for i = 1, #Data.order do
                            v:css( boole.css )
                 tbl:node( feature( Data.order[ i ] ) )
                         end
            end -- for i = 1, #Data.order
                        dd:node( v )
        end
                    end
        if Config.cssTabWrap then
                    if type( boole.suffix ) == "string" then
            r = mw.html.create( "div" )
                         dd:wikitext( boole.suffix )
            if type( Config.cssTabWrap ) == "table" then
                    end
                r:css( Config.cssTabWrap )
                    if boole.lead == false then
            elseif type( Config.cssTabWrap ) == "string" then
                         dd:wikitext( " " )
                -- deprecated
                          :node( mw.html.create( "code" )
                r:cssText( Config.cssTabWrap )
                                        :wikitext( show ) )
                    end
                elseif s == "suggestedvalues" then
                    local html, values = feasible( param, access )
                    dd:newline()
                      :node( html )
                    Data.params[ access ].suggestedvalues = values
                 else
                    dd:wikitext( show )
                end
                dl:node( mw.html.create( "dt" )
                                :wikitext( section ) )
                  :node( dd )
             end
             end
            r:node( tbl )
        end -- i = 1, #details
         else
        desc:node( dl )
             r = tbl
    end
 
    -- type
    if type( param.type ) == "string" then
        param.type = mw.text.trim( param.type )
         if param.type == "" then
             param.type = false
         end
         end
     end
     end
     return r
     if param.type then
end -- features()
        s    = Permit.types[ param.type ]
 
        typed = mw.html.create( "td" )
 
                  :addClass( styles .. "type" )
 
        if s then
local function finalize( advance )
            if s == "string" then
    -- Wrap presentation into frame
                Data.params[ access ].type = s
    -- Parameter:
                typed:wikitext( factory( "doc-param-type-" .. s ) )
    --     advance  -- true, for nice
                    :tag( "br" )
    -- Returns string
                typed:node( mw.html.create( "span" )
    local r, lapsus
                                  :addClass( "error" )
    if Data.div then
                                  :wikitext( param.type ) )
        r = tostring( Data.div )
                Data.lasting = true
    elseif Data.strip then
            else
        r = Data.strip
                local support = Config[ "support4" .. param.type ]
    else
                s = factory( "doc-param-type-" .. param.type )
        lapsus = true
                if support then
        r      = ""
                    s = string.format( "[[%s|%s]]", support, s )
    end
                end
    r = r .. failures()
                typed:wikitext( s )
    if Data.source then
            end
        local live = ( advance or lapsus )
        else
        if not live then
            Data.params[ access ].type = "unknown"
             live = TemplateData.frame:preprocess( "{{REVISIONID}}" )
            typed:addClass( "error" )
             live = ( live == "" )
                :wikitext( "INVALID" )
             s = string.format( "params.<code>%s</code>.type", access )
             Fault(  factory( "invalid-value" ):gsub( "$1", s )  )
            legal = false
         end
         end
         if live then
    else
             r = r .. fancy( advance, lapsus )
        typed = mw.html.create( "td" )
                  :wikitext( factory( "doc-param-type-unknown" ) )
        Data.params[ access ].type = "unknown"
         if param.default then
             Data.params[ access ].default = nil
            Fault( "Default value requires <code>type</code>" )
            legal = false
         end
         end
     end
     end
     return r
     -- status
end -- finalize()
    if param.required then
 
        mode = 1
 
        if param.autovalue then
 
            Fault( string.format( "autovalued <code>%s</code> required",
local function find()
                                  access ) )
    -- Find JSON data within page source (title)
            legal = false
    -- Returns string, or nil
        end
    local s = Data.title:getContent()
        if param.default then
    local i, j = s:find( "<templatedata>", 1, true )
            Fault( string.format( "Defaulted <code>%s</code> required",
    local r
                                  access ) )
    if i then
            legal = false
        local k = s:find( "</templatedata>", j, true )
        if k then
          r = mw.text.trim( s:sub( j + 1,  k - 1 ) )
         end
         end
    end
         if param.deprecated then
    return r
             Fault( string.format( "Required deprecated <code>%s</code>",
end -- find()
                                  access ) )
 
            legal = false
 
 
local function flat( adjust )
    -- Remove formatting from text string
    -- Parameter:
    --    arglist  -- string, to be stripped, or nil
    -- Returns string, or nil
    local r
    if adjust then
        r = adjust:gsub( "\n", " " )
         if r:find( "<noexport>", 1, true ) then
             r = r:gsub( "<noexport>(.*)</noexport>", "" )
         end
         end
         if r:find( "''", 1, true ) then
    elseif param.deprecated then
            r = r:gsub( "'''", "" ):gsub( "''", "" )
        mode = 4
        end
    elseif param.suggested then
         if r:find( "<", 1, true ) then
        mode = 2
             local Text = Fetch( "Text" )
    else
             r = Text.getPlain( r )
         mode = 3
    end
    status = ranking[ mode ]
    ranking = factory( "doc-param-status-" .. status )
    if mode == 1 or  mode == 4 then
        ranking = mw.html.create( "span" )
                        :css( "font-weight", "bold" )
                        :wikitext( ranking )
         if type( param.deprecated ) == "string" then
             ranking:tag( "br" )
             ranking:wikitext( param.deprecated )
         end
         end
         if r:find( "[", 1, true ) then
         if param.suggested  and  mode == 4 then
             local WLink = Fetch( "WLink" )
             s = string.format( "Suggesting deprecated <code>%s</code>",
            if WLink.isBracketedURL( r ) then
                              access )
                r = r:gsub( "%[([hf]tt?ps?://%S+) [^%]]+%]", "%1" )
             Fault( s )
             end
             legal = false
            r = WLink.getPlain( r )
        end
        if r:find( "&", 1, true ) then
             r = mw.text.decode( r )
         end
         end
     end
     end
     return r
     eager:attr( "data-sort-value", tostring( mode ) )
end -- flat()
                :node( ranking )
                :addClass( string.format( "%sstatus-%s",
                                          styles, status ) )


 
    -- <tr>
 
    r:attr( "id",  "templatedata:" .. mw.uri.anchorEncode( access ) )
local function flush()
    :css( Permit.css[ status ] )
     -- JSON encode narrowed input; obey unnamed (numerical) parameters
    :addClass( styles .. status )
     -- Returns <templatedata> JSON string
    :node( begin )
    :node( code )
    :node( desc )
    :node( typed )
    :node( eager )
    :newline()
    if not legal then
        r:css( "border", "#FF0000 3px solid" )
    end
    return r
end -- feature()
 
 
 
local function features()
     -- Create <table> for parameters
     -- Returns <table>, or nil
     local r
     local r
     if Data.tag then
     if Data.tree and Data.tree.params then
         r = mw.text.jsonEncode( Data.tag ):gsub( "%}$", "," )
         local tbl = mw.html.create( "table" )
    else
         local tr  = mw.html.create( "tr" )
         r = "{"
        feat()
    end
        if Data.order and  #Data.order > 1 then
    r = r .. "\n\"params\":{"
            tbl:addClass( "sortable" )
    if Data.order then
         end
        local sep = ""
         if type( Config.classTable ) == "table" then
         local s
            for k, v in pairs( Config.classTable ) do
         for i = 1, #Data.order do
                tbl:addClass( v )
             = Data.order[ i ]
             end -- for k, v
            r  = string.format( "%s%s\n%s:%s",
        end
                                r,
        if type( Config.cssTable ) == "table" then
                                sep,
            tbl:css( Config.cssTable )
                                mw.text.jsonEncode( s ),
        end
                                mw.text.jsonEncode( Data.params[ s ] ) )
        tr:node( mw.html.create( "th" )
            sep = ",\n"
                        :attr( "colspan", "2" )
        end -- for i = 1, #Data.order
                        :css( Permit.css.tablehead )
    end
                        :wikitext( factory( "doc-param-name" ) ) )
    r = r .. "\n}\n}"
          :node( mw.html.create( "th" )
    return r
                        :css( Permit.css.tablehead )
end -- flush()
                        :wikitext( factory( "doc-param-desc" ) ) )
 
          :node( mw.html.create( "th" )
 
                        :css( Permit.css.tablehead )
 
                        :wikitext( factory( "doc-param-type" ) ) )
local function focus( access )
          :node( mw.html.create( "th" )
    -- Check components; focus multilingual description, build trees
                        :css( Permit.css.tablehead )
    -- Parameter:
                        :wikitext( factory( "doc-param-status" ) ) )
    --    access  -- string, name of parameter, nil for root
        tbl:newline()
    local f = function ( a, at )
--         :node( mw.html.create( "thead" )
                     local r
                        :node( tr )
                     if at then
--             )
                        r = string.format( "<code>params.%s</code>", at )
          :newline()
                     else
        if Data.order then
                         r = "''root''"
            local leave, s
            for i = 1, #Data.order do
                s = Data.order[ i ]
                if s:sub( 1, 1 ) == "=" then
                     leave = true
                    tbl:node( fatten( s ) )
                     Data.order[ i ] = false
                elseif s:match( "[=|]" ) then
                    Fault( string.format( "Bad param <code>%s</code>",
                                          s ) )
                else
                    tbl:node( feature( s ) )
                end
            end -- for i = 1, #Data.order
            if leave then
                for i = #Data.order, 1, -1 do
                     if not Data.order[ i ] then
                         table.remove( Data.order, i )
                     end
                     end
                    if a then
                 end -- for i = #Data.order, 1, -1
                        r = string.format( "%s<code>.%s</code>", r, a )
                    end
                    return r
                 end
    local parent
    if access then
        parent = Data.got.params[ access ]
    else
        parent = Data.got
    end
    if type( parent ) == "table" then
        local elem, got, permit, s, scope, slot, tag, target
        if access then
            permit = Permit.params
            if type( access ) == "number" then
                slot = tostring( access )
            else
                slot = access
             end
             end
        else
             Data.tag.paramOrder = Data.order
             permit = Permit.root
         end
         end
         for k, v in pairs( parent ) do
         if Config.cssTabWrap or Data.scroll then
             scope = permit[ k ]
             r = mw.html.create( "div" )
             if scope then
             if type( Config.cssTabWrap ) == "table" then
                 s = type( v )
                 r:css( Config.cssTabWrap )
                 if s == "string" and  k ~= "format" then
            elseif type( Config.cssTabWrap ) == "string" then
                    v = mw.text.trim( v )
                -- deprecated
                end
                 r:cssText( Config.cssTabWrap )
                if scope:find( s, 1, true ) then
            end
                    if scope:find( "I18N", 1, true ) then
            if Data.scroll then
                        if s == "string" then
                r:css( "height",  Data.scroll )
                            elem = fair( v )
                :css( "overflow", "auto" )
                         else
            end
                            local translated
            r:node( tbl )
                            v, translated = faraway( v )
        else
                             if v then
            r = tbl
                                 if translated and
        end
                                   k == "description" then
    end
                                     elem = { [ 1 ] = fair( v ),
    return r
                                            [ 2 ] = translated }
end -- features()
                                else
 
                                     elem = fair( v )
 
 
local function fellow( any, assigned, at )
    -- Check sets[] parameter and issue error message, if necessary
    -- Parameter:
    --    any      -- should be number
    --    assigned -- parameter name
    --    at        -- number, of set
    local s
    if type( any ) ~= "number" then
        s = "<code>sets[%d].params[%s]</code>??"
        Fault( string.format( s,
                              at,
                              mw.text.nowiki( tostring( any ) ) ) )
    elseif type( assigned ) == "string" then
        if not Data.got.params[ assigned ] then
            s = "<code>sets[%d].params %s</code> is undefined"
            Fault( string.format( s, at, assigned ) )
        end
    else
        s = "<code>sets[%d].params[%d] = %s</code>??"
        Fault( string.format( s, k,  type( assigned ) ) )
    end
end -- fellow()
 
 
 
local function fellows()
    -- Check sets[] and issue error message, if necessary
    local s
    if type( Data.got.sets ) == "table" then
        if type( Data.got.params ) == "table" then
            for k, v in pairs( Data.got.sets ) do
                if type( k ) == "number" then
                    if type( v ) == "table" then
                         for ek, ev in pairs( v ) do
                             if ek == "label" then
                                s = type( ev )
                                 if s ~= "string" and
                                   s ~= "table" then
                                     s = "<code>sets[%d].label</code>??"
                                     Fault( string.format( s, k ) )
                                 end
                                 end
                            elseif ek == "params"  and
                                type( ev ) == "table" then
                                for pk, pv in pairs( ev ) do
                                    fellow( pk, pv, k )
                                end -- for pk, pv
                             else
                             else
                                 elem = false
                                 ek = mw.text.nowiki( tostring( ek ) )
                                s  = "<code>sets[%d][%s]</code>??"
                                Fault( string.format( s, k, ek ) )
                             end
                             end
                         end
                         end -- for ek, ev
                         if v then
                    else
                            if scope:find( "nowiki", 1, true ) then
                         k = mw.text.nowiki( tostring( k ) )
                                elem = mw.text.nowiki( v )
                        v = mw.text.nowiki( tostring( v ) )
                            else
                        s = string.format( "<code>sets[%s][%s]</code>??",
                                v = flat( v )
                                          k, v )
                            end
                        Fault( s )
                        end
                    end
                    else
                else
                        if k == "params"  and  not access then
                    k = mw.text.nowiki( tostring( k ) )
                            v    = nil
                    s = string.format( "<code>sets[%s]</code> ?????", k )
                            elem = nil
                    Fault( s )
                        elseif k == "format"  and  not access then
                end
                            elem = mw.text.decode( v )
            end -- for k, v
                            v    = nil
        else
                        elseif k == "inherits" then
            s = "<code>params</code> required for <code>sets</code>"
                            elem = v
            Fault( s )
                            if not Data.heirs then
        end
                                Data.heirs = { }
    else
                            end
        s = "<code>sets</code> needs to be of <code>object</code> type"
                            Data.heirs[ slot ] = v
        Fault( s )
                            v                  = nil
    end
                        elseif s == "string" then
end -- fellows()
                            v    = mw.text.nowiki( v )
 
                            elem = v
 
                        else
 
                            elem = v
local function finalize( advance )
                        end
    -- Wrap presentation into frame
                    end
    -- Parameter:
                    if type( elem ) ~= "nil" then
    --    advance  -- true, for nice
                        if not target then
    -- Returns string
                            if access then
    local r, lapsus
                                if not Data.tree.params then
    if Data.div then
                                    Data.tree.params = { }
        r = tostring( Data.div )
                                end
    elseif Data.strip then
                                Data.tree.params[ slot ] = { }
        r = Data.strip
                                target = Data.tree.params[ slot ]
    else
                            else
        lapsus = true
                                Data.tree = { }
        r      = ""
                                target    = Data.tree
    end
                            end
    r = r .. failures()
                        end
    if Data.source then
                        target[ k ] = elem
        local live = ( advance or lapsus )
                        elem        = false
        if not live then
                    end
            live = TemplateData.frame:preprocess( "{{REVISIONID}}" )
                    if type( v ) ~= "nil" then
            live = ( live == "" )
                        if not tag then
        end
                            if access then
        if live then
                                if not Data.params then
             r = r .. fancy( advance, lapsus )
                                    Data.params = { }
         end
                                end
     end
                                Data.params[ slot ] = { }
     return r
                                tag = Data.params[ slot ]
end -- finalize()
                            else
                                Data.tag = { }
                                tag      = Data.tag
                            end
                        end
                        tag[ k ] = v
                    end
                else
                    s = string.format( "Type <code>%s</code> bad for %s",
                                      scope,  f( k, slot ) )
                    Fault( s )
                end
             else
                Fault( "Unknown component " .. f( k, slot ) )
            end
         end -- for k, v
     else
        Fault( f() .. " needs to be of <code>object</code> type" )
     end
end -- focus()






local function format()
local function find()
     -- Build formatted element
     -- Find JSON data within page source (title)
     -- Returns <inline>
     -- Returns string, or nil
     local source = Data.tree.format:lower()
     local s = Data.title:getContent()
     local r, s
     local i, j = s:find( "<templatedata>", 1, true )
     if source == "inline"  or  source == "block" then
    local r
        r = mw.html.create( "i" )
     if i then
                  :wikitext( source )
        local k = s:find( "</templatedata>", j, true )
     else
        if k then
         local code
          r = mw.text.trim( s:sub( j + 1,  k - 1 ) )
         if source:find( "|", 1, true ) then
        end
             local scan = "^[\n ]*%{%{[\n _]*|[\n _]*=[\n _]*%}%}[\n ]*$"
    end
            if source:match( scan, 1, true ) then
    return r
                code = source:gsub( "\n", "N" )
end -- find()
             else
 
                s = mw.text.nowiki( source ):gsub( "\n", "&#92;n" )
 
                s = tostring( mw.html.create( "code" )
 
                                    :wikitext( s ) )
local function flat( adjust )
                Fault( "Invalid format " .. s )
     -- Remove formatting from text string for VE
                 source = false
    -- Parameter:
    --    arglist  -- string, to be stripped, or nil
    -- Returns string, or nil
    local r
    if adjust then
         r = adjust:gsub( "\n", " " )
         if r:find( "<noexport>", 1, true ) then
             r = r:gsub( "<noexport>.*</noexport>", "" )
        end
        if r:find( "<exportonly>", 1, true ) then
            r = r:gsub( "</?exportonly>", "" )
        end
        if r:find( "''", 1, true ) then
             r = r:gsub( "'''", "" ):gsub( "''", "" )
        end
        if r:find( "<", 1, true ) then
            local Text = Fetch( "Text" )
            r = Text.getPlain( r:gsub( "<br */?>", "\r\n" ) )
        end
        if r:find( "[", 1, true ) then
            local WLink = Fetch( "WLink" )
            if WLink.isBracketedURL( r ) then
                 r = r:gsub( "%[([hf]tt?ps?://%S+) [^%]]+%]", "%1" )
             end
             end
        else
             r = WLink.getPlain( r )
             local words = mw.text.split( source, "%s+" )
        end
            local show, start, unknown
        if r:find( "&", 1, true ) then
            for i = 1, #words do
             r = mw.text.decode( r )
                s = words[ i ]
            if r:find( "&shy;", 1, true ) then
                if i == 1 then
                r = r:gsub( "&shy;", "" )
                    start = s
                end
                if Permit.builder[ s ] == start then
                    Permit.builder[ s ] = true
                else
                    if unknown then
                        unknown = string.format( "%s %s", unknown, s )
                    else
                        unknown = s
                    end
                end
             end -- i = 1, #words
            if unknown then
                s = tostring( mw.html.create( "code" )
                                    :css( "white-space", "nowrap" )
                                    :wikitext( s ) )
                Fault( "Unknown/misplaced format keyword " .. s )
                source = false
                start  = false
             end
             end
            if start == "inline" then
        end
                if Permit.builder.half == true then
    end
                    show = "inline half"
    return r
                    code = "{{_ |_=_}}"
end -- flat()
                elseif Permit.builder.grouped == true then
 
                    show = "inline grouped"
 
                    code = "{{_ | _=_}}"
 
                elseif Permit.builder.spaced == true then
local function flush()
                    show = "inline spaced"
    -- JSON encode narrowed input; obey unnamed (numerical) parameters
                    code = "{{_ | _ = _ }}"
    -- Returns <templatedata> JSON string
                end
    local r
             elseif start == "block" then
    if Data.tag then
                local space  = ""     -- amid "|" and name
        r = mw.text.jsonEncode( Data.tag ):gsub( "%}$", "," )
                local spaced = " "    -- preceding "="
    else
                local spacer = " "    -- following "="
        r = "{"
                local suffix = "N"    -- closing "}}" on new line
    end
                show = "block"
    r = r .. "\n\"params\":{"
                if Permit.builder.indent == true then
    if Data.order then
                    start = " "
        local sep = ""
                    show = "block indent"
        local s
                else
        for i = 1, #Data.order do
                    start = ""
            s  = Data.order[ i ]
                end
             = string.format( "%s%s\n%s:%s",
                if Permit.builder.compressed == true then
                                r,
                    spaced = ""
                                sep,
                    spacer = ""
                                mw.text.jsonEncode( s ),
                     show  = show .. " compressed"
                                mw.text.jsonEncode( Data.params[ s ] ) )
                     if Permit.builder.last == true then
            sep = ",\n"
                         show = show .. " last"
        end -- for i = 1, #Data.order
    end
    r = r .. "\n}\n}"
    return r
end -- flush()
 
 
 
local function focus( access )
    -- Check components; focus multilingual description, build trees
    -- Parameter:
    --    access  -- string, name of parameter, nil for root
    local f = function ( a, at )
                     local r
                     if at then
                         r = string.format( "<code>params.%s</code>", at )
                     else
                     else
                         suffix = ""
                         r = "''root''"
                     end
                     end
                else
                     if a then
                     if Permit.builder.lead == true then
                         r = string.format( "%s<code>.%s</code>", r, a )
                         show  = show .. " lead"
                        space = " "
                     end
                     end
                     if Permit.builder.align == true then
                     return r
                        if type( Data.got ) == "table"  and
                end
                          type( Data.got.params ) == "table" then
    local parent
                            local n = 0
    if access then
                            for k, v in pairs( Data.got.params ) do
        parent = Data.got.params[ access ]
                                if type( v ) == "table"  and
    else
                                  not v.deprecated  and
        parent = Data.got
                                  type( k ) == "string" then
    end
                                    k = mw.ustring.len( k )
    if type( parent ) == "table" then
                                    if k > n then
        local elem, got, permit, s, scope, slot, tag, target
                                        n = k
        if access then
                                    end
            permit = Permit.params
                                end
            if type( access ) == "number" then
                            end -- for k, v
                 slot = tostring( access )
                            if n > 1 then
             else
                                spaced = string.rep( "_", n ) .. " "
                 slot = access
                            end
                        end
                        show = show .. " align"
                    elseif Permit.builder.after == true then
                        spaced = ""
                        show  = show .. " after"
                    elseif Permit.builder.dense == true then
                        spaced = ""
                        spacer = ""
                        show  = show .. " dense"
                    end
                    if Permit.builder.last == true then
                        suffix = spacer
                        show  = show .. " last"
                    end
                end
                 code = string.format( "N{{_N%s|%s_%s=%s_%s}}N",
                                      start,
                                      space,
                                      spaced,
                                      spacer,
                                      suffix )
                if show == "block" then
                    show = "block newlines"
                end
             end
            if show then
                 r = mw.html.create( "span" )
                          :wikitext( show )
             end
             end
        else
            permit = Permit.root
         end
         end
         if code then
         for k, v in pairs( parent ) do
            source = code:gsub( "N", "\n" )
            scope = permit[ k ]
            code  = mw.text.nowiki( code ):gsub( "N", "&#92;n" )
            if scope then
            code  = mw.html.create( "code" )
                s = type( v )
                             :css( "margin-left",  "1em" )
                if s == "string" and  k ~= "format" then
                             :css( "margin-right", "1em" )
                    v = mw.text.trim( v )
                             :wikitext( code )
                end
            if r then
                if scope:find( s, 1, true ) then
                r = mw.html.create( "span" )
                    if scope:find( "I18N", 1, true ) then
                          :node( r )
                        if s == "string" then
                          :node( code )
                             elem = fair( v )
            else
                        elseif s == "table" then
                r = code
                             local translated
            end
                             v, translated = faraway( v )
        end
                            if v then
    end
                                if translated  and
    if source then
                                  k == "description" then
        Data.tag.format  = source
                                    elem = { [ 1 ] = fair( v ),
    end
                                            [ 2 ] = translated }
    return r
                                else
end -- format()
                                    elem = fair( v )
 
                                end
 
                            else
 
                                elem = false
local function formatter()
                            end
    -- Build presented documentation
                        end
    -- Returns <div>
                        if type( v ) == "string" then
    local r = mw.html.create( "div" )
                            if k == "deprecated" then
    local s = feasible( Data.tree, true )
                                if v == "1" then
    if s then
                                    v = true
        r:node( s )
                                elseif v == "0" then
    end
                                    v = false
    if Data.leading then
                                end
        local toc = mw.html.create( "div" )
                                elem = v
        if Config.suppressTOCnum then
                            elseif scope:find( "nowiki", 1, true ) then
            toc:addClass( Config.suppressTOCnum )
                                elem = mw.text.nowiki( v )
        end
                                elem = elem:gsub( "&#13;\n", "<br>" )
        toc:css( "margin-top", "0.5em" )
                                v    = v:gsub( string.char( 13 ),  "" )
          :wikitext( "__TOC__" )
                            else
        r:newline()
                                v = flat( v )
        :node( toc )
                            end
        :newline()
                        elseif s == "boolean" then
    end
                            if scope:find( "boolean", 1, true ) then
    s = features()
                                elem = v
    if s then
                            else
        if Data.leading then
                                s = "Type <code>boolean</code> bad for "
            r:node( mw.html.create( "h2" )
                                    .. f( k, slot )
                          :wikitext( factory( "doc-params" ) ) )
                                Fault( s )
            :newline()
                            end
        end
                        end
        r:node( s )
                    else
    end
                        if k == "params"  and  not access then
    if Data.tree and Data.tree.format then
                            v    = nil
        local e = format()
                            elem = nil
        if e then
                        elseif k == "format"  and  not access then
            local show = "Format"
                            elem = mw.text.decode( v )
            if Config.supportFormat then
                            v    = nil
                 show = string.format( "[[%s|%s]]",
                        elseif k == "inherits" then
                                      Config.supportFormat, show )
                            elem = v
            end
                            if not Data.heirs then
             r:node( mw.html.create( "p" )
                                Data.heirs = { }
                          :wikitext( show .. ": " )
                            end
                          :node( e ) )
                            Data.heirs[ slot ] = v
        end
                            v                  = nil
    end
                        elseif k == "style" then
    return r
                            elem = v
end -- formatter()
                            v    = nil
 
                        elseif s == "string" then
 
                            v    = mw.text.nowiki( v )
 
                            elem = v
local function free()
                        else
     -- Remove JSON comment lines
                            elem = v
    Data.source:gsub( "([{,\"'])(%s*\n%s*//.*\n%s*)([},\"'])",
                        end
                      "%1%3" )
                    end
end -- free()
                    if type( elem ) ~= "nil" then
                        if not target then
                            if access then
                                if not Data.tree.params then
                                    Data.tree.params = { }
                                end
                                Data.tree.params[ slot ] = { }
                                target = Data.tree.params[ slot ]
                            else
                                Data.tree = { }
                                target    = Data.tree
                            end
                        end
                        target[ k ] = elem
                        elem        = false
                    end
                    if type( v ) ~= "nil" then
                        if not tag then
                            if access then
                                if type( v ) == "string" and
                                  v.sub( 1, 1 ) == "=" then
                                    v = nil
                                else
                                    if not Data.params then
                                        Data.params = { }
                                    end
                                    Data.params[ slot ] = { }
                                    tag = Data.params[ slot ]
                                end
                            else
                                Data.tag = { }
                                tag      = Data.tag
                            end
                        end
                        if type( v ) ~= "nil"  and
                          k ~= "suggestedvalues" then
                            tag[ k ] = v
                        end
                    end
                 else
                    s = string.format( "Type <code>%s</code> bad for %s",
                                      scope,  f( k, slot ) )
                    Fault( s )
                end
             else
                Fault( "Unknown component " .. f( k, slot ) )
            end
        end -- for k, v
        if not access  and Data.got.sets then
            fellows()
        end
     else
        Fault( f() .. " needs to be of <code>object</code> type" )
    end
end -- focus()






local function full()
local function format()
     -- Build survey table from JSON data, append invisible <templatedata>
     -- Build formatted element
     Data.div = mw.html.create( "div" )
    -- Returns <inline>
                      :addClass( "mw-templatedata-doc-wrap" )
     local source = Data.tree.format:lower()
     focus()
     local r, s
     if Data.tag then
     if source == "inline"  or  source == "block" then
        if type( Data.got.params ) == "table" then
        r = mw.html.create( "i" )
            for k, v in pairs( Data.got.params ) do
                  :wikitext( source )
                focus( k )
     else
            end -- for k, v
         local code
            if Data.heirs then
         if source:find( "|", 1, true ) then
                fathers()
             local scan = "^[\n ]*%{%{[\n _]*|[\n _]*=[\n _]*%}%}[\n ]*$"
            end
             if source:match( scan ) then
        end
                code = source:gsub( "\n", "N" )
    end
             else
    Data.div:node( formatter() )
                s = mw.text.nowiki( source ):gsub( "\n", "&#92;n" )
     if not Data.lazy then
                 s = tostring( mw.html.create( "code" )
         Data.slim = flush()
                                    :wikitext( s ) )
         if TemplateData.frame then
                 Fault( "Invalid format " .. s )
            local div  = mw.html.create( "div" )
                source = false
             local tdata = { [ 1 ] = "templatedata",
                            [ 2 ] = Data.slim }
             Data.strip = TemplateData.frame:callParserFunction( "#tag",
                                                                tdata )
             div:wikitext( Data.strip )
            if Config.loudly then
                 Data.div:node( mw.html.create( "hr" ) )
            else
                 div:css( "display", "none" )
             end
             end
             Data.div:node( div )
        else
        end
             local words = mw.text.split( source, "%s+" )
    end
            local show, start, support, unknown
end -- full()
            for i = 1, #words do
 
                s = words[ i ]
 
                if i == 1 then
 
                    start = s
local function furnish( adapt, arglist )
                end
    -- Analyze transclusion
                support = Permit.builder[ s ]
    -- Parameter:
                if support == start  or
    --    adapt    -- table, #invoke parameters
                  support == "*" then
    --    arglist  -- table, template parameters
                    Permit.builder[ s ] = true
    -- Returns string
                elseif s:match( "^[1-9]%d?" ) and
--local spy=""
                      Permit.builder.align then
    local source
                    Permit.builder.align = tonumber( s )
    favorize()
                else
    -- deprecated:
                    if unknown then
    for k, v in pairs( Config.basicCnf ) do
                        unknown = string.format( "%s %s", unknown, s )
        if adapt[ k ]  and  adapt[ k ] ~= "" then
                    else
            Config[ v ] = adapt[ k ]
                        unknown = s
        end
                    end
    end -- for k, v
                end
    Config.loudly = faculty( arglist.debug or adapt.debug )
            end -- i = 1, #words
--if mw.site.server:find( "//de.wikipedia.beta.wmflabs.org", 1, true ) then
            if unknown then
--    Config.loudly  = true
                s = tostring( mw.html.create( "code" )
--end
                                    :css( "white-space", "nowrap" )
    Data.lazy    = faculty( arglist.lazy )  and  not Config.loudly
                                    :wikitext( s ) )
    Data.leading  = faculty( arglist.TOC )
                Fault( "Unknown/misplaced format keyword " .. s )
    if arglist.JSON then
                source = false
        source = arglist.JSON
                start  = false
    elseif arglist[ 1 ] then
            end
        local s    = mw.text.trim( arglist[ 1 ] )
            if start == "inline" then
        local start = s:sub( 1, 1 )
                if Permit.builder.half == true then
        if start == "<" then
                    show = "inline half"
            Data.strip = s
                    code = "{{_ |_=_}}"
        elseif start == "{" then
                elseif Permit.builder.grouped == true then
            source = s
                    show = "inline grouped"
        elseif mw.ustring.sub( s, 1, 8 ) ==
                    code = "{{_ | _=_}}"
              mw.ustring.char( 127, 39, 34, 96, 85, 78, 73, 81 ) then
                elseif Permit.builder.spaced == true then
            Data.strip = s
                    show = "inline spaced"
        end
                    code = "{{_ | _ = _ }}"
    end
                end
    if arglist.lang then
                if Permit.builder.newlines == true then
        Data.slang = arglist.lang:lower()
                    show = show or "inline"
    elseif adapt.lang then
                    code = code or "{{_|_=_}}"
        Data.slang = adapt.lang:lower()
                    show = show .. " newlines"
    end
                    code = string.format( "N%sN", code )
    if not source then
                end
        Data.title = mw.title.getCurrentTitle()
            elseif start == "block" then
        source = find()
                local space  = ""    -- amid "|" and name
        if not source  and
                local spaced = " "    -- preceding "="
          Config.subpage  and  Config.suffix and
                local spacer = " "    -- following "="
          not Data.title.text:match( Config.subpage ) then
                local suffix = "N"    -- closing "}}" on new line
            local s = string.format( Config.suffix,
                show = "block"
                                    Data.title.prefixedText )
                if Permit.builder.indent == true then
            Data.title = mw.title.new( s )
                    start = " "
            if Data.title.exists then
                    show = "block indent"
                source = find()
                else
            end
                    start = ""
        end
                end
--if source and
                if Permit.builder.compressed == true then
--          ( source:find( "|", 1, true ) or
                    spaced = ""
--            source:find( "}}", 1, true ) ) then
                    spacer = ""
--                      -- <ref
                    show  = show .. " compressed"
--spy=string.format( "[[category:%s]]", Config.strange )
                    if Permit.builder.last == true then
--end
                        show = show .. " last"
    end
                    else
    if not Data.lazy and  Config.subpage then
                        suffix = ""
        if not Data.title then
                    end
            Data.title = mw.title.getCurrentTitle()
                else
        end
                    if Permit.builder.lead == true then
        Data.lazy = Data.title.text:match( Config.subpage )
                        show  = show .. " lead"
    end
                        space = " "
    TemplateData.getPlainJSON( source )
                    end
    return finalize( faculty( arglist.source ) )
                    if type( Permit.builder.align ) ~= "string" then
--return spy .. finalize()
                        local n
end -- furnish()
                        s = " align"
 
                        if Permit.builder.align == true then
 
                            n = 0
 
                            if type( Data.got ) == "table" and
TemplateData.failsafe = function ( assert )
                              type( Data.got.params ) == "table" then
    -- Retrieve versioning and check for compliance
                                for k, v in pairs( Data.got.params ) do
    -- Precondition:
                                    if type( v ) == "tableand
    --    assert  -- string, with required version or "wikidata",
                                      not v.deprecated  and
    --                or false
                                      type( k ) == "string" then
    -- Postcondition:
                                        k = mw.ustring.len( k )
    --    Returns  string with appropriate version, or false
                                        if k > n then
    local since = assert
                                            n = k
                                        end
                                    end
                                end -- for k, v
                            end
                        else
                            n = Permit.builder.align
                            if type( n ) == "number" and  n > 1 then
                                s = string.format( "%s %d", s, n )
                            else
                                n = 0    -- How comes?
                            end
                        end
                        if n > 1 then
                            spaced = string.rep( "_",  n - 1 )  ..  " "
                        end
                        show = show .. s
                    elseif Permit.builder.after == true then
                        spaced = ""
                        show  = show .. " after"
                    elseif Permit.builder.dense == true then
                        spaced = ""
                        spacer = ""
                        show  = show .. " dense"
                    end
                    if Permit.builder.last == true then
                        suffix = spacer
                        show  = show .. " last"
                    end
                end
                code = string.format( "N{{_N%s|%s_%s=%s_%s}}N",
                                      start,
                                      space,
                                      spaced,
                                      spacer,
                                      suffix )
                if show == "block" then
                    show = "block newlines"
                end
            end
            if show then
                r = mw.html.create( "span" )
                          :wikitext( show )
            end
        end
        if code then
            source = code:gsub( "N", "\n" )
            code  = mw.text.nowiki( code ):gsub( "N", "&#92;n" )
            code  = mw.html.create( "code" )
                            :css( "margin-left",  "1em" )
                            :css( "margin-right", "1em" )
                            :wikitext( code )
            if r then
                r = mw.html.create( "span" )
                          :node( r )
                          :node( code )
            else
                r = code
            end
        end
    end
    if source and Data.tag then
        Data.tag.format = source
    end
    return r
end -- format()
 
 
 
local function formatter()
    -- Build presented documentation
    -- Returns <div>
    local r = mw.html.create( "div" )
    local x = fashioned( Data.tree, true, r )
    local s
    if x then
        r = x
    end
    if Data.leading then
        local toc = mw.html.create( "div" )
        local shift
        if Config.suppressTOCnum then
            toc:addClass( Config.suppressTOCnum )
            if type( Config.stylesTOCnum ) == "string" then
                local src = Config.stylesTOCnum .. "/styles.css"
                s = TemplateData.frame:extensionTag( "templatestyles",
                                                    nil,
                                                    { src = src } )
                r:newline()
                :node( s )
            end
        end
        toc:css( "margin-top", "0.5em" )
          :wikitext( "__TOC__" )
        if Data.sibling then
            local block = mw.html.create( "div" )
            if TemplateData.ltr then
                shift = "right"
            else
                shift = "left"
            end
            block:css( "float", shift )
                :wikitext( Data.sibling )
            r:newline()
            :node( block )
            :newline()
        end
        r:newline()
        :node( toc )
        :newline()
        if shift then
            r:node( mw.html.create( "div" )
                          :css( "clear", shift ) )
            :newline()
        end
    end
    s = features()
    if s then
        if Data.leading then
            r:node( mw.html.create( "h" .. Config.nested )
                          :wikitext( factory( "doc-params" ) ) )
            :newline()
        end
        r:node( s )
    end
    if Data.shared then
        local global = mw.html.create( "div" )
                              :attr( "id", "templatedata-global" )
        local shift
        if TemplateData.ltr then
            shift = "right"
        else
            shift = "left"
        end
        global:css( "float", shift )
              :wikitext( string.format( "[[%s|%s]]",
                                        Data.shared, "Global" ) )
        r:newline()
        :node( global )
    end
    if Data.tree and Data.tree.format then
        local e = format()
        if e then
            local show = "Format"
            if Config.supportFormat then
                show = string.format( "[[%s|%s]]",
                                      Config.supportFormat, show )
            end
            r:node( mw.html.create( "p" )
                          :wikitext( show .. ": " )
                          :node( e ) )
        end
    end
    return r
end -- formatter()
 
 
 
local function free()
    -- Remove JSON comment lines
    if Data.source:find( "//", 1, true ) then
        Data.source:gsub( "([{,\"'])(%s*\n%s*//.*\n%s*)([{},\"'])",
                          "%1%3" )
    end
end -- free()
 
 
 
local function full()
    -- Build survey table from JSON data, append invisible <templatedata>
    Data.div = mw.html.create( "div" )
                      :addClass( "mw-templatedata-doc-wrap" )
    focus()
    if Data.tag then
        if type( Data.got.params ) == "table" then
            for k, v in pairs( Data.got.params ) do
                focus( k )
            end -- for k, v
            if Data.heirs then
                fathers()
            end
        end
    end
    Data.div:node( formatter() )
    if not Data.lazy then
        Data.slim = flush()
        if TemplateData.frame then
            local div  = mw.html.create( "div" )
            local tdata = { [ 1 ] = "templatedata",
                            [ 2 ] = Data.slim }
            Data.strip = TemplateData.frame:callParserFunction( "#tag",
                                                                tdata )
            div:wikitext( Data.strip )
            if Config.loudly then
                Data.div:node( mw.html.create( "hr" )
                                      :css( { height = "7ex" } ) )
            else
                div:css( "display", "none" )
            end
            Data.div:node( div )
        end
    end
    if Data.lasting then
        Fault( "deprecated type syntax" )
    end
    if Data.less then
        Fault( Config.solo )
    end
end -- full()
 
 
 
local function furnish( adapt, arglist )
    -- Analyze transclusion
    -- Parameter:
    --    adapt    -- table, #invoke parameters
    --    arglist  -- table, template parameters
    -- Returns string
    local source
    favorize()
    -- deprecated:
    for k, v in pairs( Config.basicCnf ) do
        if adapt[ k ]  and  adapt[ k ] ~= "" then
            Config[ v ] = adapt[ k ]
        end
    end -- for k, v
    if arglist.heading  and  arglist.heading:match( "^[3-6]$" ) then
        Config.nested = arglist.heading
    else
        Config.nested = "2"
    end
    Config.loudly = faculty( arglist.debug or adapt.debug )
    Data.lazy    = faculty( arglist.lazy )  and  not Config.loudly
    Data.leading  = faculty( arglist.TOC )
    if Data.leading and arglist.TOCsibling then
        Data.sibling = mw.text.trim( arglist.TOCsibling )
    end
    if arglist.lang then
        Data.slang = arglist.lang:lower()
    elseif adapt.lang then
        Data.slang = adapt.lang:lower()
    end
    if arglist.JSON then
        source = arglist.JSON
    elseif arglist.Global then
        source = TemplateData.getGlobalJSON( arglist.Global,
                                            arglist.Local )
    elseif arglist[ 1 ] then
        local s    = mw.text.trim( arglist[ 1 ] )
        local start = s:sub( 1, 1 )
        if start == "<" then
            Data.strip = s
        elseif start == "{" then
            source = s
        elseif mw.ustring.sub( s, 1, 8 ) ==
              mw.ustring.char( 127, 39, 34, 96, 85, 78, 73, 81 ) then
            Data.strip = s
        end
    end
    if type( arglist.vertical ) == "string"  and
      arglist.vertical:match( "^%d*%.?%d+[emprx]+$" ) then
        Data.scroll = arglist.vertical
    end
    if not source then
        Data.title = mw.title.getCurrentTitle()
        source = find()
        if not source  and
          not Data.title.text:match( Config.subpage ) then
            local s = string.format( Config.suffix,
                                    Data.title.prefixedText )
            Data.title = mw.title.new( s )
            if Data.title.exists then
                source = find()
            end
        end
    end
    if not Data.lazy then
        if not Data.title then
            Data.title = mw.title.getCurrentTitle()
        end
        Data.lazy = Data.title.text:match( Config.subpage )
    end
    if type( source ) == "string" then
        TemplateData.getPlainJSON( source )
    end
    return finalize( faculty( arglist.source ) )
end -- furnish()
 
 
 
Failsafe.failsafe = function ( atleast )
    -- Retrieve versioning and check for compliance
    -- Precondition:
    --    atleast  -- string, with required version
    --                        or wikidata|item|~|@ or false
    -- Postcondition:
    --    Returns  string  -- with queried version/item, also if problem
    --              false  -- if appropriate
    -- 2020-08-17
    local since  = atleast
    local last  = ( since == "~" )
    local linked = ( since == "@" )
    local link  = ( since == "item" )
     local r
     local r
     if since == "wikidata" then
     if last  or  link  or  linked  or  since == "wikidata" then
         local item = TemplateData.item
         local item = Failsafe.item
         since = false
         since = false
         if type( item ) == "number"  and  item > 0 then
         if type( item ) == "number"  and  item > 0 then
             local entity = mw.wikibase.getEntity( string.format( "Q%d",
             local suited = string.format( "Q%d", item )
                                                                item ) )
            if link then
            if type( entity ) == "table" then
                r = suited
                local vsn = entity:formatPropertyValues( "P348" )
            else
                if type( vsn ) == "table"  and
                local entity = mw.wikibase.getEntity( suited )
                  type( vsn.value) == "string" and
                if type( entity ) == "table" then
                  vsn.value ~= "" then
                    local seek = Failsafe.serialProperty or "P348"
                    r = vsn.value
                    local vsn = entity:formatPropertyValues( seek )
                 end
                    if type( vsn ) == "table"  and
             end
                      type( vsn.value ) == "string" and
         end
                      vsn.value ~= "" then
     end
                        if last  and  vsn.value == Failsafe.serial then
     if not r then
                            r = false
         if not since  or  since <= TemplateData.serial then
                        elseif linked then
             r = TemplateData.serial
                            if mw.title.getCurrentTitle().prefixedText
         else
                              ==  mw.wikibase.getSitelink( suited ) then
             r = false
                                r = false
         end
                            else
     end
                                r = suited
     return r
                            end
end -- TemplateData.failsafe()
                        else
 
                            r = vsn.value
 
                        end
 
                    end
TemplateData.getPlainJSON = function ( adapt )
                 end
     -- Reduce enhanced JSON data to plain text localized JSON
             end
     -- Parameter:
         end
     --    adapt  -- string, with enhanced JSON
     end
     -- Returns string, or not
     if type( r ) == "nil" then
     if type( adapt ) == "string" then
         if not since  or  since <= Failsafe.serial then
         local lucky
             r = Failsafe.serial
         Data.source = adapt
         else
         free()
             r = false
         lucky, Data.got = pcall( mw.text.jsonDecode, Data.source )
        end
         if lucky then
    end
             full()
    return r
             if Data.lasting then
end -- Failsafe.failsafe()
                 Fault( "deprecated type syntax" )
 
 
 
TemplateData.getGlobalJSON = function ( access, adapt )
    -- Retrieve TemplateData from a global repository (JSON)
    -- Parameter:
    --    access  -- string, with page specifier (on WikiMedia Commons)
    --    adapt  -- JSON string or table with local overrides
    -- Returns true, if succeeded
    local plugin = Fetch( "/global" )
    local r
    if type( plugin ) == "table"  and
      type( plugin.fetch ) == "function" then
        local s, got = plugin.fetch( access, adapt )
        if got then
            Data.got    = got
            Data.order  = got.paramOrder
            Data.shared = s
            r          = true
            full()
        else
            Fault( s )
         end
     end
     return r
end -- TemplateData.getGlobalJSON()
 
 
 
TemplateData.getPlainJSON = function ( adapt )
     -- Reduce enhanced JSON data to plain text localized JSON
     -- Parameter:
     --    adapt  -- string, with enhanced JSON
     -- Returns string, or not
     if type( adapt ) == "string" then
         local JSONutil = Fetch( "JSONutil", true )
         Data.source = adapt
         free()
         if JSONutil then
            local Multilingual = Fetch( "Multilingual", true )
            local f
            if Multilingual then
                f = Multilingual.i18n
            end
            Data.got = JSONutil.fetch( Data.source, true, f )
        else
            local lucky
            lucky, Data.got = pcall( mw.text.jsonDecode, Data.source )
        end
         if type( Data.got ) == "table" then
             full()
        elseif not Data.strip then
            local scream = type( Data.got )
             if scream == "string" then
                scream = Data.got
            else
                 scream = "Data.got: " .. scream
             end
             end
            if Data.less then
             Fault( "fatal JSON error: " .. scream )
                Fault( Config.solo )
            end
        elseif not Data.strip then
             Fault( "fatal JSON error: " .. Data.got )
         end
         end
     end
     end
Zeile 1.545: Zeile 2.242:
     end
     end
     return r
     return r
end -- p.f()
end -- p.f


p.failsafe = function ( frame )
p.failsafe = function ( frame )
Zeile 1.562: Zeile 2.259:
         end
         end
     end
     end
     return TemplateData.failsafe( since )  or  ""
     return Failsafe.failsafe( since )  or  ""
end -- p.failsafe()
end -- p.failsafe


p.TemplateData = function ()
p.TemplateData = function ()