Bearbeiten von „Modul:TemplatePar

Zur Navigation springen Zur Suche springen
Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden. Ein eigenes Benutzerkonto hat eine ganze Reihe von Vorteilen.

Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.

Aktuelle Version Dein Text
Zeile 1: Zeile 1:
local TemplatePar = { serial = "2018-08-10",
--[=[ TemplatePar 2014-12-22
                      suite  = "TemplatePar",
                      item  = 15393417,
                      extern = { },
                      frame  = false }
--[=[
Template parameter utility
Template parameter utility
* assert
* assert
Zeile 11: Zeile 6:
* countNotEmpty
* countNotEmpty
* downcase()
* downcase()
* duplicates
* match
* match
* valid
* valid
* verify()
* verify()
* TemplatePar()
* TemplatePar()
* failsafe()
]=]
]=]


Zeile 22: Zeile 15:


-- Module globals
-- Module globals
local TemplatePar = { }
local MessagePrefix = "lua-module-TemplatePar-"
local MessagePrefix = "lua-module-TemplatePar-"
local L10nDef = {}
local L10nDef = {}
Zeile 34: Zeile 28:
     missing    = "#invoke:TemplatePar missing library",
     missing    = "#invoke:TemplatePar missing library",
     multiSpell  = "Error in template * multiple spelling of parameter",
     multiSpell  = "Error in template * multiple spelling of parameter",
     noMSGnoCAT = "#invoke:TemplatePar neither message nor category",
     noErrorCat = "#invoke:TemplatePar noError and missing category",
     noname      = "#invoke:TemplatePar missing parameter name",
     noname      = "#invoke:TemplatePar missing parameter name",
     notFound    = "Error in template * missing page",
     notFound    = "Error in template * missing page",
Zeile 42: Zeile 36:
     unknown    = "Error in template * unknown parameter name",
     unknown    = "Error in template * unknown parameter name",
     unknownRule = "#invoke:TemplatePar unknown rule"
     unknownRule = "#invoke:TemplatePar unknown rule"
}
L10nDef.de  = {
    badPattern  = "#invoke:TemplatePar Syntaxfehler des pattern",
    dupOpt      = "#invoke:TemplatePar Optionsparameter wiederholt",
    dupRule    = "#invoke:TemplatePar Konflikt key/pattern",
    empty      = "Fehler bei Vorlage * Pflichtparameter ohne Wert",
    invalid    = "Fehler bei Vorlage * Parameter ungültig",
    invalidPar  = "#invoke:TemplatePar Ungültiger Parameter",
    minmax      = "#invoke:TemplatePar min > max",
    multiSpell  = "Fehler bei Vorlage * Mehrere Parameter-Schreibweisen",
    noErrorCat  = "#invoke:TemplatePar noError und keine Kategorie",
    noname      = "#invoke:TemplatePar Parameter nicht angegeben",
    notFound    = "Fehler bei Vorlage * Seite fehlt",
    tooLong    = "Fehler bei Vorlage * Parameter zu lang",
    tooShort    = "Fehler bei Vorlage * Parameter zu kurz",
    undefined  = "Fehler bei Vorlage * Pflichtparameter fehlt",
    unknown    = "Fehler bei Vorlage * Parametername unbekannt",
    unknownRule = "#invoke:TemplatePar Unbekannte Regel"
}
}
local Patterns = {
local Patterns = {
Zeile 78: Zeile 90:
     [ "pagename" ] = string.format( "^[^#<>%%[%%]|{}%c-%c%c]+$",
     [ "pagename" ] = string.format( "^[^#<>%%[%%]|{}%c-%c%c]+$",
                                     1, 31, 127 ),
                                     1, 31, 127 ),
    [ "ref" ]      = string.format( "%c'%c`UNIQ%s%sref%s%s%sQINU`%c'%c",
                                    127, 34, "%-", "%-", "%-", "%x+",
                                    "%-", 34, 127 ),
     [ "+" ]        = "%S"
     [ "+" ]        = "%S"
}
}
Zeile 128: Zeile 137:
     --    Return error keyword, or false
     --    Return error keyword, or false
     -- Uses:
     -- Uses:
    --    >< TemplatePar.extern.FileMedia
     --    Module:FileMedia
     --    Module:FileMedia
     --    FileMedia.isType()
     --    FileMedia.isType()
     local r
     local r
     if attempt and attempt ~= "" then
     if attempt and attempt ~= "" then
         local FileMedia
         local lucky, FileMedia = pcall( require, "Module:FileMedia" )
        if TemplatePar.extern.FileMedia then
            FileMedia = TemplatePar.extern.FileMedia
        else
            local lucky
            lucky, FileMedia = pcall( require, "Module:FileMedia" )
            if type( FileMedia ) == "table" then
                FileMedia                    = FileMedia.FileMedia()
                TemplatePar.extern.FileMedia = FileMedia
            end
        end
         if type( FileMedia ) == "table" then
         if type( FileMedia ) == "table" then
            FileMedia = FileMedia.FileMedia()
             local s, live = accept:match( "^([a-z]+)(:?)%+?$" )
             local s, live = accept:match( "^([a-z]+)(:?)%+?$" )
             if live then
             if live then
