Module:References: Difference between revisions

From RuneRealm Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 702: Line 702:
if hc(a.title) then
if hc(a.title) then
reftext = reftext .. "''" .. a.title .. "''"
reftext = reftext .. "''" .. a.title .. "''"
if hc(a.mw.pages) then
if hc(a.pages) then
reftext = reftext .. ', (' .. a.mw.pages .. ')'
reftext = reftext .. ', (' .. a.pages .. ')'
end
end
reftext = reftext .. '. '
reftext = reftext .. '. '
Line 932: Line 932:
end
end
if hc(a.mw.pages) then
if hc(a.pages) then
reftext = reftext .. ' pp. ' .. a.mw.pages
reftext = reftext .. ' pp. ' .. a.pages
end
end

Revision as of 11:23, 17 October 2024

Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:References/doc. [edit]
Module:References is invoked by .
Module:References requires Module:Mainonly.
Module:References requires Module:Paramtest.
Module:References requires Module:Yesno.
Module:References loads data from Module:References/GodLetter.
Module:References loads data from Module:References/Postbag.

--                Main module implementing reference templates                --

local onmain = require('Module:Mainonly').on_main
local paramtest = require('Module:Paramtest')
local hc = paramtest.has_content
local dt = paramtest.default_to
local yn = require('Module:Yesno')
local lang = mw.getContentLanguage()

local p = {} --all template entrance points here
local r = {} --reference formatters here to not expose them to #invoke, and to not clutter p

local reftext, cats = '', ''
local lostReferenceMsg = '<sup class="noprint fact">&#91;<span class="fact-text"title="The page referenced can no longer be accessed. Please try to find an archived version of it or another reference for this statement if possible.">Lost reference</span>&#93;</sup>'

function string.starts(String, Start)
	return string.sub(String, 1, string.len(Start)) == Start
end

-- for consistent date formats
local function formatDate(datep)
	local datetbl = {}
	datetbl.day = lang:formatDate('j', datep)
	datetbl.month = lang:formatDate('F', datep)
	datetbl.year = lang:formatDate('Y', datep)
	return lang:formatDate('j F Y', datep), datetbl
end

-- create the ref tag to be returned
local function reftag(frame, reftype, forcedArgs)
	local args = frame:getParent().args
	local s = ''
	local opts = {}
	
	if forcedArgs ~= nil then
		for k, v in pairs(forcedArgs) do
			args[k] = v
		end
	end
	
	if hc(args.name) then
		opts.name = args.name
	end
	if hc(args.group) then
		opts.group = args.group
	end
	
	local ref, cat = r[reftype](args)
	
	return frame:extensionTag{name = 'ref', content = mw.text.tag('span', {['class']= 'citation ' .. reftype }, ref .. cat), args = opts}
end

local function plainref(frame, reftype, forcedArgs)
	local args = frame:getParent().args
	
	if forcedArgs ~= nil then
		for k, v in pairs(forcedArgs) do
			args[k] = v
		end
	end
	
	local ref, cat = r[reftype](args)
	
	return mw.text.tag('span', {['class']= 'citation ' .. reftype }, ref .. cat)
end

------------ Helper Templates -----------------

--[==[
[[Template:NamedRef]]
--]==]
function p.namedref(frame)
	local args = frame:getParent().args
	local opts = {}
	opts.name = args.name or args[1]
	if hc(args.group) then
		opts.group = args.group
	elseif hc(args[2]) then
		opts.group = args[2]
	end
	
	return frame:extensionTag{name = 'ref', args = opts}
end


--[==[
[[Template:Reflist]]
--]==]
function p.reflist(frame)
	local args = frame:getParent().args
	local div = mw.html.create('div')
	local resp = 1
	
	if hc(args[1]) or hc(args.colwidth) then
		div:css({ ['column-width'] = args[1] or args.colwidth })
		resp = 0
	end
	
	div
		:addClass('reflist')
		:wikitext(frame:extensionTag{name = 'references', args = {group = args.group, responsive = resp}})
	
	-- Implement {{Notelist}}
	if args.group == 'lower-alpha' then
		div:addClass('reflist-lower-alpha')
	end
	
	if not yn(args.quotes) then
		div:addClass('hideQuotes')
	end
	
	return div
