diff --git a/module_citeq.lua b/module_citeq.lua index 28e5bee..6bfb259 100644 --- a/module_citeq.lua +++ b/module_citeq.lua @@ -129,6 +129,7 @@ local function makelink(v, out, maxpos, wdl, namestyle) if v.mainsnak.snaktype == "value" then if v.mainsnak.datatype == "wikibase-item" then local qnumber = v.mainsnak.datavalue.value.id + local human_instance = false local sitelink = mw.wikibase.getSitelink(qnumber) if qnumber == "Q2818964" then sitelink = nil end -- suppress link to "Various authors" @@ -172,7 +173,18 @@ local function makelink(v, out, maxpos, wdl, namestyle) if item_lookup and position <= max_authors_displayed then last_name = last_name or getValue({"P734", qid=qnumber, maxvals=1, ps=2}) first_names = first_names or getValue({"P735", qid=qnumber, maxvals=0, ps=2}) + + -- check if P31 "instance of" Q5 "human" + local instance_of = mw.wikibase.getBestStatements(qnumber, 'P31') + if instance_of and instance_of[1] then + for k, vi in pairs(instance_of) do + if vi.mainsnak.snaktype == "value" and vi.mainsnak.datatype == "wikibase-item" and vi.mainsnak.datavalue.value.id == 'Q5' then + human_instance = true + end + end + end end + if first_names then first_names = getStyledNames(first_names, namestyle) end @@ -192,6 +204,7 @@ local function makelink(v, out, maxpos, wdl, namestyle) first = first_names or nil, link = sitelink or nil, qid = qnumber, + human = human_instance, } end elseif v.mainsnak.datatype == "string" then @@ -342,6 +355,7 @@ local function get_name_list (nl_type, args, qid, wdl) label = label:gsub(''', '\''); -- prevent cs1|2 multiple names categorization; replace html entity with the actual character names[i].label = label names[i].qid = out[k].qid or nil + names[i].human = out[k].human or nil mw.log(i .. " " .. k .. " " .. label) if args[nl_type .. i] then -- name gets overwritten -- pull corresponding -link only if overwritten name is same as WD name @@ -835,10 +849,10 @@ local function _cite_q (citeq_args) local missing_names = {} for i, author in pairs(names.authors or {}) do -- mw.logObject(author) - if not author.last and i <= (tonumber (citeq_args['display-authors']) or tonumber (author_count)) then + if not author.last and i <= (tonumber(citeq_args['display-authors']) or author_count) then if author.qid then - -- ignore anonymous - if author.qid ~= 'Q4233718' then + -- ignore anonymous or non-humans + if author.human then table.insert(missing_names, author.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. author.qid .. "]] ]]") end else @@ -847,10 +861,10 @@ local function _cite_q (citeq_args) end end for i, editor in pairs(names.editors or {}) do - if not editor.last and i <= (tonumber (citeq_args['display-editors']) or tonumber (editor_count)) then + if not editor.last and i <= (tonumber(citeq_args['display-editors']) or editor_count) then if editor.qid then - -- ignore anonymous - if editor.qid ~= 'Q4233718' then + -- ignore anonymous or non-humans + if editor.human then table.insert(missing_names, editor.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. editor.qid .. "]] ]]") end else @@ -861,8 +875,8 @@ local function _cite_q (citeq_args) for i, translator in pairs(names.translators or {}) do if not translator.last then if translator.qid then - -- ignore anonymous - if translator.qid ~= 'Q4233718' then + -- ignore anonymous or non-humans + if translator.human then table.insert(missing_names, translator.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. translator.qid .. "]] ]]") end else