Module:BIC

提供: VANGUARD FLIGHT wiki
2014年3月30日 (日) 23:14時点におけるTaku.oshino (トーク | 投稿記録)による版 (1版)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索
Module for support of Template:BIC and previous Template:Bien Catalogado now merged. That is for monuments of Spanish heritage registered as Bien de Interés Cultural (BIC) and other buildings registered at regional level. See documentation of the template for more information.

Messages can be translated at Module:BIC/lang.

This module generates missing optional parameters based on patterns of the identifier of the object:

if id begins with defaults to
RI-52 type=JH
RI-53 type=CH
RI-54 type=SH
RI-55 type=ZA
7-INM type=BC, link=ar, idurl=id
IPA- type=BC, link=ct, idurl=id
IPAPC- type=ZA, link=ct
08019/ type=BC, link=ct, idurl=id
03. type=BC, link=vc
12. type=BC, link=vc
46. type=BC, link=vc

otherwise assumes type=M and links to http://toolserver.org/~platonides/wlm/ids.php


-- Support for Template:BIC

local i18n = require("Module:BIC/lang")
local this = {}

function this.templateBIC(frame)
    -- Get language
    local args = frame.args
    local lang = "en" -- default
    if i18n[args.lang1] then
        lang = args.lang1
    elseif i18n[args.lang2] then
        lang = args.lang2 -- first fallback
    elseif i18n[args.lang3] then
        lang = args.lang3 -- second fallback
    end
    local i18nLang = i18n[lang]
    
    -- Get template parameters
    local pargs = frame:getParent().args
    local id = pargs[1] or ""
    local db = mw.ustring.lower(pargs.link or "")
    local idurl = pargs.idurl or ""
    local type = mw.ustring.upper(pargs.type or "")
    
    -- Get defaults based on id patterns
    if id ~= "" then
        if db == "" then
            db = this.getDb(id)
        end
        if idurl == "" then
            idurl = this.getIdurl(id)
        end
        if type == "" then
            type = this.getType(id)
        end
    end

    local namespace = mw.title.getCurrentTitle().nsText
    
    -- Layout
    local ret = {}
    table.insert(ret, '{| cellspacing="4" ')
    table.insert(ret, 'style="text-align:left; color:#000; background:#F9FFF0;')
    table.insert(ret, ' border:1px solid #BBA22C; margin:1px;"\n')
    table.insert(ret, '| style="width:32px; height:32px;" ')
    table.insert(ret, '| [[File:Icone chateau fort.svg|30px|link=]]\n')
    table.insert(ret, '| style="font-size:9pt; padding:1pt; line-height:1.1em;" |')
    -- from Template:Lang
    table.insert(ret, '<p><span lang="' .. lang .. '" xml:lang="' .. lang .. '" class="description ' .. lang .. '">')
    if namespace == "Category" then
        table.insert(ret, i18nLang.text1Cat)
    else
        table.insert(ret, i18nLang.text1File)
    end
    if type == "CH" then
        table.insert(ret, i18nLang.text2CH)
    elseif type == "JH" then
        table.insert(ret, i18nLang.text2JH)
    elseif type == "SH" then
        table.insert(ret, i18nLang.text2SH)
    elseif type == "ZA" then
        table.insert(ret, i18nLang.text2ZA)
    elseif type == "BC" then
        table.insert(ret, i18nLang.text2BC)
    else
        table.insert(ret, i18nLang.text2M)
    end
    if type == "BC" then
        if db == "ar" then
            table.insert(ret, i18nLang.text3BCar)
        elseif db == "ct" then
            table.insert(ret, i18nLang.text3BCct)
        elseif db == "vc" then
            table.insert(ret, i18nLang.text3BCvc)
        else
            table.insert(ret, i18nLang.text3BC)
        end
    else
        if db == "ct" then
            table.insert(ret, i18nLang.text3BICct)
        elseif db == "vc" then
            table.insert(ret, i18nLang.text3BICvc)
        else
            table.insert(ret, i18nLang.text3BIC)
        end
    end
    table.insert(ret, i18nLang.text4)
    table.insert(ret, '</span><span style="white-space:nowrap;">')
    if id ~= "" then
        local idEncode = mw.uri.encode(id, PATH)
        if idurl ~= "" then
            if db == "ar" then
                table.insert(ret, '[http://www.sipca.es/censo/' .. idurl .. '/.html')
            elseif db == "ct" then
                if mw.ustring.find(idurl, "^bcn/") then
                    table.insert(ret, '[http://w10.bcn.es/APPS/cat_patri/editElement.do?reqCode=inspect&id.identificador=')
                    table.insert(ret, mw.ustring.sub(idurl, 8))
                    table.insert(ret, '&id.districte=' .. mw.ustring.sub(idurl, 5, 6))
                else
                    table.insert(ret, '[http://cultura.gencat.cat/invarquit/Fitxa.asp?idregistre=')
                    table.insert(ret, idurl)
                end
            elseif db == "vc" then
                if type == "BC" then
                    table.insert(ret, '[http://www.cult.gva.es/dgpa/brl/Detalles_brl.asp?IdInmueble=')
                else
                    table.insert(ret, '[http://www.cult.gva.es/dgpa/bics/Detalles_bics.asp?IdInmueble=')
                end
                table.insert(ret, idurl)
            else
                table.insert(ret, '[http://toolserver.org/~platonides/wlm/ids.php?bic=')
                table.insert(ret, idEncode .. '&userlang=' .. args.lang1)
            end
        else
            table.insert(ret, '[http://toolserver.org/~platonides/wlm/ids.php?bic=')
            table.insert(ret, idEncode .. '&userlang=' .. args.lang1)
        end
        table.insert(ret, ' ' .. id .. ']')
    else
        table.insert(ret, "''" .. i18nLang.text5 .. "''")
    end
    table.insert(ret, '.</span></p>\n|}')
    
    return table.concat(ret)
end

function this.getDb(id)
    local dbDefault = ""
    if mw.ustring.find(id, "^[17]%-INM") then
        dbDefault = "ar"
    elseif mw.ustring.find(id, "^08019/") or mw.ustring.find(id, "^IPA") then
        dbDefault = "ct"
    elseif mw.ustring.find(id, "^PH%-874") then
        dbDefault = "vc"
    elseif mw.ustring.find(id, "^[014][236]%.") then -- strictly 03. 12. 46.
        dbDefault = "vc"
    end
    return dbDefault
end

function this.getIdurl(id)
    local idurlDefault = ""
    if mw.ustring.find(id, "^IPA%-") then
        idurlDefault = mw.ustring.sub(id, 5)
    elseif mw.ustring.find(id, "^[17]%-INM") then
        idurlDefault = id
    end
    return idurlDefault
end

function this.getType(id)
    local typeDefault = "M"
    if mw.ustring.find(id, "^RI%-52") then
        typeDefault = "JH"
    elseif mw.ustring.find(id, "^RI%-53") then
        typeDefault = "CH"
    elseif mw.ustring.find(id, "^RI%-54") then
        typeDefault = "SH"
    elseif mw.ustring.find(id, "^RI%-55") or mw.ustring.find(id, "^IPAPC%-") then
        typeDefault = "ZA"
    elseif mw.ustring.find(id, "^PH%-874") then
        typeDefault = "ZA"
    elseif mw.ustring.find(id, "^08019/") or mw.ustring.find(id, "^IPA%-") then
        typeDefault = "BC"
    elseif mw.ustring.find(id, "^[014][236]%.") or mw.ustring.find(id, "^7%-INM") then
        typeDefault = "BC"
    end
    return typeDefault
end

return this