Zeile 191: Zeile 190:
         local l10n = L10nDef[ c ]
         local l10n = L10nDef[ c ]
         if not l10n then
         if not l10n then
             local lucky
             l10n = L10nDef[ "en" ]
            lucky, l10n = pcall( mw.loadData,
                                string.format( "Module:%s/%s",
                                                TemplatePar.suite, c ) )
            if type( l10n ) == "table" then
                L10nDef[ c ] = l10n
            end
        end
        if type( l10n ) ~= "table" then
            l10n = L10nDef.en
         end
         end
         r = l10n[ say ]
         r = l10n[ say ]
        if not r then
            r = L10nDef.en[ say ]
        end
     else
     else
         m:inLanguage( c )
         m:inLanguage( c )
Zeile 211: Zeile 198:
     end
     end
     if not r then
     if not r then
         r = string.format( "(((%s)))", say )
         r = "(((".. say .. ")))"
     end
     end
     return r
     return r
end -- factory()
end -- factory()
local function failsafe( story, scan )
    -- Test for match (possibly user-defined with syntax error)
    -- Precondition:
    --    story  -- string; parameter value
    --    scan  -- string; pattern
    -- Postcondition:
    --    Return nil, if not matching, else non-nil
    -- Uses:
    --    mw.ustring.match()
    return  mw.ustring.match( story, scan )
end -- failsafe()




Zeile 233: Zeile 234:
         if type( options.template ) == "string" then
         if type( options.template ) == "string" then
             if #options.template > 0 then
             if #options.template > 0 then
                 r = string.format( "%s (%s)", r, options.template )
                 r = r .. " (" .. options.template .. ")"
             end
             end
         end
         end
     end
     end
     if suspect then
     if suspect then
         r = string.format( "%s: %s", r, suspect )
         r = r .. ": " .. suspect
     end
     end
     return r
     return r
end -- failure()
end -- failure()
local function fair( story, scan )
    -- Test for match (possibly user-defined with syntax error)
    -- Precondition:
    --    story  -- string; parameter value
    --    scan  -- string; pattern
    -- Postcondition:
    --    Return nil, if not matching, else non-nil
    -- Uses:
    --    mw.ustring.match()
    return  mw.ustring.match( story, scan )
end -- fair()
local function familiar( accept, attempt )
    -- Check string as possible language name or list
    -- Precondition:
    --    accept  -- string; requirement
    --                        lang
    --                        langs
    --                        langW
    --                        langsW
    --                        lang+
    --                        langs+
    --                        langW+
    --                        langsW+
    --    attempt  -- string; to be tested
    -- Postcondition:
    --    Return error keyword, or false
    -- Uses:
    --    >< TemplatePar.extern.Multilingual
    --    Module:Multilingual
    --    Multilingual.isType()
    local r
    if attempt and attempt ~= "" then
        local Multilingual
        if TemplatePar.extern.Multilingual then
            Multilingual = TemplatePar.extern.Multilingual
        else
            local lucky
            lucky, Multilingual = pcall( require, "Module:Multilingual" )
            if type( Multilingual ) == "table" then
                Multilingual = Multilingual.Multilingual()
                TemplatePar.extern.Multilingual = Multilingual
            end
        end
        if type( Multilingual ) == "table" then
            local lazy = accept:find( "W", 1, true )
            if accept:find( "s", 1, true ) then
                local group = mw.text.split( attempt, "%s+" )
                r = false
                for i = 1, #group do
                    if not Multilingual.isLang( group[ i ], lazy ) then
                        r = "invalid"
                        break -- for i
                    end
                end -- for i
            elseif Multilingual.isLang( attempt, lazy ) then
                r = false
            else
                r = "invalid"
            end
        else
            r = "missing"
        end
    elseif accept:find( "+", 1, true ) then
        r = "empty"
    else
        r = false
    end
    return r
