Module:Wikidata: Difference between revisions

From Random Island Wiki
Jump to navigation Jump to search
>RexxS
(try to generalise function call by supplying an extra parameter)
>RexxS
(create function to get values that are not linked (e.g. dates))
Line 56: Line 56:
end
end


p.getRawValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            local out = {}
            for i=0, #entity.claims[propertyID] do
                out[#out + 1] = entity.claims[propertyID][i]
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end


return p
return p

Revision as of 10:49, 26 August 2013

Documentation for this module may be created at Module:Wikidata/doc

local p = {}

p.getSpouse = function(frame)
    local input_parm = mw.text.trim(frame.args[1] or "")
    if input_parm == "FETCH_WIKIDATA" then
        local entity = mw.wikibase.getEntity()
        if entity.claims.p26 ~= nil then
            local out = {}
            for k, v in pairs(entity.claims.p26) do
                out[#out + 1] = "[[" .. mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"]) .. "]]"
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end

p.getBirthPlace = function(frame)
    local input_parm = mw.text.trim(frame.args[1] or "")
    if input_parm == "FETCH_WIKIDATA" then
        local entity = mw.wikibase.getEntity()
        if entity.claims.p19 ~= nil then
            local out = {}
            for k, v in pairs(entity.claims.p19) do
                out[#out + 1] = "[[" .. mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"]) .. "]]"
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end

p.getValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            local out = {}
            for k, v in pairs(entity.claims[propertyID]) do
                out[#out + 1] = "[[" .. mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"]) .. "]]"
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end

p.getRawValue = function(frame)
    local propertyID = mw.text.trim(frame.args[1] or "")
    local input_parm = mw.text.trim(frame.args[2] or "")
    if input_parm == "FETCH_WIKIDATA" then
        local entity = mw.wikibase.getEntity()
        if entity.claims[propertyID] ~= nil then
            local out = {}
            for i=0, #entity.claims[propertyID] do
                out[#out + 1] = entity.claims[propertyID][i]
            end
            return table.concat(out, ", ")
        else
            return ""
        end
    else
        return input_parm
    end
end

return p