Compare commits

..

No commits in common. "60a73e860803e9b0baf4bcae34dace4286ec28d9" and "b2ab54ccb4a2c86999fa4a6e3c081ce0cfb53509" have entirely different histories.

2 changed files with 16 additions and 67 deletions

View file

@ -9,9 +9,6 @@ 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 max_authors_displayed = 10 -- Don't look up all 500+ author items (is this in CS1 config somewhere?)
--------------------------------------------------------------------------------
-- makeOrdinal needs to be internationalised along with cfg.i18n_t
@ -84,11 +81,13 @@ local function accept_value( param_val, wd_val )
end
-- Split string of comma-separated first names into a table of initials
-- 2026-10-10: corrected for UTF-8 by [[User:Pengo]].
local function getInitials(str)
local initials = {}
for word in mw.ustring.gmatch(str, '[^%s%.]+') do
table.insert(initials, mw.ustring.upper(mw.ustring.sub(word, 1, 1)))
for _, word in pairs(mw.text.split(str, ' ', true)) do
local initial = mw.text.trim(word)
if #initial > 0 then
table.insert(initials, initial:sub(1, 1):upper())
end
end
return initials
end
@ -108,6 +107,7 @@ end
-- function to fetch a value to display
local function makelink(v, out, link, maxpos, wdl, namestyle)
local label
local max_authors_displayed = 10 -- TODO: this is probably in CS1 config somewhere
local item_lookup = false
if v.mainsnak.snaktype == "value" then
if v.mainsnak.datatype == "wikibase-item" then
@ -168,7 +168,6 @@ local function makelink(v, out, link, maxpos, wdl, namestyle)
label = label,
last = last_name or nil,
first = first_names or nil,
qid = qnumber or nil,
}
else
out[position] = label
@ -190,7 +189,6 @@ local function makelink(v, out, link, maxpos, wdl, namestyle)
label = label,
last = last_name or nil,
first = first_names or nil,
qid = qnumber or nil,
}
else
out[position] = label
@ -249,10 +247,7 @@ local function makelink(v, out, link, maxpos, wdl, namestyle)
}
end
else
label = {
label = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper) .. (cfg.i18n_t.trackingcats["unknown-author"] or ""),
qid = 'Q4233718',
}
label = mw.wikibase.getLabel("Q4233718"):gsub("^%l", mw.ustring.upper) .. (cfg.i18n_t.trackingcats["unknown-author"] or "")
end
maxpos = maxpos + 1
out[maxpos] = label
@ -267,13 +262,12 @@ arguments:
args - pointer to the parameter arguments table from the template call
qid - value from |qid= parameter; the Q-id of the source (book, etc.) in qid
wdl - value from the |wdl= parameter; a Boolean passed to enable links to Wikidata when no article exists
returns name data found in Wikidata (label, first, last, link, qid); modifies the args table
returns nothing; modifies the args table
]=]
local function get_name_list (nl_type, args, qid, wdl)
local propertyID
local fallbackID
local names = {}
if nl_type =="author" then
propertyID = 'P50' -- for authors
@ -349,7 +343,6 @@ local function get_name_list (nl_type, args, qid, wdl)
end
table.sort(keys) -- as they might be out of order
for i, k in ipairs(keys) do
names[i] = {}
local label
if out[k].label then
label = out[k].label
@ -357,32 +350,25 @@ local function get_name_list (nl_type, args, qid, wdl)
label = out[k]
end
label = label:gsub(''', '\''); -- prevent cs1|2 multiple names categorization; replace html entity with the actual character
names[i].label = label
names[i].qid = out[k].qid or nil
mw.log(i .. " " .. k .. " " .. label)
if args[nl_type .. i] then -- name gets overwritten
-- pull corresponding -link only if overwritten name is same as WD name
if link[k] and (args[nl_type .. i] == label) then
args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
names[i].link = link[k]
end
else -- name does not get overwritten, so pull name from WD
if out[k].first and out[k].last then
-- First/last names were found, so add them
args[nl_type .. '-last' .. i] = args[nl_type .. '-last' .. i] or out[k].last
args[nl_type .. '-first' .. i] = args[nl_type .. '-first' .. i] or out[k].first
names[i].last = out[k].last
names[i].first = out[k].first
else
args[nl_type .. i] = label
end
if link[k] then
args[nl_type .. '-link' .. i] = args[nl_type .. '-link' .. i] or link[k] -- author-linkn or editor-linkn
names[i].link = link[k]
end
end
end
return names
end
-- gets language codes used for a monolingual text property as a table
@ -778,7 +764,6 @@ local function _cite_q (citeq_args)
end
end
local names = {}
if is_set (qid) then
if not is_set (citeq_args.author) and not is_set (citeq_args.author1)
and not is_set (citeq_args.subject) and not is_set (citeq_args.subject1)
@ -787,19 +772,19 @@ local function _cite_q (citeq_args)
and not is_set (citeq_args.surname) and not is_set (citeq_args.surname1)
and not is_set (citeq_args['author-last']) and not is_set (citeq_args['author-last1']) and not is_set (citeq_args['author1-last'])
and not is_set (citeq_args['author-surname']) and not is_set (citeq_args['author-surname1']) and not is_set (citeq_args['author1-surname1']) then -- if neither are set, try to get authors from Wikidata
names.authors = get_name_list ('author', citeq_args, qid, wdl) -- modify citeq_args table with authors from Wikidata
get_name_list ('author', citeq_args, qid, wdl) -- modify citeq_args table with authors from Wikidata
end
if not is_set (citeq_args.editor) and not is_set (citeq_args.editor1)
and not is_set (citeq_args['editor-last']) and not is_set (citeq_args['editor-last1']) and not is_set (citeq_args['editor1-last'])
and not is_set (citeq_args['editor-surname']) and not is_set (citeq_args['editor-surname1']) and not is_set (citeq_args['editor1-surname']) then -- if neither are set, try to get editors from Wikidata
names.editors = get_name_list ('editor', citeq_args, qid, wdl) -- modify citeq_args table with editors from Wikidata
get_name_list ('editor', citeq_args, qid, wdl) -- modify citeq_args table with editors from Wikidata
end
if not is_set (citeq_args.translator) and not is_set (citeq_args.translator1)
and not is_set (citeq_args['translator-last']) and not is_set (citeq_args['translator-last1']) and not is_set (citeq_args['translator1-last'])
and not is_set (citeq_args['translator-surname']) and not is_set (citeq_args['translator-surname1']) and not is_set (citeq_args['translator1-surname']) then -- if neither are set, try to get translators from Wikidata
names.translators = get_name_list ('translator', citeq_args, qid, wdl) -- modify citeq_args table with translators from Wikidata
get_name_list ('translator', citeq_args, qid, wdl) -- modify citeq_args table with translators from Wikidata
end
end
@ -813,7 +798,7 @@ local function _cite_q (citeq_args)
local author_count = 0
for k, v in pairs(citeq_args) do
if k:find("^author%d+$") or k:find("^author%-last%d+$") then
if k:find("^author%d+$") then
author_count = author_count + 1
end
end
@ -827,7 +812,7 @@ local function _cite_q (citeq_args)
local editor_count = 0
for k, v in pairs(citeq_args) do
if k:find("^editor%d+$") or k:find("editor%-last%d+$") then
if k:find("^editor%d+$") then
editor_count = editor_count + 1
end
end
@ -839,43 +824,6 @@ local function _cite_q (citeq_args)
end
end
-- check only the names being displayed for missing first/last name errors
local missing_names = {}
for i, author in pairs(names.authors or {}) do
if not author.last and i <= (citeq_args['display-authors'] or author_count) then
if author.qid and author.qid == 'Q4233718' then
-- ignore anonymous
else
table.insert(missing_names, author.label)
end
end
end
for i, editor in pairs(names.editors or {}) do
if not editor.last and i <= (citeq_args['display-editors'] or editor_count) then
if editor.qid and editor.qid == 'Q4233718' then
-- ignore anonymous
else
table.insert(missing_names, editor.label)
end
end
end
for i, translator in pairs(names.translators or {}) do
if not translator.last then
if translator.qid and translator.qid == 'Q4233718' then
-- ignore anonymous
else
table.insert(missing_names, translator.label)
end
end
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
opt_cat = opt_cat .. ' <span class="error" style="font-size:1em"><code class="cs1-code">{{[[Template:Cite Q|Cite Q]]}}</code>: Missing first/last names in Wikidata for ' .. table.concat(missing_names, ', ') .. '</span> '
end
-- change edition to ordinal if it's set and numeric
citeq_args.edition = citeq_args.edition and makeOrdinal(citeq_args.edition)
@ -938,10 +886,12 @@ local function _cite_q (citeq_args)
citeq_args.id = id
end
local opt_cat = ''
-- Indicator if item has been retracted
local retract = ''
if citeq_args.retracted_by then
opt_cat = opt_cat .. cfg.i18n_t.trackingcats.retracted
opt_cat = cfg.i18n_t.trackingcats.retracted
local retract_id = string.gsub(citeq_args.retracted_by, 'Q', '')
local retr_params = {
citeq = 'yes',

View file

@ -32,7 +32,6 @@ local i18n_t = {
["replaced"] = "[[Category:Cite Q - cites a replaced work]]<!-- replaced -->",
["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]]",
["missing-author-first-last-names"] = "[[Category:Cite Q - authors with missing given and family names]]",
},
}