end -- familiar()
local function far( accept, attempt )
    -- Check string as possible URL
    -- Precondition:
    --    accept  -- string; requirement
    --                        url
    --                        url+
    --    attempt  -- string; to be tested
    -- Postcondition:
    --    Return error keyword, or false
    -- Uses:
    --    >< TemplatePar.extern.Multilingual
    --    Module:Multilingual
    --    Multilingual.isType()
    local r
    if attempt and attempt ~= "" then
        local URLutil
        if TemplatePar.extern.URLutil then
            URLutil = TemplatePar.extern.URLutil
        else
            local lucky
            lucky, URLutil = pcall( require, "Module:URLutil" )
            if type( URLutil ) == "table" then
                URLutil                    = URLutil.URLutil()
                TemplatePar.extern.URLutil = URLutil
            end
        end
        if type( URLutil ) == "table" then
            if URLutil.isWebURL( attempt ) then
                r = false
            else
                r = "invalid"
            end
        else
            r = "missing"
        end
    elseif accept:find( "+", 1, true ) then
        r = "empty"
    else
        r = false
    end
    return r
end -- far()




Zeile 380: Zeile 261:
     end
     end
     if store then
     if store then
         r = string.format( "%s; %s", store, s )
         r = store .. "; " .. s
     else
     else
         r = s
         r = s
Zeile 406: Zeile 287:
     --    mw.text.trim()
     --    mw.text.trim()
     --    facility()
     --    facility()
     --    fair()
     --    failsafe()
     --    containsCJK()
     --    containsCJK()
     local r    = false
     local r    = false
Zeile 429: Zeile 310:
         if type( scan ) == "string" then
         if type( scan ) == "string" then
             if s == "n" or s == "0,0" or s == "0.0" then
             if s == "n" or s == "0,0" or s == "0.0" then
                 if not analyze:match( "[0-9]" )  and
                 if not analyze:match( "[0-9]" ) then
                  not analyze:match( "^%s*$" ) then
                     scan = false
                     scan = false
                     if options.say then
                     if options.say then
                         show = string.format( "'%s'", options.say )
                         show = "'" .. options.say .. "'"
                     end
                     end
                     if abbr then
                     if abbr then
Zeile 475: Zeile 355:
                 r = facility( s, analyze )
                 r = facility( s, analyze )
                 n = true
                 n = true
             elseif s:match( "langs?W?%+?" ) then
             elseif s:match( "langW?%+?" ) then
                r = familiar( s, analyze )
                 n = "lang"
                 n = true
-- lang lang+
            elseif s:match( "url%+?" ) then
-- langW langW+
                r = far( s, analyze )
                n = true
             end
             end
-- datetime+
-- iso8631+
-- line+
             if not n and not r then
             if not n and not r then
                 r = "unknownRule"
                 r = "unknownRule"
Zeile 490: Zeile 365:
             if r then
             if r then
                 if options.say then
                 if options.say then
                     show = string.format( "'%s' %s", options.say, s )
                     show = "'" .. options.say .. "' " .. s
                 else
                 else
                     show = s
                     show = s
Zeile 503: Zeile 378:
     end
     end
     if scan then
     if scan then
         local legal, got = pcall( fair, analyze, scan )
         local legal, got = pcall( failsafe, analyze, scan )
         if legal then
         if legal then
             if not got then
             if not got then
Zeile 511: Zeile 386:
                 if not got then
                 if not got then
                     if options.say then
                     if options.say then
                         show = string.format( "'%s'", options.say )
                         show = "'" .. options.say .. "'"
                     end
                     end
                     if abbr then
                     if abbr then
Zeile 522: Zeile 397:
         else
         else
             r = failure( "badPattern",
             r = failure( "badPattern",
                         string.format( "%s *** %s", scan, got ),
                         scan .. " *** " .. got,
                         options )
                         options )
         end
         end
Zeile 538: Zeile 413:
     -- Postcondition:
     -- Postcondition:
     --    Return true iff found
     --    Return true iff found
     local k, v, r
     local k, v
     for k, v in pairs( haystack ) do
     for k, v in pairs( haystack ) do
         if k == needle then
         if k == needle then
             r = true
             return true
         end
         end
     end -- for k, v
     end -- for k, v
     return r or false
     return false
