Modul:TemplateData: Unterschied zwischen den Versionen

K
73 Versionen von wikivoyage:Modul:TemplateData importiert
(2023-01-07)
K (73 Versionen von wikivoyage:Modul:TemplateData importiert)
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
local TemplateData = { suite  = "TemplateData",
local TemplateData = { suite  = "TemplateData",
                       serial = "2023-01-07",
                       serial = "2021-07-05",
                       item  = 46997995 }
                       item  = 46997995 }
--[==[
--[==[
Zeile 11: Zeile 11:
local Config = {
local Config = {
     -- multiple option names mapped into unique internal fields
     -- multiple option names mapped into unique internal fields
     basicCnf = { catProblem         = "strange",
     basicCnf = { catProblem   = "strange",
                classMultiColumns  = "selMultClm",
                 classNoNumTOC = "suppressTOCnum",
                 classNoNumTOC       = "suppressTOCnum",
                 classTable   = "classTable",
                 classTable         = "classTable",
                 cssParWrap   = "cssTabWrap",
                 cssParWrap         = "cssTabWrap",
                 cssParams     = "cssTable",
                 cssParams           = "cssTable",
                 docpageCreate = "suffix",
                 docpageCreate       = "suffix",
                 docpageDetect = "subpage",
                 docpageDetect       = "subpage",
                 helpBoolean   = "support4boolean",
                helpAliases        = "supportAliases",
                 helpContent   = "support4content",
                 helpBoolean         = "support4boolean",
                 helpDate     = "support4date",
                 helpContent         = "support4content",
                 helpFile     = "support4wiki-file-name",
                 helpDate           = "support4date",
                 helpFormat   = "supportFormat",
                 helpFile           = "support4wiki-file-name",
                 helpLine     = "support4line",
                 helpFormat         = "supportFormat",
                 helpNumber   = "support4number",
                 helpLine           = "support4line",
                 helpPage     = "support4wiki-page-name",
                 helpNumber         = "support4number",
                 helpString   = "support4string",
                 helpPage           = "support4wiki-page-name",
                 helpTemplate = "support4wiki-template-name",
                 helpString         = "support4string",
                 helpURL       = "support4url",
                 helpTemplate       = "support4wiki-template-name",
                 helpUser     = "support4wiki-user-name",
                 helpURL             = "support4url",
                 msgDescMiss   = "solo",
                 helpUser           = "support4wiki-user-name",
                 tStylesTOCnum = "stylesTOCnum" },
                 msgDescMiss         = "solo",
                tStylesMultiColumns = "stylesMultClm",
                 tStylesTOCnum       = "stylesTOCnum" },
     classTable    = { "wikitable" },    -- classes for params table
     classTable    = { "wikitable" },    -- classes for params table
     debugmultilang = "C0C0C0",
     debugmultilang = "C0C0C0",
Zeile 71: 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   = "*",
                 newlines       = "*",
                 spaced     = "inline" },
                 spaced         = "inline" },
     colors  = { bg          = "FFFFFF",
     colors  = { tableheadbg = "B3B7FF",
                fg          = "000000",
                tableheadbg = "B3B7FF",
                 required    = "EAF3FF",
                 required    = "EAF3FF",
                 suggested  = "FFFFFF",
                 suggested  = "FFFFFF",
Zeile 102: Zeile 97:
                 style          = "string table",
                 style          = "string table",
                 suggested      = "boolean",
                 suggested      = "boolean",
                 suggestedvalues = "string table number boolean",
                 suggestedvalues = "string table number",
                 type            = "string" },
                 type            = "string" },
     root    = { description = "string table I18N",
     root    = { description = "string table I18N",
Zeile 244: Zeile 239:
     return r
     return r
end -- facet()
end -- facet()
local function facilities( apply )
    -- Retrieve details of suggestedvalues
    -- Parameter:
    --    apply  -- table, with plain or enhanced values
    --              .suggestedvalues  -- table|string|number, or more
    -- Returns
    --    1  -- table, with suggestedvalues
    --    2  -- table, with CSS map, or not
    --    3  -- string, with class, or not
    --    4  -- string, with templatestyles, or not
    local elements = apply.suggestedvalues
    local s        = type( elements )
    local r1, r2, r3, r4
    if s == "table" then
        local values = elements.values
        if type( values ) == "table" then
            r1 = values
            if type( elements.scroll ) == "string" then
                r2 = r2  or  { }
                r2.height  = apply.scroll
                r2.overflow = "auto"
            end
            if type( elements.minwidth ) == "string" then
                local s = type( elements.maxcolumns )
                r2 = r2  or  { }
                r2["column-width"] = elements.minwidth
                if s == "string"  or
                  s == "number" then
                    s = tostring( elements.maxcolumns )
                    r2["column-count"] = s
                end
                if type( Config.selMultClm ) == "string" then
                    r3 = Config.selMultClm
                end
mw.log("facilities()",Config.stylesMultClm)
                if type( Config.stylesMultClm ) == "string" then
                    local src = Config.stylesMultClm .. "/styles.css"
                    r4 = TemplateData.frame
                                    :extensionTag( "templatestyles",
                                                    nil,
                                                    { src = src } )
mw.log(r4)
                end
            end
        elseif elements  and  elements ~= "" then
            r1 = elements
        end
    elseif s == "string" then
        s = mw.text.trim( about )
        if s ~= "" then
            r1 = { }
            table.insert( r1,
                          { code = s } )
        end
    elseif s == "number" then
        r1 = { }
        table.insert( r1,
                      { code = tostring( elements ) } )
    end
    return r1, r2, r3, r4
end -- facilities()




Zeile 678: Zeile 609:
     local l, cx = pcall( mw.loadData,
     local l, cx = pcall( mw.loadData,
                         TemplateData.frame:getTitle() .. "/config" )
                         TemplateData.frame:getTitle() .. "/config" )
     local scripting, style
     local scripting
     TemplateData.ltr = not mw.language.getContentLanguage():isRTL()
     TemplateData.ltr = not mw.language.getContentLanguage():isRTL()
     if TemplateData.ltr then
     if TemplateData.ltr then
Zeile 697: Zeile 628:
             k = "tablehead"
             k = "tablehead"
         end
         end
        if k == "fg" then
         Permit.css[ k ] = { ["background-color"] = "#" .. v }
            style = "color"
        else
            style = "background-color"
        end
         Permit.css[ k ] = { }
        Permit.css[ k ][ style ] = "#" .. v
     end -- for k, v
     end -- for k, v
     if type( cx ) == "table" then
     if type( cx ) == "table" then
Zeile 726: Zeile 651:
         for k, v in pairs( Config.basicCnf ) do
         for k, v in pairs( Config.basicCnf ) do
             s = type( cx[ k ] )
             s = type( cx[ k ] )
mw.log(k, v,s )
             if s == "string"  or  s == "table" then
             if s == "string"  or  s == "table" then
                 Config[ v ] = cx[ k ]
                 Config[ v ] = cx[ k ]
Zeile 752: Zeile 676:




local function feasible( all, at, about )
local function feasible( about, at )
     -- Deal with suggestedvalues within parameter
     -- Deal with suggestedvalues within parameter
     -- Parameter:
     -- Parameter:
     --    all    -- parameter details
     --    about  -- parameter details
     --              .default
     --              .suggestedvalues  -- table|string|number,
    --                                    value and possibly description
    --                                    .code  -- mandatory
    --                                    .label  -- table|string
    --                                    .icon  -- string
    --                                    .class  -- table|string
    --                                    .css    -- table
    --                                    .style  -- string
    --                                    .less  -- true: suppress code
     --              .type
     --              .type
     --    at    -- string, with parameter name
     --    at    -- string, with parameter name
    --    about  -- suggestedvalues  -- table,
    --                                  value and possibly description
    --                                  table may have elements:
    --                                    .code    -- mandatory
    --                                    .label  -- table|string
    --                                    .support -- table|string
    --                                    .icon    -- string
    --                                    .class  -- table|string
    --                                    .css    -- table
    --                                    .style  -- string
    --                                    .less    -- true: suppress code
     -- Returns
     -- Returns
     --    1: mw.html object <ul>
     --    1: mw.html object
     --    2: sequence table with values, or nil
     --    2: sequence table with values, or nil
     local h = { }
     local p = about.suggestedvalues
     local e, r1, r2, s, v
    local s = type( p )
     if #about > 0 then
     local e, r1, r2, v
        for i = 1, #about do
     if s == "table" then
            e = about[ i ]
        if #p > 0 then
            s = type( e )
            for i = 1, #p do
            if s == "table" then
                e = p[ i ]
                if type( e.code ) == "string" then
                s = type( e )
                    s = mw.text.trim( e.code )
                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
                     if s == "" then
                         e = nil
                         e = nil
                        s = string.format( "params.%s.%s[%d] EMPTY",
                                          at, "suggestedvalues", i )
                        Fault( s )
                     else
                     else
                         e.code = s
                         e = { code = s }
                     end
                     end
                elseif s == "number" then
                    e = { code = tostring( e ) }
                 else
                 else
                    e = nil
                     s = string.format( "params.%s.%s[%d] INVALID",
                    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 )
                                       at, "suggestedvalues", i )
                     Fault( s )
                     Fault( s )
                else
                     e = false
                     e = { code = s }
                 end
                 end
            elseif s == "number" then
                 if e then
                e = { code = tostring( e ) }
                    v = v  or  { }
            else
                    table.insert( v, e )
                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 )
                if h[ e.code ] then
                    s = string.format( "params.%s.%s REPEATED %s",
                                      at,
                                      "suggestedvalues",
                                      e.code )
                    Fault( s )
                else
                    h[ e.code ] = true
                 end
                 end
             end
             end -- for i
        end -- for i
        else
    else
            Fault( string.format( "params.%s.suggestedvalues %s",
        Fault( string.format( "params.%s.suggestedvalues %s",
                  at, "NOT AN ARRAY" ) )
                              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
     end
     if v then
     if v then
         local code, d, k, less, story, swift, t, u
         local d, less, story, swift, t, u
         r1 = mw.html.create( "ul" )
         r1 = mw.html.create( "ul" )
         r2 = { }
         r2 = { }
Zeile 875: Zeile 801:
                     end
                     end
                 end
                 end
                 if all.type:sub( 1, 5 ) == "wiki-"  and
                 if about.type:sub( 1, 5 ) == "wiki-"  and
                   swift == e.code then
                   swift == e.code then
                     local rooms = { file = 6,
                     local rooms = { file = 6,
                                     temp = 10,
                                     temp = 10,
                                     user = 2 }
                                     user = 2 }
                     local ns = rooms[ all.type:sub( 6, 9 ) ]  or  0
                     local ns = rooms[ about.type:sub( 6, 9 ) ]  or  0
                     t = mw.title.makeTitle( ns, swift )
                     t = mw.title.makeTitle( ns, swift )
                     if t and t.exists then
                     if t and t.exists then
Zeile 887: Zeile 813:
                     end
                     end
                 end
                 end
                 if e.code == all.default then
                 u:node( mw.html.create( "code" )
                    k = 800
                              :css( "white-space", "nowrap" )
                else
                              :wikitext( swift ) )
                    k = 300
                end
                code = mw.html.create( "code" )
                              :css( "font-weight", tostring( k ) )
                              :css( "white-space", "nowrap" )
                              :wikitext( swift )
                u:node( code )
             end
             end
             if e.class then
             if e.class then
Zeile 930: Zeile 849:
                 end
                 end
             end
             end
             if all.type == "wiki-file-name"  and  not e.icon then
             if about.type == "wiki-file-name"  and  not e.icon then
                 e.icon = e.code
                 e.icon = e.code
             end
             end
Zeile 996: Zeile 915:
         end -- for i
         end -- for i
     end
     end
     if not r1 and  v ~= false then
     if not r1 then
         Fault( string.format( "params.%s.suggestedvalues INVALID", at ) )
         Fault( string.format( "params.%s.suggestedvalues INVALID", at ) )
         r1 = mw.html.create( "code" )
         r1 = mw.html.create( "code" )
Zeile 1.141: Zeile 1.060:
                         :wikitext( s )
                         :wikitext( s )
                 else
                 else
                    if Config.supportAliases then
                        s = string.format( "[[%s|%s]]",
                                          Config.supportAliases,
                                          mw.text.nowiki( s ) )
                    end
                     syn = mw.html.create( "span" )
                     syn = mw.html.create( "span" )
                                 :addClass( styles .. "alias" )
                                 :addClass( styles .. "alias" )
Zeile 1.221: Zeile 1.135:
                     end
                     end
                 elseif s == "suggestedvalues" then
                 elseif s == "suggestedvalues" then
                     local v, css, class, ts = facilities( param )
                     local html, values = feasible( param, access )
                    if v then
                    dd:newline()
                        local ul
                      :node( html )
                        ul, v = feasible( param, access, v )
                    Data.params[ access ].suggestedvalues = values
                        if v then
                            dd:newline()
                              :node( ul )
                            if css then
                                dd:css( css )
                                if class then
                                    dd:addClass( class )
                                end
                                if ts then
                                    dd:newline()
                                    dd:node( ts )
                                end
                            end
                            Data.params[ access ].suggestedvalues = v
                        end
                    end
                 else
                 else
                     dd:wikitext( show )
                     dd:wikitext( show )
Zeile 1.298: Zeile 1.196:
         end
         end
     end
     end
    typed:addClass( "navigation-not-searchable" )
     -- status
     -- status
     if param.required then
     if param.required then
Zeile 1.343: Zeile 1.240:
     eager:attr( "data-sort-value", tostring( mode ) )
     eager:attr( "data-sort-value", tostring( mode ) )
                 :node( ranking )
                 :node( ranking )
                 :addClass( string.format( "%sstatus-%s %s",
                 :addClass( string.format( "%sstatus-%s",
                                           styles, status,
                                           styles, status ) )
                                          "navigation-not-searchable" ) )


     -- <tr>
     -- <tr>
Zeile 1.384: Zeile 1.280:
             tbl:css( Config.cssTable )
             tbl:css( Config.cssTable )
         end
         end
         tr:addClass( "navigation-not-searchable" )
         tr:node( mw.html.create( "th" )
          :node( mw.html.create( "th" )
                         :attr( "colspan", "2" )
                         :attr( "colspan", "2" )
                         :css( Permit.css.tablehead )
                         :css( Permit.css.tablehead )
Zeile 1.592: Zeile 1.487:
         if r:find( "<", 1, true ) then
         if r:find( "<", 1, true ) then
             local Text = Fetch( "Text" )
             local Text = Fetch( "Text" )
             r = r:gsub( "<br */?>", "\r\n" )
             r = Text.getPlain( r:gsub( "<br */?>", "\r\n" ) )
                :gsub( "<sup>2</sup>", "&sup2;" )
                :gsub( "<sup>3</sup>", "&sup3;" )
            r = Text.getPlain( r )
         end
         end
         if r:find( "[", 1, true ) then
         if r:find( "[", 1, true ) then
Zeile 2.011: Zeile 1.903:
             end
             end
         end
         end
         toc:addClass( "navigation-not-searchable" )
         toc:css( "margin-top", "0.5em" )
          :css( "margin-top", "0.5em" )
           :wikitext( "__TOC__" )
           :wikitext( "__TOC__" )
         if Data.sibling then
         if Data.sibling then
Zeile 2.069: Zeile 1.960:
             end
             end
             r:node( mw.html.create( "p" )
             r:node( mw.html.create( "p" )
                          :addClass( "navigation-not-searchable" )
                           :wikitext( show .. ": " )
                           :wikitext( show .. ": " )
                           :node( e ) )
                           :node( e ) )
Zeile 2.093: Zeile 1.983:
     Data.div = mw.html.create( "div" )
     Data.div = mw.html.create( "div" )
                       :addClass( "mw-templatedata-doc-wrap" )
                       :addClass( "mw-templatedata-doc-wrap" )
    if Permit.css.bg then
        Data.div:css( Permit.css.bg )
    end
    if Permit.css.fg then
        Data.div:css( Permit.css.fg )
    end
     focus()
     focus()
     if Data.tag then
     if Data.tag then
Zeile 2.382: Zeile 2.266:
     return TemplateData
     return TemplateData
end
end
setmetatable( p,  { __call = function ( func, ... )
                                setmetatable( p, nil )
                                return Failsafe
                            end } )


return p
return p