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 "<span class=\"cite-error\">Error: title required</span>"
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 publicationDate = args["publication-date"] or ""
local url = args["url"] or ""
local accessDate = args["access-date"] or ""
local archiveUrl = args["archive-url"] or ""
local archiveDate = args["archive-date"] or "<span class=\"cite-error\">Error: please provide an archive-date alongside the archive-url</span>"
local archiveCentre = args["archive-centre"] or ""
local archiveCollection = args["archive-collection"] or ""
local archiveRef = args["archive-ref"] or ""
local archiveRefUrl = args["archive-ref-url"] or ""
local titleItal = "''"
if args["title-ital"] == "no" or (work ~= "" and args["title-ital"] ~= "yes") then
titleItal = ""
end
local titleQuotes = ""
if args["title-quotes"] == "yes" or (work ~= "" and args["title-quotes"] ~= "no") then
titleQuotes = "\""
end
if publisher == "" and publicationDate ~= "" then
date = date .. ", published " .. publicationDate
end
if url ~= "" then
if archiveUrl ~= "" then
title = "[" .. archiveUrl .. " " .. title .. "]"
else
title = "[" .. url .. " " .. title .. "]"
end
end
local citation = titleQuotes .. titleItal .. title .. titleItal .. titleQuotes
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 .. ", edited by " .. editors
end
elseif work == "" and editors ~= "" then
citation = citation .. " edited by " .. editors
if date ~= "" then
citation = citation .. " (" .. date .. ")"
end
elseif date ~= "" then
citation = citation .. " (" .. date .. ")"
end
if work ~= "" then
citation = citation .. ", part of " .. work .. workDetails
if editors ~= "" then
citation = citation .. ", edited by " .. editors
end
end
if publisher ~= "" then
citation = citation .. ", published by " .. publisher
if publicationDate ~= "" then
citation = citation .. " (" .. publicationDate .. ")"
end
end
if archiveUrl ~= "" then
citation = citation .. ", archived from [" .. url .. " the original] on " .. archiveDate
end
if accessDate ~= "" then
citation = citation .. ", accessed on " .. accessDate
end
if archiveCentre ~= "" or archiveCollection ~= "" then
citation = citation .. ", available "
if archiveCollection ~= "" then
citation = citation .. "in the " .. archiveCollection
if archiveCentre ~= "" then
citation = citation .. ", " .. archiveCentre
end
elseif archiveCentre ~= "" then
citation = citation .. "at the " .. archiveCentre
end
if archiveRef ~= "" then
citation = citation .. ", "
if archiveRefUrl ~= "" then
citation = citation .. "[" .. archiveRefUrl .. " "
end
citation = citation .. archiveRef
if archiveRefUrl ~= "" then
citation = citation .. "]"
end
end
end
citation = citation .. "."
return citation
end
return p