Jump to content

Module:Cite web

ពីវិគីភីឌា

Documentation for this module may be created at Module:Cite web/doc

local p = {}

local args = {} --will contain Cite_web template parameters

local function authorStr()
	local fullStr = ""
	local fullName = ""
	if args["last"] then
		if args["first"] then
			fullName = args["first"] .. " " .. args["last"]
		else
			fullName = args["last"]
		end
	else
		fullName = args["author"]
	end

	if args["authorlink"] then
		fullStr = "[[" .. args["authorlink"] .. "|" .. args["fullName"] .. "]]"
	else
		fullStr = fullName
	end

	if args["coauthors"] then
		fullStr = fullStr .. "<nowiki>;</nowiki> " .. args["coauthors"]
	end

	return fullStr
end

local function dateStr()
	if not (args["year"] or args["date"]) then
		return ""
	end

	local date =
		args["date"]
		or (args["month"] .. " " .. args["year"])
		or args["year"]

	return "(" .. date .. ")"
end

--[[
@args url | archiveurl, title [, curly]
@returns linked title, optionnaly wrapped inside curly single quotes
]]
function titleStr()
	local titleStr = "[" .. (args["archiveurl"] or args["url"]) .. " " .. args["title"] .. "]"
	if args ["curly"] then
		titleStr = "“" .. titleStr .. "”"
	end

	return titleStr
end

local function accessDateStr()
	local fullDate = ""
	local fullStr = ""

	if args["accessdate"] then
		fullDate = args["accessdate"]
	elseif args["accessmonthday"] then
		fullDate = args["accessmonthday"]
	elseif args["accessdaymonth"] then
		fullDate = accessdaymonth
	end

	if args["accessyear"] then
		fullDate = fullDate .. " , " .. args["accessyear"]
	end

	if fullDate and fullDate ~= "" then
		fullStr = "Retrieved on " .. fullDate .. " "
		return fullStr
	else
		return ""
	end
end




function p.main (frame)
	args = frame:getParent().args

	local refContent = ""

	-- if title or url unset:
	-- You must specify  '''''title = ''''' and '''''url = ''''' when using {{[[Template:cite web|cite web]]}}.
	-- if no namespace: [[Category:Articles with broken citations]]}}

	local author = authorStr()
	local hasAuthor = author and author ~= ""
	if hasAuthor then
		refContent = authorStr() .. " " .. dateStr() .. " "
	end

	if args["editor"] then
		refContent = refContent .. " " .. args["editor"] .. ": "
	end

	refContent = refContent .. titleStr()

	if args["format"] then
		refContent = refContent .. " (" .. args["format"] .. ")"
	end

	if args["language"] then
		refContent = refContent .. " (in " .. args["language"] .. ")"
	end

	if args["work"] or args["website"] then
		refContent = refContent .. "  ''" .. (args["work"] or args["website"]) .. "''"
	end

	if args["pages"] then
		refContent = refContent .. " " .. args["pages"]
	end

	if args["publisher"] then
		refContent = refContent .. ". " .. args["publisher"] .. " " ..dateStr()
	elseif not hasAuthor then
		refContent = refContent .. " " .. dateStr() .. " "
	end

	if args["archivedate"] then
		refContent = refContent .." Archived from [" .. args["url"] .. " the original] on " .. args["archivedate"] .. " "
	end

	if args["doi"] then
		refContent = refContent .. " doi:[http://dx.doi.org/" .. args["doi"] .. " " .. (args["doilabel"] or args["doi"]) .. "]"
	end

	refContent = refContent .. accessDateStr()

	if args["quote"] then
		refContent = refContent .. "&nbsp;“" .. args["quote"] .. "”"
	end
	
	return refContent
end

return p