Modul:Infoboks USA delstater

Fra Wikipedia, den frie encyklopedi
Moduldokumentasjon
local p = {}

function dump( out )
    if type( out ) == 'table' then
        local s = '{ '
        for k,v in pairs( out ) do
                if type( k ) ~= 'number' then k = '"'..k..'"' end
                s = s .. '['..k..'] = ' .. dump( v ) .. ','
        end
        return s .. '} '
    else
        return tostring( out )
    end
end

-- Return bilde til artikkelen
function p.wikidataarg(frame,wikidataarg)
    if not mw.wikibase then
        return ""
    end
    local artikkel = mw.wikibase.getEntity()
    if not artikkel then
        return ""
    end
    local claims = artikkel.claims
    if not claims then
        return ""
    end
    local p36 = claims.p36   -- må generaliseres slik at wikidataarg brukes. Hvordan?
    if not p36 then
        return ""
    end

    return p36[0].mainsnak.datavalue.value
end

function p.framearg(frame,infoboksarg)
    local args = frame.args
    if args[1] == nil then
        local pFrame = frame:getParent();
        args = pFrame.args;
        for k,v in pairs( frame.args ) do
            args[k] = v;
        end
     end
     if args[infoboksarg] then
        return args[infoboksarg]
     end
     return ""
end

function p.velgArgument(frame,infoboksarg,wikidataarg)
    local arg = p.framearg(frame,infoboksarg)
    if arg then
        if arg == "" then
--            return ""
        else
           return arg
        end
    else
        return ""
    end

    return p.wikidataarg(frame,wikidataarg)
end

function p.hovedstad(frame)
    return p.velgArgument(frame,"hovedstad","P36") -- P36 er property i Wikidata for hovedstad
end

return p