Module:Wikidata

From Zoophilia Wiki
Revision as of 18:48, 25 August 2013 by meta>RexxS (catch the script error if the spouse property P26 doesn't exist for this article - just show a message)
Jump to navigationJump to search

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

local p = {}

p.getSpouse = function(frame)
    local spouse_input = mw.text.trim(frame.args[1] or "")
    if spouse_input == "FETCH_WIKIDATA" then
        -- get from wikidata
        local entity = mw.wikibase.getEntity()
        if entity.claims.p26 > "" 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
            -- TODO: hlist return
            return table.concat(out, ", ")
        else
            return "Not Found"
        end
    else
        return spouse_input
    end
end

return p