Module:Citation: Difference between revisions

From Warwick Wiki
Created page with "local p = {} local h = {} function p.citation(frame) local args = frame:getParent().args local data = {} data["authors"] = args["authors"] or "" if data["authors"] == "" then local finished = false local i = 1 while not finished do if i == 1 then local displayText = "" if args["author"] or args["author1"] then displayText = displayText .. (args["author"] or args["author1"]) elseif args["last"] or args["last1"] then displayText = disp..."
 
No edit summary
Line 8: Line 8:
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
data["authors"] = args["author"] or args["author1"]
elseif args["last"] or args["last1"] then
data["authors"] = args["last"] or args["last1"]
if args["first"] or args["first1"] then
data["authors"] = data["authors"] .. ", " .. (args["first"] or args["first1"])
end
end
if args["author-link"] or args["author-link1"] then
data["authors"] = "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. data["authors"] .. "]]"
end
local finished = false
local finished = false
local i = 1
local i = 2
if not (args["author" .. toString(i)] or args["last" .. toString(i)]) then
finished = true
end
while not finished do
while not finished do
if i == 1 then
local displayText = ""
local displayText = ""
if args["author" .. toString(i)] then
if args["author"] or args["author1"] then
displayText = displayText .. args["author" .. toString(i)]
displayText = displayText .. (args["author"] or args["author1"])
elseif args["last" .. toString(i)] then
elseif args["last"] or args["last1"] then
displayText = displayText .. args["last" .. toString(i)]
displayText = displayText .. (args["last"] or args["last1"])
if args["first" .. toString(i)] then
if args["first"] or args["first1"] then
displayText = displayText .. ", " .. args["first" .. toString(i)]
displayText = displayText .. ", " .. (args["first"] or args["first1"])
end
end
if args["author-link"] or args["author-link1"] then
data["authors"] = data["authors"] .. "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. displayText .. "]]"
else
data["authors"] = displayText
end
end
end
if args["author-link" .. toString(i)] then
data["authors"] = data["authors"] .. "; [[" .. args["first" .. toString(i)] .. "|" .. displayText .. "]]"
else
else
--tba, mostly same logic
data["authors"] = data["authors"] .. "; " .. displayText
end
i = i + 1
if not (args["author" .. toString(i)] or args["last" .. toString(i)]) then
finished = true
end
end
end
end
end
end
end
end

Revision as of 20:20, 6 July 2025

Powers {{citation}}.


local p = {}
local h = {}

function p.citation(frame)
	local args = frame:getParent().args
	local data = {}
	
	data["authors"] = args["authors"] or ""
	if data["authors"] == "" then
		if args["author"] or args["author1"] then
			data["authors"] = args["author"] or args["author1"]
		elseif args["last"] or args["last1"] then
			data["authors"] = args["last"] or args["last1"]
			if args["first"] or args["first1"] then
				data["authors"] = data["authors"] .. ", " .. (args["first"] or args["first1"])
			end
		end
		if args["author-link"] or args["author-link1"] then
			data["authors"] = "[[" .. (args["author-link"] or args["author-link1"]) .. "|" .. data["authors"] .. "]]"
		end
		
		local finished = false
		local i = 2
		if not (args["author" .. toString(i)] or args["last" .. toString(i)]) then
				finished = true
		end
		while not finished do
			local displayText = ""
			if args["author" .. toString(i)] then
				displayText = displayText .. args["author" .. toString(i)]
			elseif args["last" .. toString(i)] then
				displayText = displayText .. args["last" .. toString(i)]
				if args["first" .. toString(i)] then
					displayText = displayText .. ", " .. args["first" .. toString(i)]
				end
			end
			if 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 (args["author" .. toString(i)] or args["last" .. toString(i)]) then
				finished = true
			end
		end
	end
end