end

------------RuneScape Citation templates--------------

--[==[
[[Template:CiteDevBlog]] and [[Template:PlainCiteDevBlog]]
--]==]
function p.devblogref(frame)
	return reftag(frame, 'devblog')
end

function p.devblogplain(frame)
	return plainref(frame, 'devblog')
end

function r.devblog(a)
	reftext = dt(a.author, 'Jagex') --author, defaults to Jagex
	reftext = reftext .. '. '
	if hc(a.url) then --url, if present makes a link
		reftext = reftext .. '[' .. a.url
		if hc(a.title) then
			reftext = reftext .. ' "' .. a.title .. '."'--if title not present leave as link
		end
		reftext = reftext .. ']'
	else
		if hc(a.title) then
			reftext = reftext .. '"' .. a.title .. '."'
		end
	end
	reftext = reftext .. ' '
	if hc(a.blogdate) then
		a.blogdate = formatDate(a.blogdate)
		reftext = reftext .. a.blogdate .. '.'
	end
	reftext = reftext .. " Developers' Blogs. "
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not (hc(a.author) and hc(a.url) and hc(a.title) and hc(a.blogdate)) then --validation, required params are author, url, title, and blogdate (mainonly)
		cats = '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CiteDevDiary]] and [[Template:PlainCiteDevDiary]]
--]==]
function p.devdiaryref(frame)
	return reftag(frame, 'devdiary')
end

function p.devdiaryplain(frame)
	return plainref(frame, 'devdiary')
end

function r.devdiary(a)
	reftext = dt(a.author, 'Jagex') --author, defaults to Jagex
	reftext = reftext .. '. '
	if hc(a.url) then --url, if present makes a link
		reftext = reftext .. '[' .. a.url
		if hc(a.title) then
			reftext = reftext .. ' "' .. a.title .. '". '--if title not present leave as link
		end
		reftext = reftext .. ']'
	elseif hc(a.title) then
		reftext = reftext .. '"' .. a.title .. '". '
	end
	
	if hc(a.diarydate) then
		a.diarydate = formatDate(a.diarydate)
		reftext = reftext .. a.diarydate .. '.'
	end
	reftext = reftext .. ' Development Diaries. '
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not (hc(a.author) and hc(a.url) and hc(a.title) and hc(a.diarydate)) then
		cats = '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CiteForum]] and [[Template:PlainCiteForum]]
--]==]
function p.forumref(frame)
	return reftag(frame, 'forum')
end

function p.forumplain(frame)
	return plainref(frame, 'forum')
end

function r.forum(a)
	reftext = dt(a.author, 'Jagex') --author, defaults to Jagex
	reftext = reftext .. '. '
	if hc(a.url) or hc(a.archiveurl) then --url, if present makes a link
		if hc(a.archiveurl) then
			reftext = reftext .. '[' .. a.archiveurl
		elseif hc(a.url) then
			reftext = reftext .. '[' .. a.url
		end
		if hc(a.title) then
			reftext = reftext .. ' "' .. a.title .. '."'--if title not present leave as link
		end
		reftext = reftext .. ']'
	elseif hc(a.title) then
		reftext = reftext .. '"' .. a.title .. '."'
	end
	reftext = reftext .. ' '
	if hc(a.postdate) then
		a.postdate = formatDate(a.postdate)
		reftext = reftext .. a.postdate .. '.'
	end
	
	if hc(a.archivedate) then
		a.archivedate = formatDate(a.archivedate)
		reftext = reftext .. ' Archived from [' .. a.url .. ' the original] on ' .. a.archivedate .. '. '
	end
	
	reftext = reftext .. " ''" .. dt(a.forum, 'Old School RuneScape') .. "'' Forums. "
	reftext = reftext .. (a.notes or '')
	if hc(a.lost) then
		reftext = reftext .. lostReferenceMsg
	end
	
	if onmain() then
		if not (hc(a.author) and hc(a.url) and hc(a.title) and hc(a.postdate)) then
			cats = cats .. '[[Category:Incomplete references]]'
		end
		if a.url and (string.find(a.url, 'forum.runescape.com/', 1, true) or string.find(a.url, 'services.runescape.com/m=forum/', 1, true) or string.find(a.url, 'secure.runescape.com/m=forum/', 1, true)) then
			if hc(a.lost) then
				cats = cats .. '[[Category:Lost forum references]]'
			elseif not (hc(a.archiveurl) and hc(a.archivedate)) then
				cats = cats .. '[[Category:Unarchived forum references]]'
			end
		end
	end
	return reftext, cats
