Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/RexxS/AA
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- Testing for arbitrary access -- Intended to be: -- Use : {{#invoke:Wikidata|getValueFromID|<ID>|<Property>|FETCH_WIKIDATA}} -- E.g.: {{#invoke:Wikidata|getValueFromID|Q151973|P26|FETCH_WIKIDATA}} - to fetch value of 'spouse' (P26) from 'Richard Burton' (Q151973) -- While in sandbox: -- Use : {{#invoke:Sandbox/RexxS/AA|getValueFromID|<ID>|<Property>|FETCH_WIKIDATA}} -- E.g.: {{#invoke:Sandbox/RexxS/AA|getValueFromID|Q151973|P26|FETCH_WIKIDATA}} - 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 exist p.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] = "[[" .. sitelink .. "|" .. label .. "]]" else out[#out + 1] = "[[:d:Q" .. v.mainsnak.datavalue.value["numeric-id"] .. "|" .. label .. "]]<abbr title='Article is not yet available in this wiki'>[*]</abbr>" end end return table.concat(out, ", ") else return entity:formatPropertyValues(propertyID, mw.wikibase.entity.claimRanks).value end else return "" end else return input_parm end end -- 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: {{#invoke:Sandbox/RexxS/AA|getQIDFromID|Q151973|P26|FETCH_WIKIDATA}} -- 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 "" end end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/RexxS/AA/doc
(
edit
)