Compare commits
9 commits
d2e75d6e21
...
f057618b52
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f057618b52 | ||
|
|
b45a3cba82 | ||
|
|
31303f54ab | ||
|
|
756321f787 | ||
|
|
ca015c4f68 | ||
|
|
4724cd3c55 | ||
| dc7f9358db | |||
| a12122b03f | |||
| 0dfb7e26e1 |
2 changed files with 74 additions and 46 deletions
118
module_citeq.lua
118
module_citeq.lua
|
|
@ -6,10 +6,11 @@ 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?)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,6 +60,14 @@ 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.
|
||||||
|
|
@ -105,21 +114,23 @@ local function getStyledNames(names, style)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Concatenate up to the first four names, and the year, into a CITEREF and return it
|
-- 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
|
||||||
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 or ''
|
local name = v.last or v.label;
|
||||||
refs[i] = mw.text.trim(name)
|
if not name then break end; -- no v.last or v.label? abandon the ipairs() loop
|
||||||
if i == 4 then break end
|
refs[i] = mw.text.trim (name);
|
||||||
|
if i == 4 then break end -- collect only four names
|
||||||
end
|
end
|
||||||
table.insert(refs, year)
|
|
||||||
local id = table.concat(refs) or ''
|
if 0 < #refs then -- don't add <year> when there are no names in <refs>; CITEREFYYYY is more-or-less meaningless
|
||||||
if id == '' then
|
table.insert (refs, year); -- add <year>
|
||||||
return ''
|
table.insert (refs, 1, 'CITEREF'); -- and insert the 'CITEREF' prefix
|
||||||
else
|
return table.concat (refs); -- concatenate and done
|
||||||
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
|
||||||
|
|
@ -192,7 +203,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|alt=|link=]]</span>",
|
"[[:d:Q%s|%s]] <span title='%s'>[[File:Wikidata-logo.svg|16px|class=noviewer|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"]
|
||||||
|
|
@ -252,8 +263,9 @@ 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) .. (cfg.i18n_t.trackingcats["unknown-author"] or ""),
|
label = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper),
|
||||||
qid = 'Q4233718',
|
qid = 'Q4233718',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -853,7 +865,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, author.label .. " <span title='edit author in Wikidata'>[[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. author.qid .. "]] ]]</span>")
|
table.insert(missing_names, string.format (cfg.i18n_t.errors.missing_name, author.label, 'author', author.qid));
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(missing_names, author.label)
|
table.insert(missing_names, author.label)
|
||||||
|
|
@ -865,7 +877,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, editor.label .. " <span title='edit editor in Wikidata'>[[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. editor.qid .. "]] ]]</span>")
|
table.insert(missing_names, string.format (cfg.i18n_t.errors.missing_name, editor.label, 'editor', editor.qid));
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(missing_names, editor.label)
|
table.insert(missing_names, editor.label)
|
||||||
|
|
@ -877,7 +889,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, translator.label .. " <span title='edit translator in Wikidata'>[[File:Edit icon on Wikisite.svg|14px|alt=|link=[[:d:" .. translator.qid .. "]] ]]</span>")
|
table.insert(missing_names, string.format (cfg.i18n_t.errors.missing_name, translator.label, 'translator', translator.qid));
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(missing_names, translator.label)
|
table.insert(missing_names, translator.label)
|
||||||
|
|
@ -886,11 +898,10 @@ 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
|
||||||
local name_cat = cfg.i18n_t.trackingcats['missing-author-first-last-names']
|
if #missing_names > 0 and not in_array('missing-author-first-last-names', opt_cat) then
|
||||||
if #missing_names > 0 and not string.find(opt_cat, name_cat, 1, true) then
|
tableset_add(opt_cat, cfg.i18n_t.trackingcats['missing-author-first-last-names'])
|
||||||
opt_cat = opt_cat .. name_cat
|
|
||||||
-- TODO: format and i18n this string
|
-- 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
|
end
|
||||||
|
|
||||||
-- change edition to ordinal if it's set and numeric
|
-- change edition to ordinal if it's set and numeric
|
||||||
|
|
@ -901,13 +912,20 @@ 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 citeref = make_citeref(names.authors or names.editors, pubyear)
|
local refnames
|
||||||
if citeq_args.ref == citeref then
|
if #names.authors > 0 then
|
||||||
citeq_args.ref = nil -- avoid CS1 maint: ref duplicates default
|
refnames = names.authors
|
||||||
else
|
elseif #names.editors > 0 then
|
||||||
|
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
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -961,7 +979,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|alt=|link=]]' -- possibly replace by WD edit icon?
|
id = id .. '[[File:Wikidata-logo.svg|16px|class=noviewer|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
|
||||||
|
|
@ -972,7 +990,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
|
||||||
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 retract_id = string.gsub(citeq_args.retracted_by, 'Q', '')
|
||||||
local retr_params = {
|
local retr_params = {
|
||||||
citeq = 'yes',
|
citeq = 'yes',
|
||||||
|
|
@ -993,18 +1011,31 @@ 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
|
|
||||||
citeq_args['retracted-intentional'] = nil
|
|
||||||
|
|
||||||
-- clean up any blank parameters
|
citeq_args.retracted_by = nil -- remove non-CS1 parameters
|
||||||
|
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
|
||||||
|
|
||||||
for k, v in pairs(citeq_args) do
|
for k, v in pairs(citeq_args) do
|
||||||
if v == "" then citeq_args[k] = nil end
|
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 [[<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
|
||||||
|
|
@ -1027,7 +1058,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
|
||||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.erratum
|
tableset_add(opt_cat, cfg.i18n_t.trackingcats.erratum)
|
||||||
local erratum_params = {
|
local erratum_params = {
|
||||||
citeq = 'yes',
|
citeq = 'yes',
|
||||||
id = frame:expandTemplate{
|
id = frame:expandTemplate{
|
||||||
|
|
@ -1053,7 +1084,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
|
||||||
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 = {
|
local eoc_params = {
|
||||||
citeq = 'yes',
|
citeq = 'yes',
|
||||||
id = frame:expandTemplate{
|
id = frame:expandTemplate{
|
||||||
|
|
@ -1077,22 +1108,16 @@ 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
|
||||||
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.replaced
|
tableset_add(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
|
||||||
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
|
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
|
||||||
|
|
@ -1102,9 +1127,10 @@ 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 .. opt_cat
|
return output .. erratumid .. eoc .. retract .. table.concat(opt_cat, ' ') .. cq_errors
|
||||||
end
|
end
|
||||||
|
|
||||||
local function cite_q (frame)
|
local function cite_q (frame)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ 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",
|
||||||
|
|
@ -33,6 +34,7 @@ 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