Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/RexxS/WdRefs
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!
--[[ Returns a list of all claims and references, if any, from Wikidata ]] local p = {} p.seeRefs = function(frame) -- look for named parameter qid; if it's blank make it nil local qid = frame.args.qid if qid and (#qid == 0) then qid = nil end -- look for named parameter lang -- it should contain a two-character ISO-639 language code -- if it's blank fetch the language of the local wiki local lang = frame.args.lang if (not lang) or (#lang < 2) then lang = mw.language.getContentLanguage().code end local result = "{| class='wikitable sortable'\r\n! scope='col' | Property\r\n! scope='col' | Value\r\n" local numclaims = 0 local ent = mw.wikibase.getEntity(qid) if ent and ent.claims then for k1, v1 in pairs(ent.claims) do -- code to look for claims numclaims = numclaims + 1 result = result .. "|-\r\n| " .. (mw.wikibase.getLabel(k1) or "nolabel") .. " || " local numvals = 0 local val = "<pre>\r\n" for k2, v2 in pairs(v1) do numvals = numvals + 1 local valtype = v2.mainsnak.datatype if valtype == "wikibase-item" then local label = "Q" .. v2.mainsnak.datavalue.value["numeric-id"] label = mw.wikibase.getLabel("Q" .. v2.mainsnak.datavalue.value["numeric-id"]) or label val = val .. k2 .. ". " .. label elseif valtype == "string" or valtype == "external-id" or valtype == "url" or valtype == "commonsMedia" then val = val .. k2 .. ". " .. v2.mainsnak.datavalue.value elseif valtype == "monolingualtext" then val = val .. k2 .. ". " .. v2.mainsnak.datavalue.value.text else val = val .. k2 .. ". <" .. valtype .. "> " .. ent:formatPropertyValues(k1, mw.wikibase.entity.claimRanks).value -- expand this later end if v2.qualifiers then val = val .. " -- " .. mw.wikibase.renderSnaks(v2.qualifiers) end if v2.references then for k3, v3 in pairs(v2.references) do val = val .. " ++ Ref = " .. mw.wikibase.renderSnaks(v3.snaks) end val = val .. " \r\n" else val = val .. " -- NO REFS\r\n" end end val = val .. "</pre>\r\n" result = result .. val end end result = result .. "|}\r\n" .. numclaims .. " claims\r\n\r\n" if qid then result = result .. "[[d:" .. qid .. "|Edit this on Wikidata]]" else result = result .. "[[d:" .. ent.id .. "|Edit this on Wikidata]]" end return result 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)
Templates used on this page:
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Ombox
(
edit
)
Module:Arguments
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Message box/ombox.css
(
edit
)
Module:Sandbox/RexxS/WdRefs/doc
(
edit
)
Module:Yesno
(
edit
)