Difference between revisions of "Module:Sandbox/Tom Morris"

From blackwiki
Jump to navigation Jump to search
blackwiki>Tom Morris
(avoiding nils)
blackwiki>Tom Morris
(expanding to deal with multiple spouses)
Line 7: Line 7:
 
         local entity = mw.wikibase.getEntity()
 
         local entity = mw.wikibase.getEntity()
 
         local label = mw.wikibase.sitelink("Q" .. entity.claims.p26[0].mainsnak.datavalue.value["numeric-id"])
 
         local label = mw.wikibase.sitelink("Q" .. entity.claims.p26[0].mainsnak.datavalue.value["numeric-id"])
         return "[[" .. label .. "]]"
+
         local out = {}
 +
        for k, v in pairs(entity.claims.p26) do
 +
            out[#out + 1] = "[[" .. mw.wikibase.sitelink(v.mainsnak.datavalue.value["numeric-id"]) .. "]]"
 +
        end
 +
        return table.concat(out, ", ")
 
     else
 
     else
 
         return spouse_input
 
         return spouse_input

Revision as of 15:12, 19 May 2013

Documentation for this module may be created at Module:Sandbox/Tom Morris/doc

local p = {}

p.spouse = function(frame)
    local spouse_input = mw.text.trim(frame.args[1] or "")
    if spouse_input == "PARAMETER_NOT_SET" then
        -- get from wikidata
        local entity = mw.wikibase.getEntity()
        local label = mw.wikibase.sitelink("Q" .. entity.claims.p26[0].mainsnak.datavalue.value["numeric-id"])
        local out = {}
        for k, v in pairs(entity.claims.p26) do
            out[#out + 1] = "[[" .. mw.wikibase.sitelink(v.mainsnak.datavalue.value["numeric-id"]) .. "]]"
        end
        return table.concat(out, ", ")
    else
        return spouse_input
    end
end

return p