end


--[==[
[[Template:CiteGodLetter]] and [[Template:PlainCiteGodLetter]]
--]==]
local function checkGodLetterURL(frame)
	local args = frame:getParent().args
	
	if not hc(args.url) and not hc(args.archiveurl) then
		local issues = mw.loadData('Module:References/GodLetter')
		local issueNum = tonumber(args.issue)
		local article = issues[issueNum]
		
		if hc(article) then
			local newArgs = {}
			
			if not hc(args.title) then
				local title = article:match('Transcript:(.+)')
				
				if hc(title) then
					newArgs.title = title:gsub('_', ' ')
				end
			end
			
			if hc(args.letter) then
				local letter = args.letter:gsub(' ', '_'):lower()
				
				if letter:match('^%d+$') then
					newArgs.title = '[[' .. article .. '#letter_' .. letter .. '|"' .. newArgs.title .. '"]]'
				elseif letter:match('^letter_%d+$') then
					newArgs.title = '[[' .. article .. '#' .. letter .. '|"' .. newArgs.title .. '"]]'
				else
					newArgs.title = '[[' .. article .. '|"' .. newArgs.title .. '"]]'
				end
			else
				newArgs.title = '[[' .. article .. '|"' .. newArgs.title .. '"]]'
			end
			
			return newArgs
		end
	end
	
	return nil
end

function p.godletterref(frame)
	local forcedArgs = checkGodLetterURL(frame)
	return reftag(frame, 'godletter', forcedArgs)
end

function p.godletterplain(frame)
	local forcedArgs = checkGodLetterURL(frame)
	return plainref(frame, 'godletter', forcedArgs)
end

function r.godletter(a)
	if hc(a.issue) then
		reftext = reftext .. 'God Letter ' .. a.issue
		
		if hc(a.title) then
			reftext = reftext .. ': ' .. a.title
		end
	elseif hc(a.title) then
		reftext = reftext .. a.title
	end
	reftext = reftext .. '. '
	
	-- no consistent input, maybe better to just hide it
--	if hc(a.letter) then
--		reftext = reftext .. '. ' .. a.letter .. '. '
--	end
	
	reftext = reftext .. " ''RuneScape'' God Letters. Jagex. " .. (a.notes or '')
	
	if onmain() and not hc(a.issue) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CiteLore]] and [[Template:PlainCiteLore]]
--]==]
function p.loreref (frame)
	return reftag(frame, 'lore')
end

function p.loreplain(frame)
	return plainref(frame, 'lore')
end

function r.lore(a)
	if hc(a.title) then
		reftext = reftext .. '[[Transcript:' .. a.title
		if hc(a.sectitle) and yn(a.sectitle, true) then
			reftext = reftext .. '#' .. a.sectitle .. '|"' .. a.title .. '"]]. <i>§ ' .. a.sectitle .. '</i> ' 
		else
			reftext = reftext .. '|"' .. a.title .. '"]]. ' 
		end
	elseif hc(a.sectitle) and yn(a.sectitle, true) then
		reftext = reftext ..'[[' .. a.sectitle .. ']]. '
	end
	
	reftext = reftext .. "''RuneScape'' Lores and Histories. Jagex. "
	if hc(a.quote) then
		reftext = reftext .. '"' .. a.quote .. '" '
	end
	
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not hc(a.title) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CiteNews]] and [[Template:PlainCiteNews]]
--]==]
function p.newsref(frame)
	return reftag(frame, 'news')
