remove all non-cs1 parameters in one place before rendering any output

This commit is contained in:
Trappist the monk 2026-10-26 03:19:00 +13:00 • committed by Jonathan Harker
parent dc7f9358db
commit 4724cd3c55

View file

@ -114,21 +114,23 @@ local function getStyledNames(names, style)
end end
end end
-- Concatenate up to the first four names, and the year, into a CITEREF and return it -- Concatenate up to the first four names (at least one name required), and the year (optional), into a CITEREF and return it; return nil else
local function make_citeref(names, year) local function make_citeref(names, year)
local refs = {} local refs = {}
for i, v in ipairs(names) do for i, v in ipairs(names) do
local name = v.last or v.label or '' local name = v.last or v.label;
refs[i] = mw.text.trim(name) if not name then break end; -- no v.last or v.label? abandon the ipairs() loop
if i == 4 then break end refs[i] = mw.text.trim (name);
if i == 4 then break end -- collect only four names
end end
table.insert(refs, year)
local id = table.concat(refs) or '' if 0 < #refs then -- don't add <year> when there are no names in <refs>; CITEREFYYYY is more-or-less meaningless
if id == '' then table.insert (refs, year); -- add <year>
return '' table.insert (refs, 1, 'CITEREF'); -- and insert the 'CITEREF' prefix
else return table.concat (refs); -- concatenate and done
return "CITEREF" .. id
end end
return; -- no names so return nil
end end
-- function to fetch a value to display -- function to fetch a value to display
@ -913,13 +915,13 @@ local function _cite_q (citeq_args)
local refnames local refnames
if #names.authors > 0 then if #names.authors > 0 then
refnames = names.authors refnames = names.authors
else elseif #names.editors > 0 then
refnames = names.editors refnames = names.editors
end end
local citeref = make_citeref(refnames, pubyear) local citeref = refnames and make_citeref (refnames, pubyear) or nil; -- <refnames> nil when no authors and no editors
if citeq_args.ref == citeref then if citeq_args.ref == citeref then -- CITEREF from wikidata authors / editors matches the value provided in |ref=
citeq_args.ref = nil -- avoid CS1 maint: ref duplicates default citeq_args.ref = nil -- unset to avoid CS1 maint: ref duplicates default maintenance message / category
else elseif citeref then -- CITEREF from wikidata authors / editors is different from the value provided in |ref=
tableset_add(opt_cat, cfg.i18n_t.trackingcats['supplied-ref']) tableset_add(opt_cat, cfg.i18n_t.trackingcats['supplied-ref'])
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 -- TODO: format and i18n this string
@ -1009,9 +1011,13 @@ local function _cite_q (citeq_args)
end end
retract = ' ' .. frame:expandTemplate{ title = "Retracted", args = retr_params } retract = ' ' .. frame:expandTemplate{ title = "Retracted", args = retr_params }
end end
-- remove non-CS1 retraction properties
citeq_args.retracted_by = nil citeq_args.retracted_by = nil -- remove non-CS1 parameters
citeq_args['retracted-intentional'] = nil citeq_args['retracted-intentional'] = nil
citeq_args['instance-of'] = nil
if citeq_args['name-list-style'] and citeq_args['name-list-style'] == 'apa' then
citeq_args['name-list-style'] = nil
end
-- clean up any blank parameters -- clean up any blank parameters
for k, v in pairs(citeq_args) do for k, v in pairs(citeq_args) do
@ -1103,12 +1109,6 @@ local function _cite_q (citeq_args)
-- Disable CiteSeerX IDs for now -- Disable CiteSeerX IDs for now
citeq_args.citeseerx = nil citeq_args.citeseerx = nil
-- remove any remaining non-CS1 fields
citeq_args['instance-of'] = nil
if citeq_args['name-list-style'] and citeq_args['name-list-style'] == 'apa' then
citeq_args['name-list-style'] = nil
end
-- render the template -- render the template
local lc_template = template and template:lower() or "citation" local lc_template = template and template:lower() or "citation"
local output local output