Compare commits
No commits in common. "f057618b52b1ca59bef94a5768a4e4a4172e6f03" and "d2e75d6e21f52a84229c8f2db18a17a8406a31a0" have entirely different histories.
f057618b52
...
d2e75d6e21
2 changed files with 45 additions and 73 deletions
116
module_citeq.lua
116
module_citeq.lua
|
|
@ -6,11 +6,10 @@ local _getPropOfProp = wdib._getPropOfProp
|
||||||
local followQid = wdib._followQid
|
local followQid = wdib._followQid
|
||||||
--local getPropertyIDs = wdib._getPropertyIDs
|
--local getPropertyIDs = wdib._getPropertyIDs
|
||||||
local cite_cfg = mw.loadData ('Module:Cite/config')
|
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_module = 'Module:Citation/CS1' -- don't load the module yet, may not be needed
|
||||||
local cs1_cfg = mw.loadData('Module:Citation/CS1/Configuration')
|
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?)
|
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
|
return false
|
||||||
end
|
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 >-------------------------------------------------------
|
--[[--------------------------< 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.
|
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
|
||||||
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 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;
|
local name = v.last or v.label or ''
|
||||||
if not name then break end; -- no v.last or v.label? abandon the ipairs() loop
|
refs[i] = mw.text.trim(name)
|
||||||
refs[i] = mw.text.trim (name);
|
if i == 4 then break end
|
||||||
if i == 4 then break end -- collect only four names
|
|
||||||
end
|
end
|
||||||
|
table.insert(refs, year)
|
||||||
if 0 < #refs then -- don't add <year> when there are no names in <refs>; CITEREFYYYY is more-or-less meaningless
|
local id = table.concat(refs) or ''
|
||||||
table.insert (refs, year); -- add <year>
|
if id == '' then
|
||||||
table.insert (refs, 1, 'CITEREF'); -- and insert the 'CITEREF' prefix
|
return ''
|
||||||
return table.concat (refs); -- concatenate and done
|
else
|
||||||
|
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
|
||||||
|
|
@ -203,7 +192,7 @@ local function makelink(v, out, maxpos, wdl, namestyle)
|
||||||
if wdl then
|
if wdl then
|
||||||
-- show that there's a Wikidata entry available
|
-- show that there's a Wikidata entry available
|
||||||
out[position] = string.format(
|
out[position] = string.format(
|
||||||
"[[:d:Q%s|%s]] <span title='%s'>[[File:Wikidata-logo.svg|16px|class=noviewer|alt=|link=]]</span>",
|
"[[:d:Q%s|%s]] <span title='%s'>[[File:Wikidata-logo.svg|16px|alt=|link=]]</span>",
|
||||||
v.mainsnak.datavalue.value["numeric-id"],
|
v.mainsnak.datavalue.value["numeric-id"],
|
||||||
label,
|
label,
|
||||||
cfg.i18n_t["errors"]["local-article-not-found"]
|
cfg.i18n_t["errors"]["local-article-not-found"]
|
||||||
|
|
@ -263,9 +252,8 @@ local function makelink(v, out, maxpos, wdl, namestyle)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
-- use anonymous
|
-- use anonymous
|
||||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats["unknown-author"])
|
|
||||||
label = {
|
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',
|
qid = 'Q4233718',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -865,7 +853,7 @@ local function _cite_q (citeq_args)
|
||||||
if author.qid then
|
if author.qid then
|
||||||
-- ignore anonymous or non-humans
|
-- ignore anonymous or non-humans
|
||||||
if author.human then
|
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 .. " <span title='edit author in Wikidata'>[[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. author.qid .. "]] ]]</span>")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(missing_names, author.label)
|
table.insert(missing_names, author.label)
|
||||||
|
|
@ -877,7 +865,7 @@ local function _cite_q (citeq_args)
|
||||||
if editor.qid then
|
if editor.qid then
|
||||||
-- ignore anonymous or non-humans
|
-- ignore anonymous or non-humans
|
||||||
if editor.human then
|
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 .. " <span title='edit editor in Wikidata'>[[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. editor.qid .. "]] ]]</span>")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(missing_names, editor.label)
|
table.insert(missing_names, editor.label)
|
||||||
|
|
@ -889,7 +877,7 @@ local function _cite_q (citeq_args)
|
||||||
if translator.qid then
|
if translator.qid then
|
||||||
-- ignore anonymous or non-humans
|
-- ignore anonymous or non-humans
|
||||||
if translator.human then
|
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 .. " <span title='edit translator in Wikidata'>[[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. translator.qid .. "]] ]]</span>")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(missing_names, translator.label)
|
table.insert(missing_names, translator.label)
|
||||||
|
|
@ -898,10 +886,11 @@ local function _cite_q (citeq_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- add category and display error if name errors found
|
-- 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
|
local name_cat = cfg.i18n_t.trackingcats['missing-author-first-last-names']
|
||||||
tableset_add(opt_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
|
-- TODO: format and i18n this string
|
||||||
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> '
|
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> '
|
||||||
end
|
end
|
||||||
|
|
||||||
-- change edition to ordinal if it's set and numeric
|
-- 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.authors_overridden or (#names.authors == 0 and names.editors_overridden) then
|
||||||
-- if names are supplied manually, then don't mess with supplied ref parameter
|
-- if names are supplied manually, then don't mess with supplied ref parameter
|
||||||
elseif citeq_args.ref and 'none' ~= citeq_args.ref then
|
elseif citeq_args.ref and 'none' ~= citeq_args.ref then
|
||||||
local refnames
|
local citeref = make_citeref(names.authors or names.editors, pubyear)
|
||||||
if #names.authors > 0 then
|
if citeq_args.ref == citeref then
|
||||||
refnames = names.authors
|
citeq_args.ref = nil -- avoid CS1 maint: ref duplicates default
|
||||||
elseif #names.editors > 0 then
|
else
|
||||||
refnames = names.editors
|
|
||||||
end
|
|
||||||
local citeref = refnames and make_citeref (refnames, pubyear) or nil; -- <refnames> 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 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
|
||||||
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> '
|
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> '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -979,7 +961,7 @@ local function _cite_q (citeq_args)
|
||||||
local id = cfg.i18n_t.wdq.. ' [[:d:' .. qid .. '|' .. qid .. ']]'
|
local id = cfg.i18n_t.wdq.. ' [[:d:' .. qid .. '|' .. qid .. ']]'
|
||||||
local old_id = citeq_args.id
|
local old_id = citeq_args.id
|
||||||
if wdl then -- show WD logo
|
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
|
end
|
||||||
if is_set (old_id) then
|
if is_set (old_id) then
|
||||||
citeq_args.id = old_id .. list_sep .. id -- append to user-specified contents
|
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
|
-- Indicator if item has been retracted
|
||||||
local retract = ''
|
local retract = ''
|
||||||
if citeq_args.retracted_by then
|
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 retract_id = string.gsub(citeq_args.retracted_by, 'Q', '')
|
||||||
local retr_params = {
|
local retr_params = {
|
||||||
citeq = 'yes',
|
citeq = 'yes',
|
||||||
|
|
@ -1011,31 +993,18 @@ 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 -- remove non-CS1 parameters
|
citeq_args.retracted_by = nil
|
||||||
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
|
||||||
for k, v in pairs(citeq_args) do
|
for k, v in pairs(citeq_args) do
|
||||||
if v == "" then
|
if v == "" then citeq_args[k] = nil end
|
||||||
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 [[<link>|<label>]] wikilinks where <link> and <label> are identical
|
|
||||||
v, changed = v:gsub (pattern, '[[%1]]'); -- where <link> and <label> are identical, rewrite all such [[<link>|<label>]] wikilinks in <v> using [[<link>]]
|
|
||||||
|
|
||||||
if changed then -- when changes have been made
|
|
||||||
citeq_args[k] = v; -- update <citeq_args[k]>
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if |expand=<anything>, write a nowiki'd version to see what the {{citation}} template call looks like
|
-- if |expand=<anything>, write a nowiki'd version to see what the {{citation}} template call looks like
|
||||||
if expand then
|
if expand then
|
||||||
|
|
||||||
local expand_args = { "{{" .. (template and ("Cite "..template) or "Citation") } -- init with citation template
|
local expand_args = { "{{" .. (template and ("Cite "..template) or "Citation") } -- init with citation template
|
||||||
if expand == "self" then
|
if expand == "self" then
|
||||||
citeq_args.id = old_id -- restore original |id= parameter
|
citeq_args.id = old_id -- restore original |id= parameter
|
||||||
|
|
@ -1058,7 +1027,7 @@ local function _cite_q (citeq_args)
|
||||||
-- Indicator if item has corrigendum/erratum
|
-- Indicator if item has corrigendum/erratum
|
||||||
local erratumid = ""
|
local erratumid = ""
|
||||||
if citeq_args.erratum then
|
if citeq_args.erratum then
|
||||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats.erratum)
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.erratum
|
||||||
local erratum_params = {
|
local erratum_params = {
|
||||||
citeq = 'yes',
|
citeq = 'yes',
|
||||||
id = frame:expandTemplate{
|
id = frame:expandTemplate{
|
||||||
|
|
@ -1084,7 +1053,7 @@ local function _cite_q (citeq_args)
|
||||||
-- Indicator if item has an expression of concern notice (P14891)
|
-- Indicator if item has an expression of concern notice (P14891)
|
||||||
local eoc = ""
|
local eoc = ""
|
||||||
if citeq_args['expression-of-concern'] then
|
if citeq_args['expression-of-concern'] then
|
||||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats['expression-of-concern'])
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats['expression-of-concern']
|
||||||
local eoc_params = {
|
local eoc_params = {
|
||||||
citeq = 'yes',
|
citeq = 'yes',
|
||||||
id = frame:expandTemplate{
|
id = frame:expandTemplate{
|
||||||
|
|
@ -1108,16 +1077,22 @@ local function _cite_q (citeq_args)
|
||||||
citeq_args['eoc-intentional'] = nil
|
citeq_args['eoc-intentional'] = nil
|
||||||
|
|
||||||
if citeq_args.replaced_by then
|
if citeq_args.replaced_by then
|
||||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats.replaced)
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.replaced
|
||||||
citeq_args.replaced_by = nil
|
citeq_args.replaced_by = nil
|
||||||
end
|
end
|
||||||
if not citeq_args.title then -- emit category link if missing title
|
if not citeq_args.title then -- emit category link if missing title
|
||||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats['no-label-or-title'])
|
opt_cat = opt_cat .. cfg.i18n_t.trackingcats['no-label-or-title'];
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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
|
||||||
|
|
@ -1127,10 +1102,9 @@ local function _cite_q (citeq_args)
|
||||||
else
|
else
|
||||||
output = frame:expandTemplate{ -- render the template
|
output = frame:expandTemplate{ -- render the template
|
||||||
title = "Cite "..template, args = citeq_args
|
title = "Cite "..template, args = citeq_args
|
||||||
}
|
} .. cfg.i18n_t.trackingcats["unknown-template"]
|
||||||
tableset_add(opt_cat, cfg.i18n_t.trackingcats["unknown-template"])
|
|
||||||
end
|
end
|
||||||
return output .. erratumid .. eoc .. retract .. table.concat(opt_cat, ' ') .. cq_errors
|
return output .. erratumid .. eoc .. retract .. opt_cat
|
||||||
end
|
end
|
||||||
|
|
||||||
local function cite_q (frame)
|
local function cite_q (frame)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ local i18n_t = {
|
||||||
["errors"] = {
|
["errors"] = {
|
||||||
["local-article-not-found"] = "Local article not found.",
|
["local-article-not-found"] = "Local article not found.",
|
||||||
["no-label-or-title"] = "No label or title -- debug: ",
|
["no-label-or-title"] = "No label or title -- debug: ",
|
||||||
missing_name = '%s <span title="edit %s in Wikidata">[[File:Edit icon on Wikisite.svg|14px|class=noviewer|alt=|link=[[:d:%s]] ]]</span>'; -- %s: <name>.label, '<name>', <name>.qid
|
|
||||||
},
|
},
|
||||||
["months"] = {
|
["months"] = {
|
||||||
"January", "February", "March", "April", "May", "June",
|
"January", "February", "March", "April", "May", "June",
|
||||||
|
|
@ -34,7 +33,6 @@ local i18n_t = {
|
||||||
["unknown-author"] = "", -- [[Category:Cite Q - author unknown]] removed as misplaced; someone is welcome to restore it if it is placed outside of the template parameter value
|
["unknown-author"] = "", -- [[Category:Cite Q - author unknown]] removed as misplaced; someone is welcome to restore it if it is placed outside of the template parameter value
|
||||||
["unknown-template"] = "[[Category:Cite Q - template unknown]]",
|
["unknown-template"] = "[[Category:Cite Q - template unknown]]",
|
||||||
["missing-author-first-last-names"] = "[[Category:Cite Q - authors with missing given and family names]]",
|
["missing-author-first-last-names"] = "[[Category:Cite Q - authors with missing given and family names]]",
|
||||||
["supplied-ref"] = "[[Category:Cite Q - supplied citeref does not match]]",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue