-- Testing for arbitrary access-- Intended to be:-- Use : -- E.g.: - to fetch value of 'spouse' (P26) from 'Richard Burton' (Q151973)-- While in sandbox:-- Use : -- E.g.: - to fetch value of 'spouse' (P26) from 'Richard Burton' (Q151973)
local p =
-- This is used to get a value, or a comma separated list of them if multiple values existp.getValueFromID = function(frame) local itemID = mw.text.trim(frame.args[1] or "") local propertyID = mw.text.trim(frame.args[2] or "") local input_parm = mw.text.trim(frame.args[3] or "") if input_parm
"value" and claims[1].mainsnak.datavalue.type
nil then label = "Q" .. v.mainsnak.datavalue.value["numeric-id"] end if sitelink then out[#out + 1] = "" .. label .. "" else out[#out + 1] = "" .. label .. "[*]" end end return table.concat(out, ", ") else return entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value end else return "" end else return input_parm endend
-- A function to return the QID of a property value, rather than its text label-- May be useful for constructing chains of calls to get properties of properties, etc.-- It returns the QID of only the first property value if more than one-- Use like this: -- That will fetch the QID of the first value for the spouse (P26) of Richard Burton (Q151973)-- Returns an empty string if the value doesn't exist or has no QID.
p.getQIDFromID = function(frame) local itemID = mw.text.trim(frame.args[1] or "") local propertyID = mw.text.trim(frame.args[2] or "") local input_parm = mw.text.trim(frame.args[3] or "")
local entity = mw.wikibase.getEntity(itemID) local claims = entity.claims[propertyID] if claims then -- if wiki-linked value return the QID of the first value of the property if (claims[1] and claims[1].mainsnak.snaktype
"wikibase-entityid") then return "Q" .. claims[1].mainsnak.datavalue.value["numeric-id"] else return "" end else return "" endend
return p