--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
-- construct a table of tables: -- key = series ordinal; -- value = 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 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
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] = 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
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] = 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] .. " frameless|16px|link=https://orcid.org/" .. v.orcid .. "" end if v.emp then out[i] = out[i] .. frame:expandTemplate end end -- glue the list of authors together as a comma separated list local returntxt = "
" .. table.concat(out, ", ") return returntxtend
return p