end

function p.newsplain(frame)
	return plainref(frame, 'news')
end

function r.news(a)
	local upns = hc(a.title) and 'Update:' .. a.title
	local archiveurl
	local osrspost = false
	
	if hc(a.url) and hc(a.title) and mw.title.new(upns).exists then --update: ns, ifexists makes a link
		reftext = reftext .. '[[' .. upns .. '|"' .. a.title .. '"]].'
		archiveurl = a.url
		osrspost = true
	elseif hc(a.url) then --url, if present makes a link
		reftext = reftext .. '[' .. a.url
		if hc(a.title) then
			reftext = reftext .. ' "' .. a.title .. '"'--if title not present leave as link
		end
		reftext = reftext .. '].'
	elseif hc(a.title) then
		reftext = reftext .. '"' .. a.title .. '"'
	end
	
	local newsdatetbl = {}
	if hc(a.newsdate) then
		a.newsdate, newsdatetbl = formatDate(a.newsdate)
	end
	
	if osrspost and (hc(a.newsdate) and tonumber(newsdatetbl.year) >= 2013) then
		reftext = reftext .. " ''Old School RuneScape'' News. "
	else
		reftext = reftext .. " ''RuneScape'' News. "
	end
	
	if hc(a.author) then
		reftext = reftext .. a.author .. '. '
	else
		reftext = reftext .. 'Jagex. '
	end
	
	reftext = reftext .. ' '
	if hc(a.newsdate) then
		reftext = reftext .. a.newsdate .. '. '
	end
	
	if archiveurl then
		reftext = reftext .. 'Archived from [' .. archiveurl .. ' the original]. '
	else
		reftext = reftext .. 'Archived from the original. '
	end
	
	if a.date then
		mw.addWarning('[[Template:CiteNews]] is using `date` parameter instead of `newsdate`')
	end
	
	if hc(a.quote) then
		reftext = reftext .. ' "' .. a.quote .. '"'
	end
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not (hc(a.url) and hc(a.title) and hc(a.newsdate)) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CiteNPC]] and [[Template:PlainCiteNPC]]
--]==]
function p.npcref(frame)
	return reftag(frame, 'npc')
end

function p.npcplain(frame)
	return plainref(frame, 'npc')
end

function r.npc(a)
	if hc(a.npc) then
--		if mw.title.new(a.npc) then
			reftext = reftext .. '[[' .. a.npc .. ']]'
--		else
--			reftext = reftext .. a.npc
--		end
	end
	if hc(a.loc) then
		reftext = reftext .. ' in [[' .. a.loc .. ']]. '
	else
		reftext = reftext .. '. '
	end
	
	reftext = reftext .. "''Old School RuneScape''. "
	
	local islist
	if hc(a.quote) then
		islist = mw.ustring.match( a.quote, '^%s*%*.*\n%*' )
		local quote = islist and ('\n' .. a.quote) or '"' .. a.quote .. '" '
		local span = mw.html.create('span')
		if islist then
			span:newline()
		end
		span:wikitext(quote)
		reftext = reftext .. tostring(span)
	end
	
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not ((hc(a.npc) or islist) and hc(a.quote)) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CitePoll]] and [[Template:PlainCitePoll]]
--]==]
function p.pollref(frame)
	return reftag(frame, 'poll')
end

function p.pollplain(frame)
	return plainref(frame, 'poll')
end

