Module:Citation: Difference between revisions

From Warwick Wiki
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local h = {}
local h = {}
function h.existsNotBlank(var)
return var and var ~= ""
end


function p.citation(frame)
function p.citation(frame)
Line 8: Line 12:
data["authors"] = args["authors"] or ""
data["authors"] = args["authors"] or ""
if data["authors"] == "" then
if data["authors"] == "" then
if args["author"] or args["author1"] then
if h.existsNotBlank(args["author"]) or h.existsNotBlank(args["author1"]) then
data["authors"] = args["author"] or args["author1"]
data["authors"] = args["author"] or args["author1"]
elseif args["last"] or args["last1"] then
elseif h.existsNotBlank(args["last"]) or h.existsNotBlank(args["last1"]) then
data["authors"] = args["last"] or args["last1"]
data["authors"] = args["last"] or args["last1"]
if args["first"] or args["first1"] then
if h.existsNotBlank(args["first"]) or h.existsNotBlank(args["first1"]) then
data["authors"] = data["authors"] .. ", " .. (args["first"] or args["first1"])
data["authors"] = data["authors"] .. ", " .. (args["first"] or args["first1"])
end
end
end
end
if args["author-link"] or 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"] .. "]]"
data["authors"] = "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. data["authors"] .. "]]"
end
end
Line 22: Line 26:
local finished = false
local finished = false
local i = 2
local i = 2
if not (args["author" .. toString(i)] or args["last" .. toString(i)]) then
if not (h.existsNotBlank(args["author" .. toString(i)]) or h.existsNotBlank(args["last" .. toString(i)])) then
finished = true
finished = true
end
end
while not finished do
while not finished do
local displayText = ""
local displayText = ""
if args["author" .. toString(i)] then
if h.existsNotBlank(args["author" .. toString(i)]) then
displayText = displayText .. args["author" .. toString(i)]
displayText = displayText .. args["author" .. toString(i)]
elseif args["last" .. toString(i)] then
elseif h.existsNotBlank(args["last" .. toString(i)]) then
displayText = displayText .. args["last" .. toString(i)]
displayText = displayText .. args["last" .. toString(i)]
if args["first" .. toString(i)] then
if h.existsNotBlank(args["first" .. toString(i)]) then
displayText = displayText .. ", " .. args["first" .. toString(i)]
displayText = displayText .. ", " .. args["first" .. toString(i)]
end
end
end
end
if args["author-link" .. toString(i)] then
if h.existsNotBlank(args["author-link" .. toString(i)]) then
data["authors"] = data["authors"] .. "; [[" .. args["first" .. toString(i)] .. "|" .. displayText .. "]]"
data["authors"] = data["authors"] .. "; [[" .. args["first" .. toString(i)] .. "|" .. displayText .. "]]"
else
else
Line 41: Line 45:
end
end
i = i + 1
i = i + 1
if not (args["author" .. toString(i)] or args["last" .. toString(i)]) then
if not (h.existsNotBlank(args["author" .. toString(i)]) or h.existsNotBlank(args["last" .. toString(i)])) then
finished = true
finished = true
end
end
end
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
end

Revision as of 14:45, 7 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 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