Compare commits

..

No commits in common. "2929b048361bdac1a0c38cd6e30fa247b99726e1" and "f52af6b71b5022dd92703e01c551c4c091866149" have entirely different histories.

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, maxpos, wdl, namestyle) local function makelink(v, out, link, 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,22 +176,42 @@ local function makelink(v, out, maxpos, wdl, namestyle)
first_names = getStyledNames(first_names, namestyle) first_names = getStyledNames(first_names, namestyle)
end end
if wdl then if sitelink then
-- show that there's a Wikidata entry available -- just the plain name,
out[position] = string.format( -- but keep a record of the links, using the same index
"[[:d:Q%s|%s]]&nbsp;<span title='%s'>[[File:Wikidata-logo.svg|16px|alt=|link=]]</span>", if last_name and first_names then
v.mainsnak.datavalue.value["numeric-id"], out[position] = {
label, label = label,
cfg.i18n_t["errors"]["local-article-not-found"] last = last_name or nil,
) first = first_names or nil,
qid = qnumber or nil,
}
else
out[position] = label
end
link[position] = sitelink
else else
out[position] = { if wdl then
label = label, -- show that there's a Wikidata entry available
last = last_name or nil, out[position] = string.format(
first = first_names or nil, "[[:d:Q%s|%s]]&nbsp;<span title='%s'>[[File:Wikidata-logo.svg|16px|alt=|link=]]</span>",
link = sitelink or nil, v.mainsnak.datavalue.value["numeric-id"],
qid = qnumber, 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 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.
@ -211,17 +231,23 @@ local function makelink(v, out, 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
out[position] = { if last_name and first_names then
label = v.mainsnak.datavalue.value, out[position] = {
last = last_name or nil, label = v.mainsnak.datavalue.value,
first = first_names or nil, last = last_name 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
@ -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 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
label = { if last_name and first_names then
label = v.qualifiers.P1932[1].datavalue.value, -- "object named as" label = {
last = last_name or nil, label = label,
first = first_names or nil, last = last_name 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',
@ -308,13 +335,15 @@ 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 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 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, maxpos, wdl, args['name-list-style']) maxpos = makelink(v, out, link, maxpos, wdl, args['name-list-style'])
end end
end end
end end
@ -322,7 +351,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, maxpos, wdl, args['name-list-style']) maxpos = makelink(v, out, link, maxpos, wdl, args['name-list-style'])
end end
end 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 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 = out[k].label local 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 out[k].link and (args[nl_type .. i] == label) then if link[k] 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 args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
names[i].link = out[k].link names[i].link = link[k]
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] = out[k].label args[nl_type .. i] = label
end end
if out[k].link then if link[k] then
args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or out[k].link -- author-linkn or editor-linkn args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
names[i].link = out[k].link names[i].link = link[k]
end end
end 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 -- 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 then if author.qid and author.qid == 'Q4233718' 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
@ -838,11 +868,8 @@ 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 then if editor.qid and editor.qid == 'Q4233718' 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
@ -850,11 +877,8 @@ 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 then if translator.qid and translator.qid == 'Q4233718' 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
@ -865,8 +889,7 @@ 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
-- 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, ', ') .. '</span> '
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
@ -880,8 +903,7 @@ 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} }
-- 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 .. '</span></span> '
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