function r.poll(a)
	local pns = hc(a.poll) and 'Poll:' .. a.poll
	local archive = ''
	
	-- largely resembling r.news
	if hc(a.url) and hc(a.poll) and mw.title.new(pns).exists then
		reftext = reftext .. '[[' .. pns .. '|"' .. a.poll .. '"]]. '
		archive = ' Archived from [' .. a.url .. ' the original].'
	elseif hc(a.url) then
		reftext = reftext .. '[' .. a.url
		if hc(a.poll) then
			reftext = reftext .. ' "' .. a.poll .. '"'
		end
		reftext = reftext .. ']. '
	elseif hc(a.poll) then
		reftext = reftext .. '"' .. a.poll .. '". '
	end
	
	if hc(a.question) and yn(a.question, true) then
		reftext = reftext .. 'Question ' .. a.question .. '. '
	end
	
	if hc(a.polldate) then
		a.polldate = formatDate(a.polldate)
		reftext = reftext .. a.polldate .. '.' .. archive
	end
	
	reftext = reftext .. " ''Old School RuneScape'' Polls. Jagex. "
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not (hc(a.url) and hc(a.poll) and hc(a.question) and hc(a.polldate)) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CitePostbag]] and [[Template:PlainCitePostbag]]
--]==]
function p.postbagref(frame)
	return reftag(frame, 'postbag')
end

function p.postbagplain(frame)
	return plainref(frame, 'postbag')
end

function r.postbag(a)
	local anchor = false
	local anchorval
	local postbags = mw.loadData('Module:References/Postbag')
	local pbpagename = postbags[tonumber(a.issue)]
	local pbname = pbpagename:gsub( 'Transcript:', '')
	
	if hc(a.letter) then
		anchorval = a.letter
		if anchorval == tostring(tonumber(anchor)) then
			anchorval = tonumber(anchor)
			if anchorval == math.floor(anchor) and anchor >= 1 and anchor <= 15 then
				anchor = true
			end
		end
	end
	
--	if hc(a.author) and mw.title.new(a.author).exists then -- ifexists makes a link
--		reftext = reftext .. '[[' .. a.author .. ']]. '
--	else
		if hc(a.author) then
		reftext = reftext .. a.author .. '. '
	end
	
	if hc(a.issue) then
		if pbpagename then
			reftext = reftext .. 'Postbag ' .. a.issue .. ': [[' .. pbpagename .. '#'
			if anchor then
				reftext = reftext .. 'letter ' .. a.letter
			else
				reftext = reftext .. a.letter
			end
			reftext = reftext .. '|"' .. pbname .. '"]]'
		else
			reftext = reftext .. 'Postbag ' .. a.issue
			if hc(a.title) then
				reftext = reftext .. ': "' .. a.title .. '"'
			end
		end
	elseif hc(a.title) then
		reftext = reftext .. '"' .. a.title .. '"'
	end
	if hc(a.letter) then
		if reftext ~= '' then
			reftext = reftext .. '. '
		end
		if anchor then
			reftext = reftext .. 'letter #' .. a.letter
		else
			reftext = reftext .. a.letter
		end
	end
	
	if tonumber(a.issue) >= 22 then
		reftext = reftext .. ". ''Old School RuneScape'' Postbags from the Hedge. "
	else
		reftext = reftext .. ". ''RuneScape'' Postbags from the Hedge. "
	end
	
	reftext = reftext .. 'Jagex. ' .. (a.notes or '')

	if hc(a.quote) then
		reftext = reftext .. '"' .. a.quote .. '" '
	end
	
	if onmain() and not (hc(a.issue) and hc(a.letter) and hc(a.author)) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CiteText]] and [[Template:PlainCiteText]]
--]==]
function p.textref(frame)
	return reftag(frame, 'text')
end

function p.textplain(frame)
	return plainref(frame, 'text')
end

function r.text(a)
	if hc(a.author) then
		reftext = reftext .. '[[' .. a.author .. ']]'
		if not hc(a.loc) then
			reftext = reftext .. '. '
		end
	end
	
	if hc(a.loc) then
		if hc(a.author) then
			reftext = reftext .. ' in [[' .. a.loc .. ']]. '
		else
			reftext = reftext .. 'In [[' .. a.loc .. ']]. '
		end
	end
	
	
	if hc(a.text) then
		-- crude fix incase link is piped via {{!}}
		local link, pipe = a.text, a.text
		if a.text:match('|') then
			link = a.text:match('^.-|'):gsub('%|$', '')
			pipe = a.text:match('|.-$'):gsub('^%|', '')
		end
		
		reftext = reftext .. '[[' .. link .. '|"' .. pipe .. '"]]. '
	end
	
	if hc(a.page) then
		reftext = reftext .. 'Page ' .. a.page .. '. '
	end
	
	reftext = reftext .. "''Old School RuneScape''. "
	
	if hc(a.quote) then
		reftext = reftext .. '"' .. a.quote .. '" '
	end
	
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not (hc(a.text) and hc(a.quote)) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


