Compare commits

..

3 commits

View file

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