Modul:Vorlage:VorlagendokumentationFlagIcon

Die Dokumentation für dieses Modul kann unter Modul:Vorlage:VorlagendokumentationFlagIcon/Doku erstellt werden

--[=[
Support {{Vorlagendokumentation Land mit Flagge}}
* first2
* flat
* from
]=]



local Title = mw.title.getCurrentTitle()



local flat = function ( aaa, frame )
    -- Linktitel aus FlagIcon auslesen
    -- Precondition:
    --     aaa    -- Title object or 3 letter string; of Template:AAA
    --     frame  -- object; #invoke environment
    -- Postcondition:
    --     Return link title or not
    local r, t
    if type( aaa ) == "string" then
        t = mw.title.makeTitle( 10, aaa )
        if not t.protectionLevels.edit then
            t = false
        end
    else
        t = aaa
    end
    if t then
        local s = frame:expandTemplate{ title = t }
        if s:sub( -2 ) == "]]"  or
           s:sub( -9 ) == "]]</span>" then
            local i
            s = s:reverse( s )
            i = s:find( "[[", 2, true )
            if i then
                s = s:sub( 3,  i - 1 )
                s = s:reverse( s )
                i = s:find( "|", 1, true )
                if i then
                    s = s:sub( i + 1 )
                end
                if s:sub( 1 ) == ":" then
                    s = s:sub( 2 )
                end
                i = s:find( "]]", 2, true )
                if i then
                    s = s:sub( 1,  i - 1 )
                end
                s = s:gsub( '["|{}<>]', "" )
                if s ~= "" then
                    r = s
                end
            end
        end
    end
    return r
end -- flat()



-- Export
local p = { }

p.first2 = function ( frame )
    -- Staatsnamen (verlinkt) zu AA-FlagIcon ermitteln
    -- Precondition:
    --     frame  -- object; #invoke environment
    -- Postcondition:
    --     Return wikilink or ""
    local r
    if Title.namespace == 10 then
        local s = Title.text
        if s:match( "^%u%u-" ) then
            local seek = "Info ISO-3166-2:"
            local t    = mw.title.makeTitle( 10,  seek .. s:sub( 1, 2 ) )
            if t.protectionLevels.edit then
                local params = { }
                table.insert( params, "lemma" )
                s = frame:expandTemplate{ title=t,  args=params }
                r = string.format( "[[%s]]",  s )
            end
        end
    end
    return r or ""
end -- p.first2()

p.flag = function ( frame )
    -- Beschreibung zu HDK bilden
    -- Precondition:
    --     frame  -- object; #invoke environment
    -- Postcondition:
    --     Return text or ""
    local r
    if Title.namespace == 10 then
        local sign, s = Title.text:match( "^(%u%u%u)-([HDKSL].*)$" )
        if s then
            local spec, sJahr = s:match( "^([HDKLS]+)-(.+)$" )
            if sJahr then
                sJahr = sJahr:match( "^[12]%d%d%d" )
            else
                spec = s:match( "^[HDKLS]+$" )
            end
            if spec then
                local hdk = { "H", "D", "K" }
                local texts = { H = "Handelsflagge",
                                D = "Dienstflagge",
                                K = "Kriegsflagge",
                                L = "/Land",
                                S = "/See" }
                for i = 1, #hdk do
                    s = hdk[ i ]
                    if spec:match( s ) then
                        r = texts[ s ]
                        if s ~= "H" then
                            if spec:find( "L" .. s,  1,  true ) then
                                 r = r .. texts.L
                            elseif spec:find( "S" .. s,  1,  true ) then
                                 r = r .. texts.S
                            end
                        end
                    end
                end -- for i
                if r and sJahr then
                    r = string.format( "%s; ab&#160;%s", r, sJahr )
                end
            end
        end
    end
    return r or ""
end -- p.flag()

p.flat = function ( frame )
    -- Linktitel aus FlagIcon auslesen
    -- Precondition:
    --     frame  -- object; #invoke environment
    --                       args.pre  -- prefix (optional)
    -- Postcondition:
    --     Return link title or ""
    local r
    if Title.namespace == 10 then
        r = flat( Title, frame )
        if r and frame.args.pre then
            r = frame.args.pre .. r
        end
    end
    return r or ""
end -- p.flat()

p.from = function ( frame )
    -- Ggf. Landesname und Jahreszahl zu AAA-9999-FlagIcon ermitteln
    -- Precondition:
    --     frame  -- object; #invoke environment
    -- Postcondition:
    --     Return details or ""
    local r
    if Title.namespace == 10 then
        local sA3, sNum = Title.text:match( "^(%u%u%u)-([12]%d%d%d)$" )
        if sA3 then
            local self  = flat( Title, frame )
            local short = flat( sA3, frame )
            sNum = string.format( "ab&#160;%s", sNum )
            if short  and  short ~= self then
                r = string.format( "%s; %s", short, sNum )
            end
            r = r or sNum
        end
    end
    return r or ""
end -- p.from()

return p

Die News der letzten Tage