Module:Wikidata: Difference between revisions

From Random Island Wiki
Jump to navigation Jump to search
>RexxS
(return an empty string instead of the message)
>RexxS
(rename to generalise input parameter; add birthplace)
Line 2: Line 2:


p.getSpouse = function(frame)
p.getSpouse = function(frame)
     local spouse_input = mw.text.trim(frame.args[1] or "")
     local input_parm = mw.text.trim(frame.args[1] or "")
     if spouse_input == "FETCH_WIKIDATA" then
     if input_parm == "FETCH_WIKIDATA" then
         local entity = mw.wikibase.getEntity()
         local entity = mw.wikibase.getEntity()
         if entity.claims.p26 ~= nil then
         if entity.claims.p26 ~= nil then
Line 15: Line 15:
         end
         end
     else
     else
         return spouse_input
         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
end
end


return p
return p

Revision as of 15:44, 25 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

return p