Moduuli:Sitaatti

Jedipediasta, vapaasta Tähtien sota-tietosanakirjasta tänään, 29. maaliskuuta 2024
Siirry navigaatioonSiirry hakuun

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Sitaatti/ohje

-- This module implements [[Template:Quote]].

local p = {}

function p._main(args)
	-- Create the surrounding div.
	local root = mw.html.create('div')
	root
		:addClass('quote')
	
	-- Start a new line and add the span containing the quote.
	root
		:newline()
		:wikitext(':')
	local quoteSpan = root:tag('span')
	if args[3] and string.find(args[3], '-ref-') == nil then
		quoteSpan:attr('title', 'Lähde: ' .. args[3])
	end
	if args.formatting then
		quoteSpan:wikitext(args[1] or '{{{1}}}')
	else
		quoteSpan
			:wikitext(string.format(
				'%s%s%s%s%s',
				args.noquote and '' or args.quotestart and '' or args.translated and '«' or '”',
				args.italics and '' or "''",
				args[1] or '{{{1}}}',
				args.italics and '' or "''",
				args.trans and '' or args.quoteend and '' or args.translated and '»' or '”'
			))
	end
	
	-- Add the attribution.
	root
		:newline()
		:wikitext(':―')
		:wikitext(args[2] or '{{{2}}}')

	-- Add everything that needs to go inside a noprint span.
	if args['ääni'] or args.url or args[3] then
		local noprintSpan = root:tag('span'):addClass('noprint')

		-- Audio link
		if args['ääni'] then
			noprintSpan
				:wikitext(' — [[Tiedosto:Gnome-speakernotes.png|20px|(ääni)|link=]]')
				:wikitext(string.format(
					'[[Media:%s|Kuuntele]] %s<small>([[:Tiedosto:%s|kuvaus]])</small>',
					args['ääni'], args.fi and '' or '<span style="color:#808080">(englanniksi)</span> ', args['ääni']
				))
		end

		-- Source link
		if args.url or args[3] then
			if args[3] and string.find(args[3], '-ref-') ~= nil then
				noprintSpan:wikitext(args[3])
			else
				local sourceSup = noprintSpan:tag('sup')
				local display = mw.text.nowiki('[lähde]')
				if args.url then
					sourceSup
						:addClass('plainlinks')
						:wikitext(string.format('[%s %s]', args.url, display))
				else
					-- We have already checked that args[3] is present.
					sourceSup:wikitext(string.format('[[%s|%s]]', args[3], display))
				end
			end
		end
	end

	-- Add the tracking category. The function passed to
	-- [[Module:SpecialCategorizer]] is called if the page being processed is
	-- not blacklisted.
	if not args.url and not args[3] then
		if mw.title.getCurrentTitle():inNamespace(0) or mw.title.getCurrentTitle():inNamespace(4) then
			-- The category link is split up so that this page isn't categorised.
			root:wikitext('[[' .. 'Luokka:Lähteettömät sitaatit]]')
		end
	end

	return tostring(root)
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