------------ General Citation Templates -----------------


--[==[
[[Template:CitePub]] and [[Template:PlainCitePub]]
--]==]
function p.pubref(frame)
	return reftag(frame, 'pub')
end

function p.pubplain(frame)
	return plainref(frame, 'pub')
end

function r.pub(a)
	if hc(a.author) then
		reftext = a.author .. '. '
	end
	
	local str = ''
	if hc(a.title) then
		reftext = reftext .. "''" .. a.title .. "''"
		if hc(a.pages) then
			reftext = reftext .. ', (' .. a.pages .. ')'
		end
		reftext = reftext .. '. '
	end
	if hc(a.publisher) then
		reftext = reftext .. a.publisher
		if hc(a.pubyear) then
			reftext = reftext .. ', ' .. a.pubyear
		end
		reftext = reftext .. '. '
	elseif hc(a.pubyear) then
		reftext = reftext .. a.pubyear .. '. '
	end
	reftext = reftext .. (a.notes or '')
	
	if onmain() and not (hc(a.title) and hc(a.publisher) and hc(a.pubyear)) then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	return reftext, cats
end


--[==[
[[Template:CiteTwitter]] and [[Template:PlainCiteTwitter]]
--]==]
function p.twitterref(frame)
	return reftag(frame, 'twitter')
end

function p.twitterplain(frame)
	return plainref(frame, 'twitter')
end

function r.twitter(a)
	reftext = reftext .. 'Jagex. '
	
	if hc(a.url) or hc(a.archiveurl) then --url, if present makes a link
		if hc(a.archiveurl) then
			reftext = reftext .. '[' .. a.archiveurl
		elseif hc(a.url) then
			reftext = reftext .. '[' .. a.url
		end
		if hc(a.author) then
			reftext = reftext .. ' ' .. a.author .. "'s Twitter account"--if title not present leave as link
		end
		reftext = reftext .. ']. '
	elseif hc(a.author) then
		reftext = reftext .. ' ' .. a.author .. "'s Twitter account. "
	end
	
	if hc(a.date) then
		a.date = formatDate(a.date)
		reftext = reftext .. a.date .. '. '
	end
	
	if hc(a.archivedate) then
		a.archivedate = formatDate(a.archivedate)
		reftext = reftext .. ' Archived from [' .. a.url .. ' the original] on ' .. a.archivedate .. '. '
	end
	
	if hc(a.quote) then
		if hc(a.author) then
			reftext = reftext .. a.author .. ': '
		end
		reftext = reftext .. '"' .. a.quote .. '" '
	end
	reftext = reftext .. (a.notes or '')
	if hc(a.lost) then
		reftext = reftext .. lostReferenceMsg
	end
	
	local err = ''
	if not (hc(a.url) and hc(a.author) and hc(a.date)) then
		err = err .. "Error calling CiteTwitter: parameters '''url''', '''author''', '''quote''', and '''date''' must be specified.<br>"
	end
	
	if hc(a.archiveurl) ~= hc(a.archivedate) then --xor
		err = err .. "Error calling CiteTwitter: parameters '''archiveurl''' and '''archivedate''' must both be specified or both be unspecified.<br>"
	end
	
	
	if onmain() and err ~= '' then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	
	if onmain() and not hc(a.archiveurl) then
		if hc(a.lost) then
			cats = cats .. '[[Category:Lost Twitter references]]'
		else
			cats = cats .. '[[Category:Unarchived Twitter references]]'
		end
	end
	
	return reftext, cats
end

--[==[
[[Template:CiteVideo]] and [[Template:PlainCiteVideo]]
--]==]
function p.videoref(frame)
	return reftag(frame, 'video')
