Module:Citation: Difference between revisions
From Warwick Wiki
No edit summary |
No edit summary |
||
(18 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
authors = args["author"] or args["author1"] | authors = args["author"] or args["author1"] | ||
elseif h.existsNotBlank(args["last"]) or h.existsNotBlank(args["last1"]) then | elseif h.existsNotBlank(args["last"]) or h.existsNotBlank(args["last1"]) then | ||
if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then | if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then | ||
authors = authors | authors = authors .. (args["first"] or args["first1"]) .. " " | ||
end | end | ||
authors = authors .. (args["last"] or args["last1"]) | |||
end | end | ||
if h.existsNotBlank(args["author-link"]) or h.existsNotBlank(args["author-link1"]) then | if h.existsNotBlank(args["author-link"]) or h.existsNotBlank(args["author-link1"]) then | ||
Line 26: | Line 26: | ||
local i = 2 | local i = 2 | ||
if not (h.existsNotBlank(args["author" .. tostring(i)]) or h.existsNotBlank(args["last" .. tostring(i)])) then | if not (h.existsNotBlank(args["author" .. tostring(i)]) or h.existsNotBlank(args["last" .. tostring(i)])) then | ||
finished = true | |||
end | end | ||
while not finished do | while not finished do | ||
Line 33: | Line 33: | ||
displayText = displayText .. args["author" .. tostring(i)] | displayText = displayText .. args["author" .. tostring(i)] | ||
elseif h.existsNotBlank(args["last" .. tostring(i)]) then | elseif h.existsNotBlank(args["last" .. tostring(i)]) then | ||
if h.existsNotBlank(args["first" .. tostring(i)]) then | if h.existsNotBlank(args["first" .. tostring(i)]) then | ||
displayText = displayText | displayText = displayText .. args["first" .. tostring(i)] .. " " | ||
end | end | ||
displayText = displayText .. args["last" .. tostring(i)] | |||
end | end | ||
if h.existsNotBlank(args["author-link" .. tostring(i)]) then | if h.existsNotBlank(args["author-link" .. tostring(i)]) then | ||
authors = authors .. " | authors = authors .. ", [[" .. args["first" .. tostring(i)] .. "|" .. displayText .. "]]" | ||
else | else | ||
authors = authors .. " | authors = authors .. ", " .. displayText | ||
end | end | ||
i = i + 1 | i = i + 1 | ||
Line 55: | Line 55: | ||
editors = args["editor"] or args["editor1"] | editors = args["editor"] or args["editor1"] | ||
elseif h.existsNotBlank(args["editor-last"]) or h.existsNotBlank(args["editor-last1"]) then | elseif h.existsNotBlank(args["editor-last"]) or h.existsNotBlank(args["editor-last1"]) then | ||
if h.existsNotBlank(args["editor-first"]) or h.existsNotBlank(args["editor-first1"]) then | if h.existsNotBlank(args["editor-first"]) or h.existsNotBlank(args["editor-first1"]) then | ||
editors = editors | editors = editors .. (args["editor-first"] or args["editor-first1"]) .. " " | ||
end | end | ||
editors = editors .. (args["editor-last"] or args["editor-last1"]) | |||
end | end | ||
if h.existsNotBlank(args["editor-link"]) or h.existsNotBlank(args["editor-link1"]) then | if h.existsNotBlank(args["editor-link"]) or h.existsNotBlank(args["editor-link1"]) then | ||
Line 67: | Line 67: | ||
local i = 2 | local i = 2 | ||
if not (h.existsNotBlank(args["editor" .. tostring(i)]) or h.existsNotBlank(args["last" .. tostring(i)])) then | if not (h.existsNotBlank(args["editor" .. tostring(i)]) or h.existsNotBlank(args["last" .. tostring(i)])) then | ||
finished = true | |||
end | end | ||
while not finished do | while not finished do | ||
Line 74: | Line 74: | ||
displayText = displayText .. args["editor" .. tostring(i)] | displayText = displayText .. args["editor" .. tostring(i)] | ||
elseif h.existsNotBlank(args["editor-last" .. tostring(i)]) then | elseif h.existsNotBlank(args["editor-last" .. tostring(i)]) then | ||
if h.existsNotBlank(args["editor-first" .. tostring(i)]) then | if h.existsNotBlank(args["editor-first" .. tostring(i)]) then | ||
displayText = displayText | displayText = displayText .. args["editor-first" .. tostring(i)] .. " " | ||
end | end | ||
displayText = displayText .. args["editor-last" .. tostring(i)] | |||
end | end | ||
if h.existsNotBlank(args["editor-link" .. tostring(i)]) then | if h.existsNotBlank(args["editor-link" .. tostring(i)]) then | ||
editors = editors .. " | editors = editors .. ", [[" .. args["editor-first" .. tostring(i)] .. "|" .. displayText .. "]]" | ||
else | else | ||
editors = editors .. " | editors = editors .. ", " .. displayText | ||
end | end | ||
i = i + 1 | i = i + 1 | ||
Line 96: | Line 96: | ||
workAuthors = args["work-author"] or args["work-author1"] | workAuthors = args["work-author"] or args["work-author1"] | ||
elseif h.existsNotBlank(args["work-author-last"]) or h.existsNotBlank(args["work-author-last1"]) then | elseif h.existsNotBlank(args["work-author-last"]) or h.existsNotBlank(args["work-author-last1"]) then | ||
if h.existsNotBlank(args["work-author-first"]) or h.existsNotBlank(args["work-author-first1"]) then | if h.existsNotBlank(args["work-author-first"]) or h.existsNotBlank(args["work-author-first1"]) then | ||
workAuthors = workAuthors | workAuthors = workAuthors .. (args["work-author-first"] or args["work-author-first1"]) .. " " | ||
end | end | ||
workAuthors = workAuthors .. (args["work-author-last"] or args["work-author-last1"]) | |||
end | end | ||
if h.existsNotBlank(args["work-author-link"]) or h.existsNotBlank(args["work-author-link1"]) then | if h.existsNotBlank(args["work-author-link"]) or h.existsNotBlank(args["work-author-link1"]) then | ||
Line 115: | Line 115: | ||
displayText = displayText .. args["work-author" .. tostring(i)] | displayText = displayText .. args["work-author" .. tostring(i)] | ||
elseif h.existsNotBlank(args["work-author-last" .. tostring(i)]) then | elseif h.existsNotBlank(args["work-author-last" .. tostring(i)]) then | ||
if h.existsNotBlank(args["work-author-first" .. tostring(i)]) then | if h.existsNotBlank(args["work-author-first" .. tostring(i)]) then | ||
displayText = displayText | displayText = displayText .. args["work-author-first" .. tostring(i)] .. " " | ||
end | end | ||
displayText = displayText .. args["work-author-last" .. tostring(i)] | |||
end | end | ||
if h.existsNotBlank(args["work-author-link" .. tostring(i)]) then | if h.existsNotBlank(args["work-author-link" .. tostring(i)]) then | ||
workAuthors = workAuthors .. " | workAuthors = workAuthors .. ", [[" .. args["work-author-first" .. tostring(i)] .. "|" .. displayText .. "]]" | ||
else | else | ||
workAuthors = workAuthors .. " | workAuthors = workAuthors .. ", " .. displayText | ||
end | end | ||
i = i + 1 | i = i + 1 | ||
Line 149: | Line 149: | ||
local date = args["date"] or "undated" | local date = args["date"] or "undated" | ||
local publisher = args["publisher"] or "" | local publisher = args["publisher"] or "" | ||
local via = args["via"] or args["website-name"] or "" | |||
local publicationDate = args["publication-date"] or "" | local publicationDate = args["publication-date"] or "" | ||
local url = args["url"] or "" | local url = args["url"] or "" | ||
local login = args["login"] or "" | |||
local accessDate = args["access-date"] or "" | local accessDate = args["access-date"] or "" | ||
local archiveUrl = args["archive-url"] or "" | local archiveUrl = args["archive-url"] or "" | ||
Line 159: | Line 161: | ||
local archiveRefUrl = args["archive-ref-url"] or "" | local archiveRefUrl = args["archive-ref-url"] or "" | ||
local isbn = args["isbn"] or "" | local isbn = args["isbn"] or "" | ||
local pages = args["page"] or args["pages"] or "" | |||
local titleItal = "''" | local titleItal = "''" | ||
if args["title-ital"] == "no" or (work ~= "" and args["title-ital"] ~= "yes") then | if args["title-ital"] == "no" or ((work ~= "" or via ~= "") and args["title-ital"] ~= "yes") then | ||
titleItal = "" | titleItal = "" | ||
end | end | ||
local titleQuotes = "" | local titleQuotes = "" | ||
if args["title-quotes"] == "yes" or (work ~= "" and args["title-quotes"] ~= "no") then | if args["title-quotes"] == "yes" or ((work ~= "" or via ~= "") and args["title-quotes"] ~= "no") then | ||
titleQuotes = "\"" | titleQuotes = "\"" | ||
end | |||
local workItal = "''" | |||
if args["work-ital"] == "no" then | |||
workItal = "" | |||
end | |||
local workQuotes = "" | |||
if args["work-quotes"] == "yes" then | |||
workQuotes = "\"" | |||
end | end | ||
Line 174: | Line 185: | ||
end | end | ||
if url ~= "" then | local titleLink = false | ||
if string.find(title, "%[%[.+%]%]") ~= nil then | |||
titleLink = true | |||
end | |||
if url ~= "" and not titleLink then | |||
if archiveUrl ~= "" then | if archiveUrl ~= "" then | ||
title = "[" .. archiveUrl .. " " .. title .. "]" | title = "[" .. archiveUrl .. " " .. title .. "]" | ||
Line 183: | Line 199: | ||
local citation = titleQuotes .. titleItal .. title .. titleItal .. titleQuotes | local citation = titleQuotes .. titleItal .. title .. titleItal .. titleQuotes | ||
if url ~= "" then | |||
if titleLink then | |||
if archiveUrl ~= "" then | |||
citation = citation .. " ([" .. archiveUrl .. " link]" | |||
else | |||
citation = citation .. " ([" .. url .. " link]" | |||
end | |||
if login ~= "" then | |||
citation = citation .. " ," .. login .. " login required)" | |||
else | |||
citation = citation .. ")" | |||
end | |||
elseif login ~= "" then | |||
citation = citation .. " (" .. login .. " login required)" | |||
end | |||
end | |||
if work == "" then | if work == "" then | ||
citation = citation .. workDetails | citation = citation .. workDetails | ||
Line 195: | Line 227: | ||
end | end | ||
elseif work == "" and editors ~= "" then | elseif work == "" and editors ~= "" then | ||
citation = citation .. " edited by " .. editors | citation = citation .. ", edited by " .. editors | ||
if date ~= "" then | if date ~= "" then | ||
citation = citation .. " (" .. date .. ")" | citation = citation .. " (" .. date .. ")" | ||
Line 201: | Line 233: | ||
elseif date ~= "" then | elseif date ~= "" then | ||
citation = citation .. " (" .. date .. ")" | citation = citation .. " (" .. date .. ")" | ||
end | |||
if publisher == "" and via ~= "" then | |||
citation = citation .. " via " .. via | |||
end | end | ||
if work ~= "" then | if work ~= "" then | ||
citation = citation .. ", part of " .. work .. workDetails | citation = citation .. ", part of " .. workQuotes .. workItal .. work .. workItal .. workQuotes .. workDetails | ||
if workAuthors ~= "" then | |||
citation = citation .. " by " .. workAuthors | |||
end | |||
if editors ~= "" then | if editors ~= "" then | ||
citation = citation .. ", edited by " .. editors | citation = citation .. ", edited by " .. editors | ||
end | |||
if pages ~= "" then | |||
if string.find(pages, "-") or string.find(pages, ",") or string.find(pages, "&") or string.find(pages, "and") then | |||
citation = citation .. ", pages " | |||
else | |||
citation = citation .. ", page " | |||
end | |||
citation = citation .. pages | |||
end | end | ||
end | end | ||
if publisher ~= "" then | if publisher ~= "" then | ||
citation = citation .. ", published by " .. publisher | citation = citation .. ", published by " .. publisher | ||
if via ~= "" then | |||
citation = citation .. " via " .. via | |||
end | |||
if publicationDate ~= "" then | if publicationDate ~= "" then | ||
citation = citation .. " (" .. publicationDate .. ")" | citation = citation .. " (" .. publicationDate .. ")" | ||
Line 242: | Line 291: | ||
end | end | ||
if isbn ~= "" then | if isbn ~= "" then | ||
citation = citation .. " | citation = citation .. ", [[Special:BookSources/" .. isbn .. "|ISBN " .. isbn .. "]]" | ||
end | |||
if work == "" and pages ~= "" then | |||
if string.find(pages, "-") or string.find(pages, ",") or string.find(pages, "&") or string.find(pages, "and") then | |||
citation = citation .. ". Pages " | |||
else | |||
citation = citation .. ". Page " | |||
end | |||
citation = citation .. pages | |||
end | end | ||
Latest revision as of 20:38, 23 August 2025
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
if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then
authors = authors .. (args["first"] or args["first1"]) .. " "
end
authors = authors .. (args["last"] or args["last1"])
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
if h.existsNotBlank(args["first" .. tostring(i)]) then
displayText = displayText .. args["first" .. tostring(i)] .. " "
end
displayText = displayText .. args["last" .. tostring(i)]
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
if h.existsNotBlank(args["editor-first"]) or h.existsNotBlank(args["editor-first1"]) then
editors = editors .. (args["editor-first"] or args["editor-first1"]) .. " "
end
editors = editors .. (args["editor-last"] or args["editor-last1"])
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
if h.existsNotBlank(args["editor-first" .. tostring(i)]) then
displayText = displayText .. args["editor-first" .. tostring(i)] .. " "
end
displayText = displayText .. args["editor-last" .. tostring(i)]
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
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
workAuthors = workAuthors .. (args["work-author-last"] or args["work-author-last1"])
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
if h.existsNotBlank(args["work-author-first" .. tostring(i)]) then
displayText = displayText .. args["work-author-first" .. tostring(i)] .. " "
end
displayText = displayText .. args["work-author-last" .. tostring(i)]
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 via = args["via"] or args["website-name"] or ""
local publicationDate = args["publication-date"] or ""
local url = args["url"] or ""
local login = args["login"] 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 isbn = args["isbn"] or ""
local pages = args["page"] or args["pages"] or ""
local titleItal = "''"
if args["title-ital"] == "no" or ((work ~= "" or via ~= "") and args["title-ital"] ~= "yes") then
titleItal = ""
end
local titleQuotes = ""
if args["title-quotes"] == "yes" or ((work ~= "" or via ~= "") and args["title-quotes"] ~= "no") then
titleQuotes = "\""
end
local workItal = "''"
if args["work-ital"] == "no" then
workItal = ""
end
local workQuotes = ""
if args["work-quotes"] == "yes" then
workQuotes = "\""
end
if publisher == "" and publicationDate ~= "" then
date = date .. ", published " .. publicationDate
end
local titleLink = false
if string.find(title, "%[%[.+%]%]") ~= nil then
titleLink = true
end
if url ~= "" and not titleLink then
if archiveUrl ~= "" then
title = "[" .. archiveUrl .. " " .. title .. "]"
else
title = "[" .. url .. " " .. title .. "]"
end
end
local citation = titleQuotes .. titleItal .. title .. titleItal .. titleQuotes
if url ~= "" then
if titleLink then
if archiveUrl ~= "" then
citation = citation .. " ([" .. archiveUrl .. " link]"
else
citation = citation .. " ([" .. url .. " link]"
end
if login ~= "" then
citation = citation .. " ," .. login .. " login required)"
else
citation = citation .. ")"
end
elseif login ~= "" then
citation = citation .. " (" .. login .. " login required)"
end
end
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 publisher == "" and via ~= "" then
citation = citation .. " via " .. via
end
if work ~= "" then
citation = citation .. ", part of " .. workQuotes .. workItal .. work .. workItal .. workQuotes .. workDetails
if workAuthors ~= "" then
citation = citation .. " by " .. workAuthors
end
if editors ~= "" then
citation = citation .. ", edited by " .. editors
end
if pages ~= "" then
if string.find(pages, "-") or string.find(pages, ",") or string.find(pages, "&") or string.find(pages, "and") then
citation = citation .. ", pages "
else
citation = citation .. ", page "
end
citation = citation .. pages
end
end
if publisher ~= "" then
citation = citation .. ", published by " .. publisher
if via ~= "" then
citation = citation .. " via " .. via
end
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
if isbn ~= "" then
citation = citation .. ", [[Special:BookSources/" .. isbn .. "|ISBN " .. isbn .. "]]"
end
if work == "" and pages ~= "" then
if string.find(pages, "-") or string.find(pages, ",") or string.find(pages, "&") or string.find(pages, "and") then
citation = citation .. ". Pages "
else
citation = citation .. ". Page "
end
citation = citation .. pages
end
citation = citation .. "."
return citation
end
return p