diff --git a/module_citeq.lua b/module_citeq.lua index e08d61e..6bfb259 100644 --- a/module_citeq.lua +++ b/module_citeq.lua @@ -6,11 +6,10 @@ local _getPropOfProp = wdib._getPropOfProp local followQid = wdib._followQid --local getPropertyIDs = wdib._getPropertyIDs local cite_cfg = mw.loadData ('Module:Cite/config') -local cfg = mw.loadData ('Module:Cite Q/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 cq_errors = '' +local opt_cat = '' local max_authors_displayed = 10 -- Don't look up all 500+ author items (is this in CS1 config somewhere?) @@ -60,14 +59,6 @@ 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. @@ -114,23 +105,21 @@ local function getStyledNames(names, style) end end --- 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 +-- 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 - local name = v.last or v.label; - if not name then break end; -- no v.last or v.label? abandon the ipairs() loop - refs[i] = mw.text.trim (name); - if i == 4 then break end -- collect only four names + local name = v.last or v.label or '' + refs[i] = mw.text.trim(name) + if i == 4 then break end end - - if 0 < #refs then -- don't add when there are no names in ; CITEREFYYYY is more-or-less meaningless - table.insert (refs, year); -- add - table.insert (refs, 1, 'CITEREF'); -- and insert the 'CITEREF' prefix - return table.concat (refs); -- concatenate and done + table.insert(refs, year) + local id = table.concat(refs) or '' + if id == '' then + return '' + else + return "CITEREF" .. id end - - return; -- no names so return nil end -- function to fetch a value to display @@ -203,7 +192,7 @@ local function makelink(v, out, maxpos, wdl, namestyle) if wdl then -- show that there's a Wikidata entry available out[position] = string.format( - "[[:d:Q%s|%s]] [[File:Wikidata-logo.svg|16px|class=noviewer|alt=|link=]]", + "[[:d:Q%s|%s]] [[File:Wikidata-logo.svg|16px|alt=|link=]]", v.mainsnak.datavalue.value["numeric-id"], label, cfg.i18n_t["errors"]["local-article-not-found"] @@ -263,9 +252,8 @@ 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), + label = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper) .. (cfg.i18n_t.trackingcats["unknown-author"] or ""), qid = 'Q4233718', } end @@ -865,7 +853,7 @@ local function _cite_q (citeq_args) if author.qid then -- ignore anonymous or non-humans if author.human then - table.insert(missing_names, string.format (cfg.i18n_t.errors.missing_name, author.label, 'author', author.qid)); + table.insert(missing_names, author.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. author.qid .. "]] ]]") end else table.insert(missing_names, author.label) @@ -877,7 +865,7 @@ local function _cite_q (citeq_args) if editor.qid then -- ignore anonymous or non-humans if editor.human then - table.insert(missing_names, string.format (cfg.i18n_t.errors.missing_name, editor.label, 'editor', editor.qid)); + table.insert(missing_names, editor.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. editor.qid .. "]] ]]") end else table.insert(missing_names, editor.label) @@ -889,7 +877,7 @@ local function _cite_q (citeq_args) if translator.qid then -- ignore anonymous or non-humans if translator.human then - table.insert(missing_names, string.format (cfg.i18n_t.errors.missing_name, translator.label, 'translator', translator.qid)); + table.insert(missing_names, translator.label .. " [[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. translator.qid .. "]] ]]") end else table.insert(missing_names, translator.label) @@ -898,10 +886,11 @@ local function _cite_q (citeq_args) end -- add category and display error if name errors found - 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']) + 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 -- TODO: format and i18n this string - cq_errors = cq_errors .. ' {{[[Template:Cite Q|Cite Q]]}}: Missing first/last names in Wikidata for ' .. table.concat(missing_names, ', ') .. ' ([[Template:Cite Q#Error messages|help]]) ' + opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: Missing first/last names in Wikidata for ' .. table.concat(missing_names, ', ') .. ' ([[Template:Cite Q#Error messages|help]]) ' end -- change edition to ordinal if it's set and numeric @@ -912,20 +901,13 @@ local function _cite_q (citeq_args) if names.authors_overridden or (#names.authors == 0 and names.editors_overridden) then -- if names are supplied manually, then don't mess with supplied ref parameter elseif citeq_args.ref and 'none' ~= citeq_args.ref then - local refnames - if #names.authors > 0 then - refnames = names.authors - elseif #names.editors > 0 then - refnames = names.editors - end - local citeref = refnames and make_citeref (refnames, pubyear) or nil; -- nil when no authors and no editors - if citeq_args.ref == citeref then -- CITEREF from wikidata authors / editors matches the value provided in |ref= - citeq_args.ref = nil -- unset to avoid CS1 maint: ref duplicates default maintenance message / category - 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']) + 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} } -- TODO: format and i18n this string - cq_errors = cq_errors .. ' {{[[Template:Cite Q|Cite Q]]}}: supplied ' .. tpara .. ' does not match value generated from Wikidata: ' .. citeref .. ' ([[Template:Cite Q#Error messages|help]]) ' + opt_cat = opt_cat .. ' {{[[Template:Cite Q|Cite Q]]}}: supplied ' .. tpara .. ' does not match value generated from Wikidata: ' .. citeref .. ' ([[Template:Cite Q#Error messages|help]]) ' end end @@ -979,7 +961,7 @@ local function _cite_q (citeq_args) local id = cfg.i18n_t.wdq.. ' [[:d:' .. qid .. '|' .. qid .. ']]' local old_id = citeq_args.id if wdl then -- show WD logo - id = id .. '[[File:Wikidata-logo.svg|16px|class=noviewer|alt=|link=]]' -- possibly replace by WD edit icon? + id = id .. '[[File:Wikidata-logo.svg|16px|alt=|link=]]' -- possibly replace by WD edit icon? end if is_set (old_id) then citeq_args.id = old_id .. list_sep .. id -- append to user-specified contents @@ -990,7 +972,7 @@ local function _cite_q (citeq_args) -- Indicator if item has been retracted local retract = '' if citeq_args.retracted_by then - tableset_add(opt_cat, cfg.i18n_t.trackingcats.retracted) + opt_cat = opt_cat .. cfg.i18n_t.trackingcats.retracted local retract_id = string.gsub(citeq_args.retracted_by, 'Q', '') local retr_params = { citeq = 'yes', @@ -1011,31 +993,18 @@ local function _cite_q (citeq_args) end retract = ' ' .. frame:expandTemplate{ title = "Retracted", args = retr_params } end - - citeq_args.retracted_by = nil -- remove non-CS1 parameters + -- remove non-CS1 retraction properties + citeq_args.retracted_by = 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 for k, v in pairs(citeq_args) do - if v == "" then - citeq_args[k] = nil; -- remove blank parameters - - elseif 'string' == type (v) then -- here when not blank; must be a string; |pmid= and the like are type 'number' - local changed; -- flag is a number when changes have been made; nil else - local pattern = '%[%[([^|]+)|%1%]%]'; -- pattern that looks for [[|