end -- fed()
end -- fed()


Zeile 566: Zeile 441:
         g = TemplatePar.downcase( options )
         g = TemplatePar.downcase( options )
     else
     else
         TemplatePar.frame = mw.getCurrentFrame()
         g = mw.getCurrentFrame()
        g                = TemplatePar.frame
         if light then
         if light then
             g = g:getParent()
             g = g:getParent()
Zeile 611: Zeile 485:
         if type( sub ) == "string" then
         if type( sub ) == "string" then
             sub            = sub:gsub( "%%!", "|" )
             sub            = sub:gsub( "%%!", "|" )
                                :gsub( "%%%(%(", "{{" )
            sub            = sub:gsub( "%%%(%(", "{{" )
                                :gsub( "%%%)%)", "}}" )
            sub            = sub:gsub( "%%%)%)", "}}" )
                                :gsub( "\\n", string.char( 10 ) )
             options.pattern = sub
             options.pattern = sub
             options.key    = nil
             options.key    = nil
Zeile 657: Zeile 530:
     --    submit  -- string or false or nil; non-empty error message
     --    submit  -- string or false or nil; non-empty error message
     --    options  -- table or nil; optional details
     --    options  -- table or nil; optional details
    --                options.noError    -- OBSOLETE
     --                options.format
     --                options.format
    --                options.preview
     --                options.cat
     --                options.cat
     --                options.template
     --                options.template
Zeile 666: Zeile 539:
     --    factory()
     --    factory()
     local r = false
     local r = false
    local lapsus    -- OBSOLETE
     if submit then
     if submit then
        local lazy  = false
        local learn = false
        local show  = false
         local opt, s
         local opt, s
        local lazy = false
        local show = false
        lapsus = false    -- OBSOLETE
         if type( options ) == "table" then
         if type( options ) == "table" then
             opt = options
             opt = options
            if opt.noError then    -- OBSOLETE
                lazy  = true
                lapsus = true
            end
             show = opt.format
             show = opt.format
             lazy = ( show == ""  or  show == "0"  or  show == "-" )
             lazy = lazy      or
            s    = opt.preview
                  ( show == ""  or  show == "0"  or  show == "-" )
            if type( s ) == "string"  and
              s ~= ""  and  s ~= "0"  and  s ~= "-" then
                local sniffer = "{{REVISIONID}}"
                if lazy then
                    show = ""
                    lazy = false
                end
                if not TemplatePar.frame then
                    TemplatePar.frame = mw.getCurrentFrame()
                end
                if TemplatePar.frame:preprocess( sniffer ) == "" then
                    if s == "1" then
                        show = "*"
                    else
                        show = s
                    end
                    learn = true
                end
            end
         else
         else
             opt = { }
             opt = { }
Zeile 700: Zeile 559:
         if lazy then
         if lazy then
             if not opt.cat then
             if not opt.cat then
                 r = string.format( "%s %s",
                 r = submit .. " " .. factory( "noErrorCat" ) -- OBSOLETE
                                  submit,  factory( "noMSGnoCAT" ) )
             end
             end
         else
         else
