Module:References

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 = 'Lost reference '

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. " 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. " 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 .. ''	end if onmain and not hc(a.archiveurl) then if hc(a.lost) then c = c .. ''		else c = c .. ''		end end return ref, c end

return p