Refactor tracking categories to a set-like table, separate from error output
This commit is contained in:
parent
0dfb7e26e1
commit
a12122b03f
1 changed files with 24 additions and 14 deletions
|
|
@ -9,7 +9,8 @@ local cite_cfg = mw.loadData ('Module:Cite/config')
|
|||
local cfg = mw.loadData ('Module:Cite_Q/config')
|
||||
local cs1_module = 'Module:Citation/CS1' -- don't load the module yet, may not be needed
|
||||
local cs1_cfg = mw.loadData('Module:Citation/CS1/Configuration')
|
||||
local opt_cat = ''
|
||||
local opt_cat = {}
|
||||
local cq_errors = ''
|
||||
local max_authors_displayed = 10 -- Don't look up all 500+ author items (is this in CS1 config somewhere?)
|
||||
|
||||
|
||||
|
|
@ -59,6 +60,14 @@ local function in_array( needle, haystack )
|
|||
return false
|
||||
end
|
||||
|
||||
--[[--------------------------< T A B L E S E T _ A D D >------------------------------------------------------
|
||||
Add needle to the haystack if it's not already there.
|
||||
]]
|
||||
local function tableset_add(haystack, needle)
|
||||
if needle == nil or in_array(needle, haystack) then return false end
|
||||
table.insert(haystack, needle)
|
||||
return true
|
||||
end
|
||||
|
||||
--[[--------------------------< A C C E P T _ V A L U E >-------------------------------------------------------
|
||||
Accept WD value by framing in ((...)) if param_val is equal to keyword; else pass-through WD value as is.
|
||||
|
|
@ -252,8 +261,9 @@ local function makelink(v, out, maxpos, wdl, namestyle)
|
|||
}
|
||||
else
|
||||
-- use anonymous
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats["unknown-author"])
|
||||
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),
|
||||
qid = 'Q4233718',
|
||||
}
|
||||
end
|
||||
|
|
@ -886,11 +896,10 @@ local function _cite_q (citeq_args)
|
|||
end
|
||||
|
||||
-- add category and display error if name errors found
|
||||
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
|
||||
opt_cat = opt_cat .. name_cat
|
||||
if #missing_names > 0 and not in_array('missing-author-first-last-names', opt_cat) then
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats['missing-author-first-last-names'])
|
||||
-- TODO: format and i18n this string
|
||||
opt_cat = opt_cat .. ' <span class="error" style="font-size:inherit"><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> '
|
||||
cq_errors = cq_errors .. ' <span class="error" style="font-size:inherit"><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
|
||||
|
||||
-- change edition to ordinal if it's set and numeric
|
||||
|
|
@ -913,7 +922,7 @@ local function _cite_q (citeq_args)
|
|||
else
|
||||
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:inherit"><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> '
|
||||
cq_errors = cq_errors .. ' <span class="error" style="font-size:inherit"><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
|
||||
|
||||
|
|
@ -978,7 +987,7 @@ local function _cite_q (citeq_args)
|
|||
-- Indicator if item has been retracted
|
||||
local retract = ''
|
||||
if citeq_args.retracted_by then
|
||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.retracted
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats.retracted)
|
||||
local retract_id = string.gsub(citeq_args.retracted_by, 'Q', '')
|
||||
local retr_params = {
|
||||
citeq = 'yes',
|
||||
|
|
@ -1033,7 +1042,7 @@ local function _cite_q (citeq_args)
|
|||
-- Indicator if item has corrigendum/erratum
|
||||
local erratumid = ""
|
||||
if citeq_args.erratum then
|
||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.erratum
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats.erratum)
|
||||
local erratum_params = {
|
||||
citeq = 'yes',
|
||||
id = frame:expandTemplate{
|
||||
|
|
@ -1059,7 +1068,7 @@ local function _cite_q (citeq_args)
|
|||
-- Indicator if item has an expression of concern notice (P14891)
|
||||
local eoc = ""
|
||||
if citeq_args['expression-of-concern'] then
|
||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats['expression-of-concern']
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats['expression-of-concern'])
|
||||
local eoc_params = {
|
||||
citeq = 'yes',
|
||||
id = frame:expandTemplate{
|
||||
|
|
@ -1083,11 +1092,11 @@ local function _cite_q (citeq_args)
|
|||
citeq_args['eoc-intentional'] = nil
|
||||
|
||||
if citeq_args.replaced_by then
|
||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.replaced
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats.replaced)
|
||||
citeq_args.replaced_by = nil
|
||||
end
|
||||
if not citeq_args.title then -- emit category link if missing title
|
||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats['no-label-or-title'];
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats['no-label-or-title'])
|
||||
end
|
||||
|
||||
-- Disable CiteSeerX IDs for now
|
||||
|
|
@ -1108,9 +1117,10 @@ local function _cite_q (citeq_args)
|
|||
else
|
||||
output = frame:expandTemplate{ -- render the template
|
||||
title = "Cite "..template, args = citeq_args
|
||||
} .. cfg.i18n_t.trackingcats["unknown-template"]
|
||||
}
|
||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats["unknown-template"])
|
||||
end
|
||||
return output .. erratumid .. eoc .. retract .. opt_cat
|
||||
return output .. erratumid .. eoc .. retract .. table.concat(opt_cat, ' ') .. cq_errors
|
||||
end
|
||||
|
||||
local function cite_q (frame)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue