Module:Cite web

-- -- -- This module implements Template:Cite web.

local p = {}

-- Lazily load a mw.language object. local lang

local function makeCategoryLink(cat) return string.format('', cat) end

local function makeWikitextError(msg) local ret = '' ret = ret .. string.format(		' Template:Cite web error: %s. ',		msg	) if mw.title.getCurrentTitle.namespace == 0 then ret = ret .. makeCategoryLink('Articles with template errors') end return ret end

local function makeDateLink(date, year) lang = lang or mw.language.getcontentlanguage local success, dateLink = pcall(		lang.formatdate, lang,		'f j, y',		date	) local ret = '' local ret if success and dateLink then ret = dateLink if year then ret = ret .. string.format(', %s', year) end end return ret end

local function makeDate(date, year, month) if date then return string.format(' (%s)', date) elseif year then if month then return string.format(' (%s %s)', month, year) else return string.format(' (%s)', year) end end end

local function makeAccessdateBlurb(monthDay, year, yearArgName) year = year or yearArgName return string.format(' Retrieved on %s, %s.', monthDay, year) end

function p._main(args) -- Validate input if not args.url or not args.title then return makeWikitextError("parameters url and title must be specified") end if args.archiveurl and not args.archivedate or args.archivedate and not args.archiveurl then return makeWikitextError(			"Parameters archiveurl and archivedate must be both specified or both omitted"		) end

local ret = {}

-- Authors if args.author or args.last then local display if args.last then display = args.last if args.first then display = display .. ', ' .. args.first end else display = args.author end if args.authorlink then ret[#ret + 1] = string.format('%s', args.authorlink, display) else ret[#ret + 1] = args.author end if args.coauthors then ret[#ret + 1] = '; ' .. args.coauthors end ret[#ret + 1] = makeDate(args.date, args.year, args.month) ret[#ret + 1] = '. '	end

-- Editor if args.editor then ret[#ret + 1] = ' ' .. args.editor .. ':'	end

-- URL if args.title then if args.archiveurl then ret[#ret + 1] = string.format('[%s %s]', args.archiveurl, args.title) elseif args.url then ret[#ret + 1] = string.format('[%s %s]', args.url, args.title) end end

-- Language if args.language then ret[#ret + 1] = string.format(			' (%s) ',			args.language		) end

-- Format if args.format then ret[#ret + 1] = string.format(' (%s)', args.format) end

-- Work if args.work then ret[#ret + 1] = string.format(". %s", args.work) end

-- Pages if args.pages then ret[#ret + 1] = ' ' .. args.pages end

-- Publisher if args.publisher then ret[#ret + 1] = '. ' .. args.publisher end

-- Add date for when no author is specified. if not args.author and not args.last then ret[#ret + 1] = makeDate(args.date, args.year, args.month) end

ret[#ret + 1] = '.'

-- Archive date. if args.archivedate then local url = args.url or '' local dateLink = makeDateLink(args.archivedate, args.archiveyear) if dateLink then ret[#ret + 1] = string.format(				' Archived from [%s the original] on %s.',				url, date			) end end

-- Access date if args.accessdate then local dateLink = makeDateLink(args.accessdate, args.accessyear) if dateLink then ret[#ret + 1] = string.format(' Retrieved on %s.', url, date) end elseif args.accessmonthday then ret[#ret + 1] = makeAccessdateBlurb(			args.accessmonthday,			args.accessyear,			''		) elseif args.accessdaymonth then ret[#ret + 1] = makeAccessdateBlurb(			args.accessdaymonth,			args.accessyear,			''		) end

-- Quote if args.quote then ret[#ret + 1] = string.format(' "%s"', args.quote) end

return table.concat(ret) end

function p.main(frame) local args = {} for k, v in pairs(frame:getParent.args) do		v = v:match('^%s*(.-)%s*$') -- trim whitespace if v ~= '' then args[k] = v		end end return p._main(args) end

return p

--