end

function p.videoplain(frame)
	return plainref(frame, 'video')
end

function r.video(a)
	if hc(a.author) then
		reftext = a.author .. '. '
	end
	if hc(a.url) then --url, if present makes a link
		if hc(a.site) and not (string.lower(a.site) == 'youtube') then
			if (string.lower(a.site) == 'twitch') then -- twitch
				if string.starts(a.url, 'https://www.twitch.tv/videos/') then
					reftext = reftext .. '[' .. a.url
				elseif string.starts(a.url, 'https://clips.twitch.tv/') then
					reftext = reftext .. '[' .. a.url
				else
					reftext = reftext .. '[https://www.twitch.tv/videos/' .. a.url
				end
			else
				reftext = reftext .. '[' .. a.url
			end
		else -- yt (default)
			if string.starts(a.url, 'https://www.youtube.com/watch?v=') then
				reftext = reftext .. '[' .. a.url
			else
				reftext = reftext .. '[https://www.youtube.com/watch?v=' .. a.url
			end
		end
		if hc(a.title) then
			reftext = reftext .. ' "' .. a.title .. '"'--if title not present leave as link
		end
		reftext = reftext .. '] '
	else
		if hc(a.title) then
			reftext = reftext .. '"' .. a.title .. '" '
		end
	end
	
	if hc(a.timestamp) then
		reftext = reftext .. '(in ' .. a.timestamp .. '). '
	else
		reftext = reftext .. '. '
	end
	
	if not hc(a.site) or string.lower(a.site) == 'youtube' then
		reftext = reftext .. 'YouTube'
	else
		reftext = reftext .. a.site
	end
	reftext = reftext .. ' video. '
	
	if hc(a.date) then
		a.date = formatDate(a.date)
		reftext = reftext .. a.date .. '. '
	end
	reftext = reftext .. (a.notes or '')
	
	if onmain() then
		if not (hc(a.author) and hc(a.url) and hc(a.title) and hc(a.date)) then
			cats = cats .. '[[Category:Incomplete references]]'
		end
	end
	return reftext, cats
end

--[==[
[[Template:CiteGeneral]] and [[Template:PlainCiteGeneral]]
--]==]
function p.generalref(frame)
	return reftag(frame, 'general')
end

function p.generalplain(frame)
	return plainref(frame, 'general')
end

