Module:Web citation: Difference between revisions

From ProleWiki, the proletarian encyclopedia
m (Attempt to change the code so that date is no longer necessary. Yes, I know it's shitty code and a series of if-else's, I don't know how to code at all lmao)
m (Added option for quote)
Line 16: Line 16:
local ArchiveDate = pframe.args['archive-date']
local ArchiveDate = pframe.args['archive-date']
local Retrieved = pframe.args.retrieved
local Retrieved = pframe.args.retrieved
local Quote = pframe.args.quote
if is_set (Date) then
if is_set (Date) then
Line 28: Line 29:
if is_set (Journalist) then
if is_set (Journalist) then
if is_set (Date) then
if is_set (Date) then
x1 = Journalist .. " (" .. Date .. ")."
first_part = Journalist .. " (" .. Date .. ")."
else
else
x1 = Journalist .. "."
first_part = Journalist .. "."
end
end
else
else
x1 = ""
first_part = ""
end
end
Line 47: Line 48:
end
end
end
end
x2 = Title
second_part = Title
else
else
x2 = ""
second_part = ""
end
end
if is_set(Newspaper) then
if is_set(Newspaper) then
x3 = "''" .. Newspaper .. "''."
third_part = "''" .. Newspaper .. "''."
else
else
x3 = ""
third_part = ""
end
end
Line 61: Line 62:
if is_set(ArchiveURL) then
if is_set(ArchiveURL) then
if is_set(ArchiveDate) then
if is_set(ArchiveDate) then
x4 = "[" .. ArchiveURL .. " " .. "Archived" .. "]" .. " " .. " from the original on" .. " " .. ArchiveDate .. "."
fourth_part = "[" .. ArchiveURL .. " " .. "Archived" .. "]" .. " " .. " from the original on" .. " " .. ArchiveDate .. "."
else
else
x4 = "[" .. ArchiveURL .. " " .. "Archived" .. "]" .. " from the original."
fourth_part = "[" .. ArchiveURL .. " " .. "Archived" .. "]" .. " from the original."
end
end
else
else
x4 = ""
fourth_part = ""
end
end
if is_set (Retrieved) then
if is_set (Retrieved) then
x5 = "Retrieved" .. " " .. Retrieved .. "."
fifth_part = "Retrieved" .. " " .. Retrieved .. "."
else
else
x5 = ""
fifth_part = ""
end
end
if is_set (Quote) then
Quote = "“" .. Quote .. "”"
local div = mw.html.create ('div')
div
:attr("style", "width:80%; margin-left:10%;")
:wikitext(Quote)
local br = mw.html.create ('br', selfClosing)
first_part = italics(tostring(div)) .. tostring(br) .. first_part
end




 
if is_set (first_part) then
if is_set (x1) then
first_part = first_part .. " "
x1 = x1 .. " "
end
end
if is_set (x2) then
if is_set (second_part) then
x2 = x2 .. " "
second_part = second_part .. " "
end
end
if is_set (x3) then
if is_set (third_part) then
x3 = x3 .. " "
third_part = third_part .. " "
end
end
if is_set (x4) then
if is_set (fourth_part) then
x4 = x4 .. " "
fourth_part = fourth_part .. " "
end
end
Render = x1 .. x2 .. x3 .. x4 .. x5
Render = first_part .. second_part .. third_part .. fourth_part .. fifth_part
return Render
return Render
end
end
return p
return p

Revision as of 16:25, 8 January 2022

local p = {}

local function is_set (var)
	return not (var == nil or var == '');
end

function p.cite( frame )
	local pframe = frame:getParent()

	local Journalist = pframe.args.journalist
	local Date = pframe.args['date']
	local Title = pframe.args.title
	local URL = pframe.args.url
	local Newspaper = pframe.args.newspaper
	local ArchiveURL = pframe.args['archive-url']
	local ArchiveDate = pframe.args['archive-date']
	local Retrieved = pframe.args.retrieved
	local Quote = pframe.args.quote
	
	if is_set (Date) then
			if not Date:match("^%d%d%d%d%-%d%d%-%d%d$") then
		Date = "<span class=\"error\">Wrong date format. Expected YYYY-MM-DD</span>"
		else
			Date = Date
			end
	end

	
	if is_set (Journalist) then
		if is_set (Date) then
			first_part = Journalist .. " (" .. Date .. ")."
			else
				first_part = Journalist .. "."
		end
		else
			first_part = ""
	end
	
	if is_set (Title) then
		if is_set (URL) then
			Title = "[" .. URL .. " " .. "\"" .. Title .. "\"" .. "]"
			end
		if not is_set (Journalist) then
			if is_set (Date) then
			Title = Title .. " (" .. Date .. ")."
			else
				Title = Title .. "."
			end
	end
		second_part = Title
		else
			second_part = ""
	end
	
	if is_set(Newspaper) then
			third_part = "''" .. Newspaper .. "''."
			else
				third_part = ""
		end
		

	if is_set(ArchiveURL) then
		if is_set(ArchiveDate) then
			fourth_part = "[" .. ArchiveURL .. " " .. "Archived" .. "]" .. " " .. " from the original on" .. " " .. ArchiveDate .. "."
			else
				fourth_part = "[" .. ArchiveURL .. " " .. "Archived" .. "]" .. " from the original."
		end
			else
				fourth_part = ""
	end
			
	if is_set (Retrieved) then
		fifth_part = "Retrieved" .. " " .. Retrieved .. "."
		else
			fifth_part = ""
	end
		
	if is_set (Quote) then
		Quote = "“" .. Quote .. "”"
		local div = mw.html.create ('div')
		div
		:attr("style", "width:80%; margin-left:10%;")
		:wikitext(Quote)
		local br = mw.html.create ('br', selfClosing)
		first_part = italics(tostring(div)) .. tostring(br) .. first_part
	end


	if is_set (first_part) then
		first_part = first_part .. " "
	end
	
	if is_set (second_part) then
		second_part = second_part .. " "
	end
	
	if is_set (third_part) then
		third_part = third_part .. " "
	end
	
	if is_set (fourth_part) then
		fourth_part = fourth_part .. " "
	end
	
	Render = first_part .. second_part .. third_part .. fourth_part .. fifth_part
	
	return Render
end
return p