Marvel Database
Register
Advertisement

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

local p = {}
local getArgs = require('Dev:Arguments').getArgs
local h = require("Module:HF")
local standard = require("Module:StandardizedName")


function p.reference(frame)
	local args = getArgs(frame)
	local arg = args[1]
	local arg2 = args[2]
	local pagename = ''
	local pagetype = ''
	local info = ''
	local info2 = ''
	local link = ''
	local output = ''
	
	if not h.isempty(arg)
		then
			pagename = standard.lua_replace_number_sign(arg)
			if string.find(pagename, ' Vol ') ~= nil
				then pagetype = 'Vol'
				elseif string.find(pagename, ' Season ') ~= nil
					then pagetype = 'Season'
			end

			if pagetype == 'Vol' or pagetype == 'Season'
				then 
					info = standard.lua_get_title_volume_issue(pagename, pagetype)
					link = info.link.all
					if not h.isempty(arg2) 
						then 
							if string.match(arg2, '^%d+$') ~= nil
								then 
									info2 = standard.lua_get_title_volume_issue(info.noissue..' '..arg2, pagetype)
									output = link..'–'..h.Link(info2.link.part1, arg2)
								else 
									output = link..' '..arg2
							end
						else 
							output = link
					end
				else
					link = arg
					if not h.isempty(arg2)
						then output = link..' '..arg2
						else output = link
					end
			end
		else
			output = 'Reference Needed'
	end
	
	return output
end


function p.referenceName(frame)
	local args = getArgs(frame)
	local arg = args[1]
	local arg2 = args[2]
	local output = ""

	if h.isempty(arg)
		then
			output = "Reference Needed"
		else
			output = string.gsub(arg, ":", "")
			output = string.gsub(output, "%.", "")
			output = string.gsub(output, "%[", "")
			output = string.gsub(output, "%]", "")
	end
  
	if not h.isempty(arg2)
		then output = output .. "-" .. arg2
	end
	
	return output
end


function p.cite_web(frame)
	local args = getArgs(frame)
	local url = args.url
	local title = args.title
	local archiveurl = args.archiveurl
	local archivedate = args.archivedate
	local author = args.author
	local authorlink = args.authorlink
	local first = args.first
	local last = args.last
	local coauthors = args.coauthors
	local date = args.date
	local year = args.year
	local month = args.month
	local language = args.language
	local format = args.format
	local work = args.work
	local pages = args.pages
	local publisher = args.publisher
	local accessdate = args.accessdate
	local accessyear = args.accessyear
	local accessmonthday = args.accessmonthday
	local link
	local output = ""
	
	if h.isempty(url) or h.isempty(title)
		then 
			output = "Error on call to [[Template:Cite web]]: Parameters '''url''' and '''title''' must be specified"..h.Category('Pages with script errors')
		elseif ( not h.isempty(archiveurl) and h.isempty(archivedate) ) or ( h.isempty(archiveurl) and not h.isempty(archivedate) )
			then output = "Error on call to [[Template:Cite web]]: Parameters '''archiveurl''' and '''archivedate''' must be both specified or both omitted"..h.Category('Pages with script errors')
		else
			if not h.isempty(author) or not h.isempty(last)
				then
					if not h.isempty(authorlink)
						then output = output .. authorlink
					end
					if not h.isempty(last) -- author's last name
						then 
							output = output .. last
							if not h.isempty(first) -- author's first name
								then output = output .. ', ' .. first
							end
						else 
							output = output .. author
					end
					if not h.isempty(coauthors)
						then output = output .. '; ' .. coauthors
					end
		
					if not h.isempty(date)
						then output = output .. ' (' .. date .. ')'
						elseif not h.isempty(year)
							then
								if not h.isempty(month)
									then output = output .. ' (' .. month  .. ' ' .. year .. ')'
									else output = output .. ' (' .. year .. ')'
								end
					end
			end		
			if not h.isempty(archiveurl)
				then link = archiveurl
				else link = url
			end 
			output = output .. ' [' .. link .. ' ' .. title .. ']'
					
			if not h.isempty(language)
				then output = output .. ' (in ' .. language .. ')'
			end

			if not h.isempty(format)
				then output = output .. ' ' .. format
			end

			if not h.isempty(work)
				then output = output .. " ''" .. work .. "''"
			end
					
			if not h.isempty(pages)
				then output = output .. " pp." .. pages
			end
					
			if not h.isempty(publisher)
				then output = output .. " " .. publisher
			end
			output = output .. "."
			
			if not h.isempty(archivedate)
				then output = output .. " Archived from " .. "[" .. url .. " the original] on " .. archivedate .. "."
				elseif not h.isempty(accessdate)
					then output = output .. " Retrieved on " .. accessdate .. "."
				elseif not h.isempty(accessyear)
					then
						if not h.isempty(accessmonthday)
							then output = output .. " Retrieved on " .. accessmonthday .. ", " .. accessyear .. "."
							else output = output .. " Retrieved on " .. accessyear .. "."
						end
			end
	end

	return output
end

return p
Advertisement