Module:Citation: Difference between revisions

From Warwick Wiki
No edit summary
No edit summary
Line 8: Line 8:
function p.citation(frame)
function p.citation(frame)
local args = frame:getParent().args
local args = frame:getParent().args
local data = {}
data["authors"] = args["authors"] or ""
local authors = args["authors"] or ""
if data["authors"] == "" then
if authors == "" then
if h.existsNotBlank(args["author"]) or h.existsNotBlank(args["author1"]) then
if h.existsNotBlank(args["author"]) or h.existsNotBlank(args["author1"]) then
data["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
data["authors"] = args["last"] or args["last1"]
authors = args["last"] or args["last1"]
if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then
if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then
data["authors"] = data["authors"] .. ", " .. (args["first"] or args["first1"])
authors = authors .. ", " .. (args["first"] or args["first1"])
end
end
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
data["authors"] = "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. data["authors"] .. "]]"
authors = "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. authors .. "]]"
end
end
Line 40: Line 39:
end
end
if h.existsNotBlank(args["author-link" .. toString(i)]) then
if h.existsNotBlank(args["author-link" .. toString(i)]) then
data["authors"] = data["authors"] .. "; [[" .. args["first" .. toString(i)] .. "|" .. displayText .. "]]"
authors = authors .. "; [[" .. args["first" .. toString(i)] .. "|" .. displayText .. "]]"
else
else
data["authors"] = data["authors"] .. "; " .. displayText
authors = authors .. "; " .. displayText
end
end
i = i + 1
i = i + 1
Line 51: Line 50:
end
end
data["title"] = args["title"] or "Error: title required"
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
data["work"] = args["work"] or args["part of"] or args["periodical"] or args["magazine"] or args["newspaper"] or ""
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 ""
end
end

Revision as of 18:30, 11 July 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
			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 ""
end