From f52af6b71b5022dd92703e01c551c4c091866149 Mon Sep 17 00:00:00 2001 From: Jonathan Harker Date: Thu, 15 Oct 2026 14:40:56 +1300 Subject: [PATCH] Handle supplied ref, avoid CS1 maint: ref duplicates default --- module_citeq.lua | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/module_citeq.lua b/module_citeq.lua index e527144..9f392be 100644 --- a/module_citeq.lua +++ b/module_citeq.lua @@ -105,6 +105,22 @@ local function getStyledNames(names, style) end end +-- Concatenate up to the first four names, and the year, into a CITEREF and return it +local function make_citeref(names, year) + local refs = {} + for i, v in ipairs(names) do + refs[i] = mw.text.trim(v.last) or mw.text.trim(v.label) or '' + if i == 4 then break end + end + table.insert(refs, year) + local id = table.concat(refs) or '' + if id == '' then + return '' + else + return "CITEREF" .. id + end +end + -- function to fetch a value to display local function makelink(v, out, link, maxpos, wdl, namestyle) local label @@ -879,9 +895,20 @@ local function _cite_q (citeq_args) -- change edition to ordinal if it's set and numeric citeq_args.edition = citeq_args.edition and makeOrdinal(citeq_args.edition) + -- handle supplied {{para|ref}} for readable ID, avoid CS1 duplicate default error + local pubyear = yearFromDate(citeq_args['publication-date']) + if citeq_args.ref then + local citeref = make_citeref(names.authors or names.editors, pubyear) + if citeq_args.ref == citeref then + 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 .. ' ' + end + end + -- code to make a guess what template to use from the supplied parameters -- (first draft for proof-of-concept) - local pubyear = yearFromDate(citeq_args['publication-date']) local guessedType = getTemplateFromInstance(qid, citeq_args) if guessedType == 'news' then template = template or "news"