diff --git a/module_citeq.lua b/module_citeq.lua index 9f392be..f3a51ed 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, link, maxpos, wdl, namestyle) +local function makelink(v, out, maxpos, wdl, namestyle) local label local item_lookup = false if v.mainsnak.snaktype == "value" then @@ -176,42 +176,22 @@ local function makelink(v, out, link, maxpos, wdl, namestyle) first_names = getStyledNames(first_names, namestyle) end - 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 + 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 - 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 + out[position] = { + label = label, + last = last_name or nil, + first = first_names or nil, + link = sitelink or nil, + qid = qnumber, + } end elseif v.mainsnak.datatype == "string" then local position = maxpos + 1 -- Default to 'next' author. @@ -231,23 +211,17 @@ local function makelink(v, out, link, maxpos, wdl, namestyle) first_names = getStyledNames(v.qualifiers.P9687[1].datavalue.value, namestyle) end - 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 + out[position] = { + label = v.mainsnak.datavalue.value, + last = last_name or nil, + first = first_names or nil, + } 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 @@ -257,14 +231,13 @@ local function makelink(v, out, link, 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 - if last_name and first_names then - label = { - label = label, - last = last_name or nil, - first = first_names or nil, - } - end + label = { + label = v.qualifiers.P1932[1].datavalue.value, -- "object named as" + last = last_name or nil, + first = first_names or nil, + } else + -- use anonymous label = { label = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper) .. (cfg.i18n_t.trackingcats["unknown-author"] or ""), qid = 'Q4233718', @@ -335,15 +308,13 @@ 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 names(s): - -- and table 'link' will store any links to the name's article + -- table 'out' is going to store the name label, qid, first/last names, and link 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, link, maxpos, wdl, args['name-list-style']) + maxpos = makelink(v, out, maxpos, wdl, args['name-list-style']) end end end @@ -351,7 +322,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, link, maxpos, wdl, args['name-list-style']) + maxpos = makelink(v, out, maxpos, wdl, args['name-list-style']) end end end @@ -366,35 +337,30 @@ 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 - if out[k].label then - label = out[k].label - else - label = out[k] - end + local label = out[k].label 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 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] + 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 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] = label + args[nl_type .. i] = out[k].label end - 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] + 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 end end end @@ -858,9 +824,13 @@ 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 and author.qid == 'Q4233718' then + if author.qid 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 @@ -868,8 +838,11 @@ 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 and editor.qid == 'Q4233718' then + if editor.qid 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 @@ -877,8 +850,11 @@ local function _cite_q (citeq_args) end for i, translator in pairs(names.translators or {}) do if not translator.last then - if translator.qid and translator.qid == 'Q4233718' then + if translator.qid 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 @@ -889,7 +865,8 @@ 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 - opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: Missing first/last names in Wikidata for ' .. table.concat(missing_names, ', ') .. ' ' + -- 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]]) ' end -- change edition to ordinal if it's set and numeric @@ -903,7 +880,8 @@ 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} } - opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: supplied ' .. tpara .. ' does not match value generated from Wikidata: ' .. citeref .. ' ' + -- 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]]) ' end end