function r.general(a)
	local str = ''
	
	if hc(a.author) or hc(a.last) then
		if hc(a.last) then
			str = a.last
			if hc(a.first) then
				str = str .. ', ' .. a.first
			end
		else
			str = a.author
		end
		
		if hc(a.authorlink) then
			reftext = reftext .. '[' .. a.authorlink
			if str ~= '' then
				reftext = reftext .. ' ' .. str
			end
			reftext = reftext .. ']'
		else
			reftext = reftext .. str
		end
		
		if hc(a.coauthors) then
			reftext = reftext .. '; ' .. a.coauthors
		end
		
		reftext = reftext .. '. '
	end
	
	if hc(a.title) then
		if hc(a.archiveurl) then
			reftext = reftext .. '[' .. a.archiveurl .. ' ' .. a.title .. ']'
		elseif hc(a.url) then
			reftext = reftext .. '[' .. a.url .. ' ' .. a.title .. ']'
		end
	end
	
	if hc(a.format) then
		reftext = reftext .. ' (' .. a.format .. ')'
	end
	
	if hc(a.language) then
		reftext = reftext .. ' (in ' .. a.language .. ')'
	end
	
	if hc(a.work) then
		reftext = reftext .. ". ''" .. a.work .. "''"
	end
	
	if hc(a.pages) then
		reftext = reftext .. ' pp. ' .. a.pages
	end
	
	if hc(a.publisher) then
		reftext = reftext .. '. ' .. a.publisher
	end
	
	if hc(a.date) then
		a.date = formatDate(a.date)
		reftext = reftext .. '. ' .. a.date
	elseif hc(a.year) then
		if hc(a.month) then
			reftext = reftext .. '. ' .. a.month .. ' ' .. a.year
		else
			reftext = reftext .. '. ' .. a.year
		end
	end
	
	if not (hc(a.archiveurl) and hc(a.archivedate)) and hc(a.accessdate) then
		a.accessdate = formatDate(a.accessdate)
		reftext = reftext .. '. Retrieved ' .. a.accessdate
	end
	
	if reftext ~= '' then
		reftext = reftext .. '.'
	end
	
	if hc(a.archivedate) then
		a.archivedate = formatDate(a.archivedate)
		reftext = reftext .. ' Archived from [' .. a.url .. ' the original] on ' .. a.archivedate .. '.'
	end
	
	if hc(a.quote) then
		reftext = reftext .. ' "' .. a.quote .. '"'
	end
	
	if hc(a.notes) then
		reftext = reftext .. ' ' .. a.notes
	end
	if hc(a.lost) then
		reftext = reftext .. lostReferenceMsg
	end
	
	local err = ''
	if not (hc(a.url) and hc(a.title)) then
		err = err .. "Error calling CiteGeneral: parameters '''url''' and '''title''' must be specified.<br>"
	end
	if hc(a.archiveurl) ~= hc(a.archivedate) then --xor
		err = err .. "Error calling CiteGeneral: parameters '''archiveurl''' and '''archivedate''' must both be specified or both be unspecified.<br>"
	end
	
	if onmain() and err ~= '' then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	--[==[ are these needed?
	if onmain() and not hc(a.archiveurl) then
		if hc(a.lost) then
			cats = cats .. '[[Category:Lost web references]]'
		else
			cats = cats .. '[[Category:Unarchived web references]]'
		end
	end
	]==]--
	return reftext, cats
end

--[==[
[[Template:CiteReddit]] and [[Template:PlainCiteReddit]]
--]==]
function p.redditref(frame)
	return reftag(frame, 'reddit')
end

function p.redditplain(frame)
	return plainref(frame, 'reddit')
end

function r.reddit(a)
	reftext = dt(a.author, 'Jagex') --author, defaults to Jagex
	reftext = reftext .. '. '
	
	if hc(a.url) or hc(a.archiveurl) then --url, if present makes a link
		if hc(a.archiveurl) then
			reftext = reftext .. '[' .. a.archiveurl
		elseif hc(a.url) then
			reftext = reftext .. '[' .. a.url
		end
		if hc(a.title) then
			reftext = reftext .. ' "' .. a.title
		end
		reftext = reftext .. '"]. '
	end
	reftext = reftext .. "''Reddit''. "
	if hc(a.date) then
		a.date = formatDate(a.date)
		reftext = reftext .. a.date .. '. '
	end
	
	if hc(a.archivedate) then
		a.archivedate = formatDate(a.archivedate)
		reftext = reftext .. ' Archived from [' .. a.url .. ' the original] on ' .. a.archivedate .. '. '
	end
	
	if hc(a.quote) then
		if hc(a.author) then
			reftext = reftext .. a.author .. ': '
		end
		reftext = reftext .. '"' .. a.quote .. '" '
	end
	reftext = reftext .. (a.notes or '')
	if hc(a.lost) then
		reftext = reftext .. lostReferenceMsg
	end
	
	local err = ''
	if not (hc(a.url) and hc(a.author) and hc(a.quote) and hc(a.date) and hc(a.title)) then
		err = err .. "Error calling CiteReddit: parameters '''url''', '''author''', '''quote''', and '''date''', and '''title''' must be specified.<br />"
	end
	
	if hc(a.archiveurl) ~= hc(a.archivedate) then --xor
		err = err .. "Error calling CiteReddit: parameters '''archiveurl''' and '''archivedate''' must both be specified or both be unspecified.<br />"
	end
	
	if onmain() and err ~= '' then
		cats = cats .. '[[Category:Incomplete references]]'
	end
	
	if onmain() and not hc(a.archiveurl) then
		cats = cats .. '[[Category:Unarchived Reddit references]]'
	end
	
	return reftext, cats
end

return p