Zeile 707: Zeile 565:
         end
         end
         if r  and  not lazy then
         if r  and  not lazy then
            local i
             if not show  or  show == "*" then
             if not show  or  show == "*" then
                 local e = mw.html.create( "span" )
                 show = "<span class=\"error\">@@@</span>"
                                :attr( "class", "error" )
                                :wikitext( "@@@" )
                if learn then
                    local max  = 1000000000
                    local id  = math.floor( os.clock() * max )
                    local sign = string.format( "error_%d", id )
                    local btn  = mw.html.create( "span" )
                    local top  = mw.html.create( "div" )
                    e:attr( "id", sign )
                    btn:css( { ["background"]      = "#FFFF00",
                              ["border"]          = "#FF0000 3px solid",
                              ["font-weight"]    = "bold",
                              ["padding"]        = "2px",
                              ["text-decoration"] = "none" } )
                      :wikitext( "&gt;&gt;&gt;" )
                    sign = string.format( "[[#%s|%s]]",
                                          sign,  tostring( btn ) )
                    top:wikitext( sign, "&#160;", submit )
                    mw.addWarning( tostring( top ) )
                end
                show = tostring( e )
            end
            i = show:find( "@@@", 1, true )
            if i then
                -- No gsub() since r might contain "%3" (e.g. URL)
                r = string.format( "%s%s%s",
                                  show:sub( 1,  i - 1 ),
                                  r,
                                  show:sub( i + 3 ) )
            else
                r = show
             end
             end
        end
             r = mw.ustring.gsub( show, "@@@", r )
        if learn and r then
             -- r = fatal( r )
         end
         end
         s = opt.cat
         s = opt.cat
         if type( s ) == "string" then
         if type( s ) == "string" then
            local link
             if not r then
             if opt.errNS then
              r = ""
                local ns = mw.title.getCurrentTitle().namespace
            end
                 local st = type( opt.errNS )
            if s:find( "@@@" ) then
                if st == "string" then
                 if type( opt.template ) == "string" then
                     local space  = string.format( ".*%%s%d%%s.*", ns )
                     s = s:gsub( "@@@", opt.template )
                    local spaces = string.format( " %s ", opt.errNS )
                    if spaces:match( space ) then
                        link = true
                    end
                elseif st == "table" then
                    for i = 1, #opt.errNS do
                        if opt.errNS[ i ] == ns then
                            link = true
                            break    -- for i
                        end
                    end -- for i
                 end
                 end
            else
                link = true
             end
             end
             if link then
             local i
                local cats, i
            local cats = mw.text.split( s, "%s*#%s*" )
                 if not r then
            for i = 1, #cats do
                  r = ""
                s = mw.text.trim( cats[ i ] )
                 if #s > 0 then
                    r = string.format( "%s[[Category:%s]]", r, s )
                 end
                 end
                if s:find( "@@@" ) then
            end -- for i
                    if type( opt.template ) == "string" then
        end
                        s = s:gsub( "@@@", opt.template )
    elseif type( options ) == "table" then
                    end
        lapsus = options.noError    -- OBSOLETE
                end
    end
                cats = mw.text.split( s, "%s*#%s*" )
    if lapsus then    -- OBSOLETE
                for i = 1, #cats do
        if not r then
                    s = mw.text.trim( cats[ i ] )
            r = ""
                    if #s > 0 then
                        r = string.format( "%s[[Category:%s]]", r, s )
                    end
                end -- for i
            end
         end
         end
        r = r ..
            "[[Category:Wikipedia:Wartung Modul:TemplatePar noError]]"
     end
     end
     return r
     return r
Zeile 834: Zeile 644:
     end -- for k, v
     end -- for k, v
     if r then
     if r then
         r = failure( "unknown",
         r = failure( "unknown", "'" .. r .. "'", options )
                    string.format( "'%s'", r ),
                    options )
     else -- all names valid
     else -- all names valid
         local i, s
         local i, s
Zeile 950: Zeile 758:




local function form( light, options, frame )
local function form( light, options )
     -- Run parameter analysis on current environment
     -- Run parameter analysis on current environment
     -- Precondition:
     -- Precondition:
Zeile 957: Zeile 765:
     --                options.mandatory
     --                options.mandatory
     --                options.optional
     --                options.optional
    --    frame    -- object; #invoke environment, or false
     -- Postcondition:
     -- Postcondition:
     --    Return string with error message as configured;
     --    Return string with error message as configured;
     --            false if valid
     --            false if valid
     -- Uses:
     -- Uses:
    --      < TemplatePar.frame
     --    fold()
     --    fold()
     --    fetch()
     --    fetch()
Zeile 968: Zeile 774:
     --    finalize()
     --    finalize()
     local duty, r
     local duty, r
    if frame then
        TemplatePar.frame = frame
    else
        TemplatePar.frame = mw.getCurrentFrame()
    end
     if type( options ) == "table" then
     if type( options ) == "table" then
         if type( options.mandatory ) ~= "table" then
         if type( options.mandatory ) ~= "table" then
Zeile 1.014: Zeile 815:
     --    feasible()
     --    feasible()
     --    failure()
     --    failure()
     local r = feasible( analyze, options, false )
     local r   = feasible( analyze, options, false )
     local show
     local show
     if options.min  and  not r then
     if options.min  and  not r then
Zeile 1.021: Zeile 822:
                 if options.max < options.min then
                 if options.max < options.min then
                     r = failure( "minmax",
                     r = failure( "minmax",
                                 string.format( "%d > %d",
                                 tostring( options.min )
                                                options.min,
                                .. " > " ..
                                                options.max ),
                                tostring( options.max ),
                                 options )
                                 options )
                 end
                 end
