Jump to content
Toggle menu
  • 799 articles
  • 4.8K files
  • 4 users
  • 64.6K edits
2b2t Uncensored
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

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

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 p = {}
local r = {}

local lostReferenceMsg = '<sup 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</sup>'

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 = ref .. cat, args = opts}
end

p.reflist = function(frame)
	local args = frame:getParent().args
	local div = mw.html.create('div')
	div:wikitext(frame:extensionTag{name = 'references', args = {group = args.group}})
	div:addClass('references-small')
	if not yn(args.quotes) then
		div:addClass('hideQuotes')
	end
	if args.colwidth then
		div :css({  ['-moz-column-width'] = args.colwidth,
					['-webkit-column-width'] = args.colwidth,
					['column-width'] = args.colwidth
				})
	end
	
	return div
end

p.generalref = function(frame)
	return reftag(frame, 'general')
end

r.general = function(a)
	local ref = ''
	local c = ''
	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
			ref = ref .. '[' .. a.authorlink
			if str ~= '' then
				ref = ref .. ' ' .. str
			end
			ref = ref .. ']'
		else
			ref = ref .. str
		end
		
		if hc(a.coauthors) then
			ref = ref .. '; ' .. a.coauthors
		end
		
		ref = ref .. '. '
	end
	
	if hc(a.title) then
		if hc(a.archiveurl) then
			ref = ref .. '[' .. a.archiveurl .. ' ' .. a.title .. ']'
		elseif hc(a.url) then
			ref = ref .. '[' .. a.url .. ' ' .. a.title .. ']'
		end
	end
	
	if hc(a.language) then
		local span =	mw.html.create('span')
							:css({['font-size'] = '0.95em', color = '#555', position = 'relative', ['font-weight'] = 'bold'})
							:wikitext('(' .. a.language .. ')')
		ref = ref .. ' ' .. tostring(span)
	end
	
	if hc(a.format) then
		ref = ref .. ' (' .. a.format .. ')'
	end
	
	if hc(a.work) then
		ref = ref .. ". ''" .. a.work .. "''"
	end
	
	if hc(a.pages) then
		ref = ref .. ' pp. ' .. a.pages
	end
	
	if hc(a.publisher) then
		ref = ref .. '. ' .. a.publisher
	end
	
	if hc(a.date) then
		ref = ref .. '. ' .. a.date
	elseif hc(a.year) then
		if hc(a.month) then
			ref = ref .. '. ' .. a.month .. ' ' .. a.year
		else
			ref = ref .. '. ' .. a.year
		end
	end
	
	if ref ~= '' then
		ref = ref .. '.'
	end
	
	if hc(a.archivedate) then
		ref = ref .. ' (Archived from [' .. a.url .. ' the original] on ' .. a.archivedate .. '.)'
	end
	
	if hc(a.quote) then
		ref = ref .. ' "' .. a.quote .. '"'
	end
	
	if hc(a.notes) then
		ref = ref .. ' ' .. a.notes
	end
	if hc(a.lost) then
		ref = ref .. 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 not (hc(a.archiveurl) and hc(a.archivedate)) then
		ref = err .. ref .. mw.getCurrentFrame():expandTemplate{title = 'RefDate', args = { (a.accessdate or ''), '180'} }
	end
	
	if onmain() and err ~= '' then
		c = c .. '[[Category:Incomplete references]]'
	end
	
	if onmain() and not hc(a.archiveurl) then
		if hc(a.lost) then
			c = c .. '[[Category:Lost web references]]'
		else
			c = c .. '[[Category:Unarchived web references]]'
		end
	end
	return ref, c
end

return p