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/Authors
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!
--[[ Fetch authors from Wikidata --]] p = {} function p.getAuthors(frame) local args= frame.args if not args.qid and not args[1] then args = frame:getParent().args end local qid = mw.text.trim(args[1] or args.qid or "") if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end if not qid then return end -- construct a table of tables: -- key = series ordinal; -- value = {name=author's name, orcid=author's orcid id, emp=author's employer} local auths = {} -- series ordinal = true when used local ords = {} -- list of employers local emps = {} -- keep track of values without series ordinals and max ordinal local noord = 0 local maxord = 0 -- get authors that have entries local prop50 = mw.wikibase.getBestStatements(qid, "P50") for i, v in ipairs(prop50) do if v.mainsnak.snaktype == "value" then -- get author's qid local nameid = v.mainsnak.datavalue.value.id -- get author's name local name = mw.wikibase.getLabel(nameid) or "No label" -- get author's orcid id local orcid local orcidtbl = mw.wikibase.getBestStatements(nameid, "P496")[1] if orcidtbl and orcidtbl.mainsnak.snaktype == "value" then orcid = orcidtbl.mainsnak.datavalue.value end -- get author's employer local emp local emptbl = mw.wikibase.getBestStatements(nameid, "P108")[1] if emptbl and emptbl.mainsnak.snaktype == "value" then emp = mw.wikibase.getLabel(emptbl.mainsnak.datavalue.value.id) end if emp then emps[emp] = true end -- get ordinal local ordinal = noord if v.qualifiers then qualP1545 = v.qualifiers["P1545"][1] if qualP1545 then ordinal = tonumber(qualP1545.datavalue.value) or noord end end if ordinal == noord then noord = noord -1 end -- check for a duplicate ordinal if ords[ordinal] then repeat ordinal = ordinal + 1 until not ords[ordinal] end auths[ordinal] = {name = name, orcid = orcid, emp = emp} ords[ordinal] = true if ordinal > maxord then maxord = ordinal end end end -- add author's name strings to the author's table local propP2093 = mw.wikibase.getBestStatements(qid, "P2093") for i, v in ipairs(propP2093) do if v.mainsnak.snaktype == "value" then local name = v.mainsnak.datavalue.value local ordinal = noord if v.qualifiers then qualP1545 = v.qualifiers["P1545"][1] if qualP1545 then ordinal = tonumber(qualP1545.datavalue.value) or noord end end if ordinal == noord then noord = noord -1 end -- check for a duplicate ordinal if ords[ordinal] then repeat ordinal = ordinal + 1 until not ords[ordinal] end auths[ordinal] = {name = name} ords[ordinal] = true if ordinal > maxord then maxord = ordinal end end end -- compact the auths table into a sequence local authors = {} for idx = 1, maxord do if auths[idx] then table.insert(authors, auths[idx]) end end for idx = 0, noord, -1 do if auths[idx] then table.insert(authors, auths[idx]) end end -- create a sequence of employers local employers = {} for k, v in pairs(emps) do table.insert(employers, k) end -- construct some output out = {} for i, v in ipairs(authors) do out[i] = v.name if v.orcid then out[i] = out[i] .. " [https://orcid.org/" .. v.orcid .. " ORCIDicon]" end if v.emp then out[i] = out[i] .. " <sup>" .. v.emp .. "</sup>" end end -- glue the list of authors together as a comma separated list local returntxt = "<p>" .. table.concat(out, ", ") -- add a list of employers returntxt = returntxt .. "</p><p>" .. table.concat(employers, ", ") .. "</p>" return returntxt 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/Authors/doc
(
edit
)