Zeile 1.030: Zeile 831:
                 show = " <" .. options.min
                 show = " <" .. options.min
                 if options.say then
                 if options.say then
                     show = string.format( "%s '%s'", show, options.say )
                     show = show .. " '" .. options.say .. "'"
                 end
                 end
                 r = failure( "tooShort", show, options )
                 r = failure( "tooShort", show, options )
Zeile 1.043: Zeile 844:
                 show = " >" .. options.max
                 show = " >" .. options.max
                 if options.say then
                 if options.say then
                     show = string.format( "%s '%s'", show, options.say )
                     show = show .. " '" .. options.say .. "'"
                 end
                 end
                 r = failure( "tooLong", show, options )
                 r = failure( "tooLong", show, options )
Zeile 1.066: Zeile 867:
     --            false if valid or no answer permitted
     --            false if valid or no answer permitted
     -- Uses:
     -- Uses:
    --    mw.text.trim()
     --    format()
     --    format()
     --    failure()
     --    failure()
     local r = false
     local r = false
     if type( assignment ) == "table" then
     if type( assignment ) == "table" then
         local story = assignment.args[ access ] or ""
         local story = assignment.args[ access ]
         if type( access ) == "number" then
         if type( story ) == "string" then
             story = mw.text.trim( story )
             if type( options ) ~= "table" then
        end
                options = { }
        if type( options ) ~= "table" then
            end
            options = { }
            options.say = access
            r = format( story, options )
        else
            r = failure( "invalid", access, options )
         end
         end
        options.say = access
        r = format( story, options )
     end
     end
     return r
     return r
Zeile 1.095: Zeile 896:
     -- Uses:
     -- Uses:
     --    form()
     --    form()
    --    mw.text.trim()
     --    failure()
     --    failure()
     --    finalize()
     --    TemplatePar.assert()
     --    TemplatePar.valid()
     --    TemplatePar.valid()
    --    TemplatePar.assert()
     local options = { mandatory = { "1" },
     local options = { mandatory = { "1" },
                       optional  = { "2",
                       optional  = { "2",
                                     "cat",
                                     "cat",
                                    "errNS",
                                     "low",
                                     "low",
                                     "max",
                                     "max",
                                     "min",
                                     "min",
                                    "noError",    -- OBSOLETE
                                     "format",
                                     "format",
                                    "preview",
                                     "template" },
                                     "template" },
                       template  = string.format( "&#35;invoke:%s|%s|",
                       template  = "&#35;invoke:TemplatePar|".. action .. "|"
                                                "TemplatePar",
                                                action )
                     }
                     }
     local r      = form( false, options, frame )
     local r      = form( false, options )
     if not r then
     if not r then
         local s
         local s
         options = { cat      = frame.args.cat,
         options = { cat      = frame.args.cat,
                    errNS    = frame.args.errNS,
                     low      = frame.args.low,
                     low      = frame.args.low,
                    noError  = frame.args.noError,    -- OBSOLETE
                     format  = frame.args.format,
                     format  = frame.args.format,
                    preview  = frame.args.preview,
                     template = frame.args.template
                     template = frame.args.template
                   }
                   }
Zeile 1.180: Zeile 977:
         if ( type( append ) == "string" ) then
         if ( type( append ) == "string" ) then
             if ( append ~= "" ) then
             if ( append ~= "" ) then
                 r = string.format( "%s<br />%s", append, r )
                 r = append .. "<br />" .. r
             end
             end
         else
         else
Zeile 1.202: Zeile 999:
     -- Uses:
     -- Uses:
     --    form()
     --    form()
     return form( true, options, false )
     return form( true, options )
end -- TemplatePar.check()
end -- TemplatePar.check()


Zeile 1.260: Zeile 1.057:
     return flat( t.args, options )
     return flat( t.args, options )
end -- TemplatePar.downcase()
end -- TemplatePar.downcase()
TemplatePar.failsafe = function ( assert )
    -- Retrieve versioning and check for compliance
    -- Precondition:
    --    assert  -- string, with required version or "wikidata",
    --                or false
    -- Postcondition:
    --    Returns  string with appropriate version, or false
    local r
    if since == "wikidata" then
        local item = TemplatePar.item
        since = false
        if type( item ) == "number"  and  item > 0 then
            local ent = mw.wikibase.getEntity( string.format( "Q%d",
                                                              item ) )
            if type( ent ) == "table" then
                local vsn = ent:formatPropertyValues( "P348" )
                if type( vsn ) == "table"  and
                  type( vsn.value) == "string"  and
                  vsn.value ~= "" then
                    r = vsn.value
                end
            end
        end
    end
    if not r then
        if not since  or  since <= TemplatePar.serial then
            r = TemplatePar.serial
        else
            r = false
        end
    end
    return r
