Handle supplied ref, avoid CS1 maint: ref duplicates default
This commit is contained in:
parent
60a73e8608
commit
f52af6b71b
1 changed files with 28 additions and 1 deletions
|
|
@ -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 .. ' <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> '
|
||||
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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue