Module:Citation
From Warwick Wiki
Powers {{citation}}.
local p = {}
local h = {}
function h.existsNotBlank(var)
return var and var ~= ""
end
function p.citation(frame)
local args = frame:getParent().args
local data = {}
data["authors"] = args["authors"] or ""
if data["authors"] == "" then
if h.existsNotBlank(args["author"]) or h.existsNotBlank(args["author1"]) then
data["authors"] = args["author"] or args["author1"]
elseif h.existsNotBlank(args["last"]) or h.existsNotBlank(args["last1"]) then
data["authors"] = args["last"] or args["last1"]
if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then
data["authors"] = data["authors"] .. ", " .. (args["first"] or args["first1"])
end
end
if h.existsNotBlank(args["author-link"]) or h.existsNotBlank(args["author-link1"]) then
data["authors"] = "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. data["authors"] .. "]]"
end
local finished = false
local i = 2
if not (h.existsNotBlank(args["author" .. toString(i)]) or h.existsNotBlank(args["last" .. toString(i)])) then
finished = true
end
while not finished do
local displayText = ""
if h.existsNotBlank(args["author" .. toString(i)]) then
displayText = displayText .. args["author" .. toString(i)]
elseif h.existsNotBlank(args["last" .. toString(i)]) then
displayText = displayText .. args["last" .. toString(i)]
if h.existsNotBlank(args["first" .. toString(i)]) then
displayText = displayText .. ", " .. args["first" .. toString(i)]
end
end
if h.existsNotBlank(args["author-link" .. toString(i)]) then
data["authors"] = data["authors"] .. "; [[" .. args["first" .. toString(i)] .. "|" .. displayText .. "]]"
else
data["authors"] = data["authors"] .. "; " .. displayText
end
i = i + 1
if not (h.existsNotBlank(args["author" .. toString(i)]) or h.existsNotBlank(args["last" .. toString(i)])) then
finished = true
end
end
end
data["title"] = args["title"] or "Error: title required"
data["work"] = args["work"] or args["part of"] or args["periodical"] or args["magazine"] or args["newspaper"] or ""
end