Module:Sandbox/RexxS/AA explained

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

"FETCH_WIKIDATA" then local entity = mw.wikibase.getEntity(itemID) local claims = entity.claims[propertyID] if claims then -- if wiki-linked value output as link if possible if (claims[1] and claims[1].mainsnak.snaktype

"value" and claims[1].mainsnak.datavalue.type

"wikibase-entityid") then local out = for k, v in pairs(claims) do local sitelink = mw.wikibase.sitelink("Q" .. v.mainsnak.datavalue.value["numeric-id"]) local label = mw.wikibase.label("Q" .. v.mainsnak.datavalue.value["numeric-id"]) if label

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

"value" and claims[1].mainsnak.datavalue.type

"wikibase-entityid") then return "Q" .. claims[1].mainsnak.datavalue.value["numeric-id"] else return "" end else return "" endend

return p