Module:Cite Q: Difference between revisions

Content deleted Content added
Hack support for author name string.
Support series ordinal qualifier
Line 45:
if wdl and (#wdl > 0) then
wdl = wdl:lower()
ifwdl = (wdl == "false") or (wdl == "no") or (wdl == "0") then
wdl = false
else
wdl = true
end
else
-- wdl is empty, so
Line 65 ⟶ 61:
end
-- Make sure it actually has at least one of the properties requested
if not (props and props[1]) and not (fallback and fallback[1]) then
return nil
Line 77 ⟶ 73:
local maxpos = 0
if props and props[1] then
-- Linked authors / editors
for k, v in pairs(props) do
local qnumber = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
Line 88 ⟶ 83:
end
local position = maxpos + 1 -- Default to 'next' author.
-- todo: use P1545 (series ordinal) instead of default position.
if v["qualifiers"] and v.qualifiers["P1545"] and v.qualifiers["P1545"][1] then
position = tonumber(v.qualifiers["P1545"][1].datavalue.value)
end
maxpos = math.max(maxpos, position)
if sitelink then
Line 125 ⟶ 123:
end
if fallback and fallback[1] then
-- NameFallback to name-only authors / editors
for k, v in pairs(fallback) do
local label = v.mainsnak.datavalue["value"]
local position = maxpos + 1 -- Default to 'next' author.
-- todo: use P1545 (series ordinal) instead of default position.
if v["qualifiers"] and v.qualifiers["P1545"] and v.qualifiers["P1545"][1] then
position = tonumber(v.qualifiers["P1545"][1].datavalue.value)
end
maxpos = math.max(maxpos, position)
if not out[position] then -- prefer the linked author above
out[position] = label
end
Line 139 ⟶ 140:
-- if there's anything to return, then insert the additions in the template arguments table
-- in the form |author1=firstname secondname |author2= ...
-- Renumber, in case we have inconsistent numbering
if #out > 0 then
local keys = {}
for k,v in ipairs(out) do -- authorn or editorn
for k,v in pairs(out) do
args[nl_type .. k] = v
keys[#keys+1] = k
end
end
for k,v in pairs(link) do -- author-linkn or editor-linkn
table.sort(keys) -- as they might be out of order
args[nl_type .. '-link' .. k] = v
for i, k in ipairs(keys) do
mw.log(i.." "..k.." "..out[k])
args[nl_type .. i] = out[k] -- author-n or editor-n
if #out > 0link[k] then
for args[nl_type k,v.. in pairs('-link)' do .. i] = link[k] -- author-linkn or editor-linkn
end
end