diff --git a/module_citeq.lua b/module_citeq.lua index f3a51ed..9f392be 100644 --- a/module_citeq.lua +++ b/module_citeq.lua @@ -122,7 +122,7 @@ local function make_citeref(names, year) end -- function to fetch a value to display -local function makelink(v, out, maxpos, wdl, namestyle) +local function makelink(v, out, link, maxpos, wdl, namestyle) local label local item_lookup = false if v.mainsnak.snaktype == "value" then @@ -176,22 +176,42 @@ local function makelink(v, out, maxpos, wdl, namestyle) first_names = getStyledNames(first_names, namestyle) end - if wdl then - -- show that there's a Wikidata entry available - out[position] = string.format( - "[[:d:Q%s|%s]] [[File:Wikidata-logo.svg|16px|alt=|link=]]", - v.mainsnak.datavalue.value["numeric-id"], - label, - cfg.i18n_t["errors"]["local-article-not-found"] - ) + if sitelink then + -- just the plain name, + -- but keep a record of the links, using the same index + if last_name and first_names then + out[position] = { + label = label, + last = last_name or nil, + first = first_names or nil, + qid = qnumber or nil, + } + else + out[position] = label + end + link[position] = sitelink else - out[position] = { - label = label, - last = last_name or nil, - first = first_names or nil, - link = sitelink or nil, - qid = qnumber, - } + if wdl then + -- show that there's a Wikidata entry available + out[position] = string.format( + "[[:d:Q%s|%s]] [[File:Wikidata-logo.svg|16px|alt=|link=]]", + v.mainsnak.datavalue.value["numeric-id"], + label, + cfg.i18n_t["errors"]["local-article-not-found"] + ) + else + -- no Wikidata links wanted, so just give the plain label + if last_name and first_names then + out[position] = { + label = label, + last = last_name or nil, + first = first_names or nil, + qid = qnumber or nil, + } + else + out[position] = label + end + end end elseif v.mainsnak.datatype == "string" then local position = maxpos + 1 -- Default to 'next' author. @@ -211,17 +231,23 @@ local function makelink(v, out, maxpos, wdl, namestyle) first_names = getStyledNames(v.qualifiers.P9687[1].datavalue.value, namestyle) end - out[position] = { - label = v.mainsnak.datavalue.value, - last = last_name or nil, - first = first_names or nil, - } + if last_name and first_names then + out[position] = { + label = v.mainsnak.datavalue.value, + last = last_name or nil, + first = first_names or nil, + } + else + out[position] = v.mainsnak.datavalue.value + end else -- not a wikibase-item or a string! end else -- try the "object named as" qualifier, otherwise use the unknown author item if v.qualifiers and v.qualifiers.P1932 then + label = v.qualifiers.P1932[1].datavalue.value -- "object named as" + -- Names from "author given names" and "author last names" qualifiers local last_name local first_names @@ -231,13 +257,14 @@ local function makelink(v, out, maxpos, wdl, namestyle) if v.qualifiers and v.qualifiers.P9687 and v.qualifiers.P9687[1] then first_names = getStyledNames(v.qualifiers.P9687[1].datavalue.value, namestyle) end - label = { - label = v.qualifiers.P1932[1].datavalue.value, -- "object named as" - last = last_name or nil, - first = first_names or nil, - } + if last_name and first_names then + label = { + label = label, + last = last_name or nil, + first = first_names or nil, + } + end else - -- use anonymous label = { label = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper) .. (cfg.i18n_t.trackingcats["unknown-author"] or ""), qid = 'Q4233718', @@ -308,13 +335,15 @@ local function get_name_list (nl_type, args, qid, wdl) end -- So now we have something to return: - -- table 'out' is going to store the name label, qid, first/last names, and link to the name's article + -- table 'out' is going to store the names(s): + -- and table 'link' will store any links to the name's article local out = {} + local link = {} local maxpos = 0 if props and props[1] then for k, v in pairs(props) do if 'deprecated' ~= v.rank then -- ignore deprecated names - maxpos = makelink(v, out, maxpos, wdl, args['name-list-style']) + maxpos = makelink(v, out, link, maxpos, wdl, args['name-list-style']) end end end @@ -322,7 +351,7 @@ local function get_name_list (nl_type, args, qid, wdl) -- second properties for k, v in pairs(fallback) do if 'deprecated' ~= v.rank then -- ignore deprecated names - maxpos = makelink(v, out, maxpos, wdl, args['name-list-style']) + maxpos = makelink(v, out, link, maxpos, wdl, args['name-list-style']) end end end @@ -337,30 +366,35 @@ local function get_name_list (nl_type, args, qid, wdl) table.sort(keys) -- as they might be out of order for i, k in ipairs(keys) do names[i] = {} - local label = out[k].label + local label + if out[k].label then + label = out[k].label + else + label = out[k] + end 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 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 - if out[k].link and (args[nl_type .. i] == label) then - args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or out[k].link -- author-linkn or editor-linkn - names[i].link = out[k].link + if link[k] and (args[nl_type .. i] == label) then + args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn + names[i].link = link[k] end else -- name does not get overwritten, so pull name from WD - names[i].last = out[k].last or nil - names[i].first = out[k].first or nil if out[k].first and out[k].last then -- First/last names were found, so add them args[nl_type .. '-last' .. i] = args[nl_type .. '-last' .. i] or out[k].last args[nl_type .. '-first' .. i] = args[nl_type .. '-first' .. i] or out[k].first + names[i].last = out[k].last + names[i].first = out[k].first else - args[nl_type .. i] = out[k].label + args[nl_type .. i] = label end - if out[k].link then - args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or out[k].link -- author-linkn or editor-linkn - names[i].link = out[k].link + if link[k] then + args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn + names[i].link = link[k] end end end @@ -824,13 +858,9 @@ local function _cite_q (citeq_args) -- check only the names being displayed for missing first/last name errors local missing_names = {} for i, author in pairs(names.authors or {}) do - -- mw.logObject(author) if not author.last and i <= (citeq_args['display-authors'] or author_count) then - if author.qid then + if author.qid and author.qid == 'Q4233718' then -- ignore anonymous - if author.qid ~= 'Q4233718' then - table.insert(missing_names, author.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. author.qid .. "]] ]]") - end else table.insert(missing_names, author.label) end @@ -838,11 +868,8 @@ local function _cite_q (citeq_args) end for i, editor in pairs(names.editors or {}) do if not editor.last and i <= (citeq_args['display-editors'] or editor_count) then - if editor.qid then + if editor.qid and editor.qid == 'Q4233718' then -- ignore anonymous - if editor.qid ~= 'Q4233718' then - table.insert(missing_names, editor.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. editor.qid .. "]] ]]") - end else table.insert(missing_names, editor.label) end @@ -850,11 +877,8 @@ local function _cite_q (citeq_args) end for i, translator in pairs(names.translators or {}) do if not translator.last then - if translator.qid then + if translator.qid and translator.qid == 'Q4233718' then -- ignore anonymous - if translator.qid ~= 'Q4233718' then - table.insert(missing_names, translator.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. translator.qid .. "]] ]]") - end else table.insert(missing_names, translator.label) end @@ -865,8 +889,7 @@ local function _cite_q (citeq_args) local name_cat = cfg.i18n_t.trackingcats['missing-author-first-last-names'] if #missing_names > 0 and not string.find(opt_cat, name_cat, 1, true) then opt_cat = opt_cat .. name_cat - -- TODO: format and i18n this string - opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: Missing first/last names in Wikidata for ' .. table.concat(missing_names, ', ') .. ' ([[Template:Cite Q#Error messages|help]]) ' + opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: Missing first/last names in Wikidata for ' .. table.concat(missing_names, ', ') .. ' ' end -- change edition to ordinal if it's set and numeric @@ -880,8 +903,7 @@ local function _cite_q (citeq_args) citeq_args.ref = nil -- avoid CS1 maint: ref duplicates default else local tpara = frame:expandTemplate{ title = 'para', args = {'ref', citeq_args.ref} } - -- TODO: format and i18n this string - opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: supplied ' .. tpara .. ' does not match value generated from Wikidata: ' .. citeref .. ' ([[Template:Cite Q#Error messages|help]]) ' + opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: supplied ' .. tpara .. ' does not match value generated from Wikidata: ' .. citeref .. ' ' end end