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

From blackwiki
Jump to navigation Jump to search
blackwiki>Tom Morris
(i'm an idiot - zero-indexed is for other languages!)
m (27 revisions imported)
 
(16 intermediate revisions by one other user not shown)
Line 2: Line 2:
  
 
p.spouse = function(frame)
 
p.spouse = function(frame)
     if not frame.args[1] == nil then
+
     local spouse_input = mw.text.trim(frame.args[1] or "")
         if not frame.args[2] == nil then
+
    if spouse_input == "PARAMETER_NOT_SET" then
            return "[[" + frame.args[1] + "|" + frame.args[2] + "]]"
+
         -- get from wikidata
        else
+
        local entity = mw.wikibase.getEntity()
            return "[[" + frame.args[1] + "]]"
+
        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
 
         end
 +
        -- TODO: hlist return
 +
        return table.concat(out, ", ")
 
     else
 
     else
         local entity = mw.wikibase.getEntity()
+
         return spouse_input
        if not entity.claims.p26 == nil then
 
            local label = mw.wikibase.label( "Q" .. entity.claims.p26[1].mainsnak.datavalue.value["numeric-id"])
 
            return "[[" + label + "]]"
 
        end
 
 
     end
 
     end
 
end
 
end
  
 
return p
 
return p

Latest revision as of 14:54, 27 September 2020

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 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 spouse_input
    end
end

return p