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 authors = args["authors"] or ""
if authors == "" then
if h.existsNotBlank(args["author"]) or h.existsNotBlank(args["author1"]) then
authors = args["author"] or args["author1"]
elseif h.existsNotBlank(args["last"]) or h.existsNotBlank(args["last1"]) then
authors = args["last"] or args["last1"]
if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then
authors = authors .. ", " .. (args["first"] or args["first1"])
end
end
if h.existsNotBlank(args["author-link"]) or h.existsNotBlank(args["author-link1"]) then
authors = "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. 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
authors = authors .. "; [[" .. args["first" .. toString(i)] .. "|" .. displayText .. "]]"
else
authors = 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
local editors = args["editors"] or ""
if editors == "" then
if h.existsNotBlank(args["editor"]) or h.existsNotBlank(args["editor1"]) then
editors = args["editor"] or args["editor1"]
elseif h.existsNotBlank(args["editor-last"]) or h.existsNotBlank(args["editor-last1"]) then
editors = args["editor-last"] or args["editor-last1"]
if h.existsNotBlank(args["editor-first"]) or h.existsNotBlank(args["editor-first1"]) then
editors = editors .. ", " .. (args["editor-first"] or args["editor-first1"])
end
end
if h.existsNotBlank(args["editor-link"]) or h.existsNotBlank(args["editor-link1"]) then
editors = "[[" .. (args["editor-link"] or args["editor-link1"]) .. "|" .. editors .. "]]"
end
local finished = false
local i = 2
if not (h.existsNotBlank(args["editor" .. toString(i)]) or h.existsNotBlank(args["last" .. toString(i)])) then
finished = true
end
while not finished do
local displayText = ""
if h.existsNotBlank(args["editor" .. toString(i)]) then
displayText = displayText .. args["editor" .. toString(i)]
elseif h.existsNotBlank(args["editor-last" .. toString(i)]) then
displayText = displayText .. args["editor-last" .. toString(i)]
if h.existsNotBlank(args["editor-first" .. toString(i)]) then
displayText = displayText .. ", " .. args["editor-first" .. toString(i)]
end
end
if h.existsNotBlank(args["editor-link" .. toString(i)]) then
editors = editors .. "; [[" .. args["editor-first" .. toString(i)] .. "|" .. displayText .. "]]"
else
editors = editors .. "; " .. displayText
end
i = i + 1
if not (h.existsNotBlank(args["editor" .. toString(i)]) or h.existsNotBlank(args["editor-last" .. toString(i)])) then
finished = true
end
end
end
local workAuthors = args["work-authors"] or ""
if workAuthors == "" then
if h.existsNotBlank(args["work-author"]) or h.existsNotBlank(args["work-author1"]) then
workAuthors = args["work-author"] or args["work-author1"]
elseif h.existsNotBlank(args["work-author-last"]) or h.existsNotBlank(args["work-author-last1"]) then
workAuthors = args["work-author-last"] or args["work-author-last1"]
if h.existsNotBlank(args["work-author-first"]) or h.existsNotBlank(args["work-author-first1"]) then
workAuthors = workAuthors .. ", " .. (args["work-author-first"] or args["work-author-first1"])
end
end
if h.existsNotBlank(args["work-author-link"]) or h.existsNotBlank(args["work-author-link1"]) then
workAuthors = "[[" .. (args["work-author-link"] or args["work-author-link1"]) .. "|" .. workAuthors .. "]]"
end
local finished = false
local i = 2
if not (h.existsNotBlank(args["work-author" .. toString(i)]) or h.existsNotBlank(args["work-author-last" .. toString(i)])) then
finished = true
end
while not finished do
local displayText = ""
if h.existsNotBlank(args["work-author" .. toString(i)]) then
displayText = displayText .. args["work-author" .. toString(i)]
elseif h.existsNotBlank(args["work-author-last" .. toString(i)]) then
displayText = displayText .. args["work-author-last" .. toString(i)]
if h.existsNotBlank(args["work-author-first" .. toString(i)]) then
displayText = displayText .. ", " .. args["work-author-first" .. toString(i)]
end
end
if h.existsNotBlank(args["work-author-link" .. toString(i)]) then
workAuthors = workAuthors .. "; [[" .. args["work-author-first" .. toString(i)] .. "|" .. displayText .. "]]"
else
workAuthors = workAuthors .. "; " .. displayText
end
i = i + 1
if not (h.existsNotBlank(args["work-author" .. toString(i)]) or h.existsNotBlank(args["work-author-last" .. toString(i)])) then
finished = true
end
end
end
local workDetails = args["work-details"] or ""
if workDetails == "" then
if h.existsNotBlank(args["volume"]) then
workDetails = ", <span title=\"volume\">vol.</span> " .. args["volume"]
end
if h.existsNotBlank(args["issue"]) then
workDetails = workDetails .. ", issue " .. args["issue"]
end
if h.existsNotBlank(args["edition"]) then
workDetails = workDetails .. " (" .. args["edition"] .. " <span title=\"edition\">ed.</span>)"
end
end
local title = args["title"] or "Error: title required"
local work = args["work"] or args["part of"] or args["periodical"] or args["magazine"] or args["newspaper"] or ""
local date = args["date"] or "undated"
local publisher = args["publisher"] or ""
local url = args["url"] or ""
local accessDate = args["access-date"] or ""
local archiveUrl = args["archive-url"] or ""
local archiveDate = args["archive-date"] or ""
local citation = title
if work == "" then
citation = citation .. workDetails
end
if authors ~= "" then
citation = citation .. " by " .. authors
if date ~= "" then
citation = citation .. " (" .. date .. ")"
end
if work == "" and editors ~= "" then
citation = citation .. ", <span title=\"editted\">ed.</span> by " .. editors
end
end
if work ~= "" then
citation = citation .. ", part of " .. work .. workDetails
if editors ~= "" then
citation = citation .. ", <span title=\"editted\">ed.</span> by " .. editors
end
end
end