end -- TemplatePar.failsafe()




Zeile 1.309: Zeile 1.070:
     --            false if valid or no answer permitted
     --            false if valid or no answer permitted
     -- Uses:
     -- Uses:
    --    >< TemplatePar.frame
     --    mw.text.trim()
     --    mw.text.trim()
     --    TemplatePar.downcase()
     --    TemplatePar.downcase()
    --    mw.getCurrentFrame()
     --    frame:getParent()
     --    frame:getParent()
     --    formatted()
     --    formatted()
Zeile 1.335: Zeile 1.096:
             params = TemplatePar.downcase( options )
             params = TemplatePar.downcase( options )
         else
         else
             if not TemplatePar.frame then
             params = mw.getCurrentFrame():getParent()
                TemplatePar.frame = mw.getCurrentFrame()
            end
            params = TemplatePar.frame:getParent()
         end
         end
         r = formatted( params, access, options )
         r = formatted( params, access, options )
Zeile 1.344: Zeile 1.102:
         r = failure( "noname", false, options )
         r = failure( "noname", false, options )
     end
     end
     return finalize( r, options, frame )
     return finalize( r, options )
end -- TemplatePar.valid()
end -- TemplatePar.valid()


Zeile 1.358: Zeile 1.116:
     -- Uses:
     -- Uses:
     --    form()
     --    form()
     return form( false, options, false )
     return form( false, options )
end -- TemplatePar.verify()
end -- TemplatePar.verify()


Zeile 1.377: Zeile 1.135:
     --    furnish()
     --    furnish()
     return furnish( frame, "assert" )
     return furnish( frame, "assert" )
end -- p.assert()
end -- .assert()




Zeile 1.393: Zeile 1.151:
                                     "opt",
                                     "opt",
                                     "cat",
                                     "cat",
                                    "errNS",
                                     "low",
                                     "low",
                                    "noError",    -- OBSOLETE
                                     "format",
                                     "format",
                                    "preview",
                                     "template" },
                                     "template" },
                       template  = "&#35;invoke:TemplatePar|check|"
                       template  = "&#35;invoke:TemplatePar|check|"
                     }
                     }
     local r = form( false, options, frame )
     local r = form( false, options )
     if not r then
     if not r then
         options = { mandatory = fill( frame.args.all ),
         options = { mandatory = fill( frame.args.all ),
                     optional  = fill( frame.args.opt ),
                     optional  = fill( frame.args.opt ),
                     cat      = frame.args.cat,
                     cat      = frame.args.cat,
                    errNS    = frame.args.errNS,
                     low      = frame.args.low,
                     low      = frame.args.low,
                    noError  = frame.args.noError,    -- OBSOLETE
                     format    = frame.args.format,
                     format    = frame.args.format,
                    preview  = frame.args.preview,
                     template  = frame.args.template
                     template  = frame.args.template
                   }
                   }
         r      = form( true, options, frame )
         r      = form( true, options )
     end
     end
     return r or ""
     return r or ""
end -- p.check()
end -- .check()




Zeile 1.425: Zeile 1.181:
     --    TemplatePar.count()
     --    TemplatePar.count()
     return tostring( TemplatePar.count() )
     return tostring( TemplatePar.count() )
end -- p.count()
end -- .count()




Zeile 1.436: Zeile 1.192:
     --    TemplatePar.countNotEmpty()
     --    TemplatePar.countNotEmpty()
     return tostring( TemplatePar.countNotEmpty() )
     return tostring( TemplatePar.countNotEmpty() )
end -- p.countNotEmpty()
end -- .countNotEmpty()




Zeile 1.442: Zeile 1.198:
function p.match( frame )
function p.match( frame )
     -- Combined analysis of parameters and their values
     -- Combined analysis of parameters and their values
    -- Precondition:
    --    frame  -- object; #invoke environment
     -- Postcondition:
     -- Postcondition:
     --    Return string with error message or ""
     --    Return string with error message or ""
     -- Uses:
     -- Uses:
    --      < TemplatePar.frame
     --    mw.text.trim()
     --    mw.text.trim()
     --    mw.ustring.lower()
     --    mw.ustring.lower()
