Moduł:Information

Z Nonsensopedii, polskiej encyklopedii humoru

Moduł generujący tabelkę w szablonie {{Information}} i ustawiający odpowiednie własności semantyczne. Instrukcję korzystania znajdziesz na stronie Nonsensopedia:Opisywanie grafik.

Zobacz też: Moduł:InformationProvider, który pobiera informacje o plikach.


local tools = require('Module:Narzędzia')
local props = {}
local rows = {}

-- funkcje lokalne

-- funkcja pomocnicza do scalania tabel atrybutów
local function appendProps(key, value)
	props[key] = props[key] or {}
	table.insert(props[key], value)
end

local function addRow(id, name, content, trid, tdstyle)
	local row = '<tr style="vertical-align: top"'
	if not content then content = '' end
	
	if trid then
		row = row .. '; id="' .. trid .. '">'
	else
		row = row .. '>'
	end
	
	row = row .. '<td id="' .. id .. '" style="background: #ccf; text-align: right; padding-right: 0.4em; width: 15%; font-weight:bold">'
	row = row .. name .. '</td>'
	
	if tdstyle then
		row = row .. '<td style="' .. tdstyle .. '">' .. content .. '</td></tr>'
	else
		row = row .. '<td>' .. content .. '</td></tr>'
	end
	
	table.insert(rows, row)
end

local function getTable()
	local s = 
		'<table class="information-template toccolours" style="width: 100%;" cellpadding="4">'
		.. table.concat(rows)
		.. '</table>'
	return s
end

local function processParts(frame, args)
	local prows = {}
	
	local function pPart(num)
		local row = '<tr><td>' .. args['psource' .. num] .. '</td>'
		row = row .. '<td>' .. (args['pauthor' .. num] or '') .. '</td>'
		local plic = (args['plic' .. num] or 'nolic')
		plic = frame:expandTemplate{ title=plic, args={ mini=1 } }
		row = row .. '<td style="padding: 0;">' .. plic .. '</td></tr>'
		table.insert(prows, row)
	end
	
	if args['psource'] ~= nil then pPart('') end
	
	for i = 1, 50 do
		if args['psource' .. i] ~= nil then pPart(i)
		else break end
	end
	
	if #prows == 0 then return end
	
	local s = [[<table class="info-inner"><tr>
<td style="background: #ccf; font-weight:bold">Źródło</td>
<td style="background: #ccf; font-weight:bold">Autor</td>
<td style="background: #ccf; font-weight:bold">Licencja</td>
</tr>]]
	s = s .. table.concat(prows) .. '</table>'
	addRow('fileinfotpl_parts', 'Składowe', s, 'fileinforow_parts', 'padding: 0')
end

-- funkcje eksportowane
local p = {}

-- zrób cuda
function p.information(frame)
	local args = tools.getArgs(frame)
	local demo = args['demo'] ~= nil
	
	-- caption
	if args['caption'] or demo then
		appendProps('Ma podpis pliku', args['caption'])
		addRow('fileinfotpl_caption', 'Podpis', args['caption'])
	else
		appendProps('Nie ma podpisu pliku', true)
	end
	
	-- description
	if args['description'] then
		appendProps('Ma opis', args['description'])
		addRow('fileinfotpl_desc', 'Opis', args['description'])
	else
		appendProps('Nie ma opisu', true)
		addRow('fileinfotpl_desc', 'Opis', "''Brak''")
	end
	
	-- składowe
	processParts(frame, args)
	
	-- data
	if args['date'] or demo then
		-- adnotacja tekstowa, by pokazało się ładnie ostrzeżenie
		addRow('fileinfotpl_date', 'Data', '[[Ma datę::' .. args['date'] .. ']]')
	else
		appendProps('Nie ma daty', true)
	end
	
	-- źródło
	if args['source'] then
		-- TODO: parsuj sos i oznacz semantycznie
		addRow('fileinfotpl_source', 'Źródło', args['source'])
	else
		addRow('fileinfotpl_source', 'Źródło', 
			"'''Nie podano źródła.''' Uzupełnij <code>Source=</code> (''Praca własna'', adres URL strony lub pliku)")
	end
	
	-- author
	if args['author'] or demo then
		local autor = require('Module:Autor')
		aprops, s = autor.process(args['author'])
		if not demo then mw.smw.set(aprops) end
		addRow('fileinfotpl_author', 'Autor', s)
	end
	
	-- permission
	if args['permission'] or demo then
		-- TODO: smw i te sprawy
		addRow('fileinfotpl_perm', 'Licencja', args['permission'])
	end
	
	-- confirmation
	if args['confirmation'] or demo then
		appendProps('Ma potwierdzenie licencji', args['confirmation'])
		addRow('fileinfotpl_confirmation', 'Potwierdzenie licencji', args['confirmation'])
	end
	
	-- other versions
	local ov = args['other_versions']
	if (ov and ov ~= '' and ov ~= '-' and ov ~= 'none') or demo then
		-- TODO: oznaczać to semantycznie
		addRow('fileinfotpl_ver', 'Inne wersje', ov)
	end
	
	if not demo then mw.smw.set(props) end
	return getTable()
end

return p