Module:Cite Q: Difference between revisions

Content deleted Content added
Prepare for "series ordinal" by introducing a "position" local variable.
Hack support for author name string.
Line 28:
local function get_name_list (nl_type, args, qid, wdl)
local propertyID = "P50"
local fallbackID = "P2093" -- author name string
if 'author' == nl_type then
propertyID = 'P50'; -- for authors
fallbackID = 'P2093';
elseif 'editor' == nl_type then
propertyID = 'P98'; -- for editors
fallbackID = nil;
else
return; -- not specified so return
Line 52 ⟶ 55:
end
local entity, props
local entity = mw.wikibase.getEntity(qid)
local entity, props = nil
local maxposfallback = 0nil
if entity and entity.claims then
props = entity.claims[propertyID]
if fallbackID then
else
-- fallback there's no such= entity or no .claims for the entity[fallbackID]
end
return nil
end
-- Make sure it actually has one of the propertyproperties requested
if not (props orand props[1]) and not props(fallback and fallback[1]) then
return nil
end
Line 71 ⟶ 75:
local out = {}
local link = {}
local maxpos = 0
if props[1].mainsnak.datavalue.type == "wikibase-entityid" then
if props and props[1] then
-- it's wiki-linked value, so output as link if possible
-- Linked authors / editors
local maxpos = 0
for k, v in pairs(props) do
local qnumber = "Q" .. v.mainsnak.datavalue.value["numeric-id"]
Line 119 ⟶ 123:
end
end
else
-- not a linkable article title
out[#out+1] = entity:formatPropertyValues(propertyID).value
end
if fallback and fallback[1] then
-- 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.
maxpos = math.max(maxpos, position)
if not out[position] then
out[position] = label
end
end
end
 
-- if there's anything to return, then insert the additions in the template arguments table
-- in the form |author1=firstname secondname |author2= ...