Zeile 1.459: Zeile 1.212:
     local r = false
     local r = false
     local options = { cat      = frame.args.cat,
     local options = { cat      = frame.args.cat,
                      errNS    = frame.args.errNS,
                       low      = frame.args.low,
                       low      = frame.args.low,
                      noError  = frame.args.noError,    -- OBSOLETE
                       format  = frame.args.format,
                       format  = frame.args.format,
                      preview  = frame.args.preview,
                       template = frame.args.template
                       template = frame.args.template
                     }
                     }
     local k, v, s
     local k, v, s
     local params = { }
     local params = { }
    TemplatePar.frame = frame
     for k, v in pairs( frame.args ) do
     for k, v in pairs( frame.args ) do
         if type( k ) == "number" then
         if type( k ) == "number" then
Zeile 1.499: Zeile 1.250:
         end -- for k, v
         end -- for k, v
         options.optional = s
         options.optional = s
         r = form( true, options, frame )
         r = form( true, options )
     end
     end
     if not r then
     if not r then
Zeile 1.532: Zeile 1.283:
                     if lack then
                     if lack then
                         if errMiss then
                         if errMiss then
                             errMiss = string.format( "%s, '%s'",
                             errMiss = errMiss .. ", '" .. k .. "'"
                                                    errMiss, k )
                         else
                         else
                             errMiss = string.format( "'%s'", k )
                             errMiss = "'" .. k .. "'"
                         end
                         end
                     elseif not errMiss then
                     elseif not errMiss then
Zeile 1.555: Zeile 1.305:
     end
     end
     return r or ""
     return r or ""
end -- p.match()
end -- .match()




Zeile 1.568: Zeile 1.318:
     --    furnish()
     --    furnish()
     return furnish( frame, "valid" )
     return furnish( frame, "valid" )
end -- p.valid()
end -- .valid()
 
 
 
p.failsafe = function ( frame )
    -- Check or retrieve version information
    -- Precondition:
    --    frame  -- object; #invoke environment
    -- Postcondition:
    --    Return string with error message or ""
    -- Uses:
    --    TemplatePar.failsafe()
    local s = type( frame )
    local since
    if s == "table" then
        since = frame.args[ 1 ]
    elseif s == "string" then
        since = frame
    end
    if since then
        since = mw.text.trim( since )
        if since == "" then
            since = false
        end
    end
    return TemplatePar.failsafe( since )  or  ""
end -- p.failsafe()




Zeile 1.603: Zeile 1.327:
     --    Return table with functions
     --    Return table with functions
     return TemplatePar
     return TemplatePar
end -- p.TemplatePar()
end -- .TemplatePar()






return p
return p

Bitte beachte, dass alle Beiträge im Regiowiki von anderen Mitwirkenden bearbeitet, geändert oder gelöscht werden können. Reiche hier keine Texte ein, falls Du nicht willst, dass diese ohne Einschränkung geändert werden können.

Mit dem Speichern dieser Seite stimmst Du den Nutzungsbedingungen zu und versicherst, dass Du den Beitrag selbst verfasst hast bzw. dass er keine fremden Rechte verletzt, und willigst ein, ihn unter der Creative Commons Attribution/Share-Alike Lizenz 3.0 zu veröffentlichen. Übertrage ohne Genehmigung keine urheberrechtlich geschützten Inhalte!

Du stimmst einer Autorennennung mindestens durch URL oder Verweis auf den Artikel zu. Wenn Du nicht möchtest, dass Dein Text weiterbearbeitet und weiterverbreitet wird bzw. den Nutzungsbedingungen nicht zustimmst, dann speichere ihn nicht.

Abbrechen Bearbeitungshilfe (wird in einem neuen Fenster geöffnet)

[] [[]] | {{}} {{{}}} “” ‘’ «» ‹› „“ ‚‘ · × ° § ~~~~ <s></s> <small></small> <sup></sup> <sub></sub> <tt></tt> <code></code> <pre></pre> &nbsp; [[Kategorie:]] [[Datei:]] [[Media:]] {{DEFAULTSORT:}} {{NAMESPACE}} {{PAGENAME}} #REDIRECT[[]] <gallery></gallery> <!-- --> <nowiki></nowiki> <code><nowiki></nowiki></code> <includeonly></includeonly> <noinclude></noinclude> <onlyinclude></onlyinclude> <translate></translate> <tvar|></> <languages/>