Modul:Babel

De la Wikipedia, enciclopedia liberă

Documentația acestui modul poate fi creată la Modul:Babel/doc

local p = {}

local getArgs

function p.main(frame)
	if not getArgs then
		getArgs = require('Modul:Arguments').getArgs
	end
	local args = getArgs(frame, {wrappers = 'Format:Babel'})
	
	local ret = mw.html.create('table')
			:addClass('userboxes')
			:css({
				float = args.aliniere or 'right',
				['margin-left'] = (args['stângă'] or '1') .. 'em',
				['margin-right'] = (args['dreaptă'] or '1') .. 'em',
				['margin-bottom'] = (args['adânc'] or '0') .. 'em',
				width = (args['întindere'] or '248') .. 'px',
				clear = args.aliniere or 'right',
				color = args['culoare text'] or '#000000',
				border = (args['culoare margin'] or '#99B3FF') .. ' solid ' .. (args.solid or 1)..'px'
			})
	
	if args['umbră'] and string.lower(args['umbră']) == 'yes' then
		ret:css({
			['box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)',
			['-mox-box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)',
			['-webkit-box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)' 
		})
	end
	
	ret:cssText(args['css adițional'] or '')
	
	local color = args.culoare or 'inherit'
	local row1 = ret:tag('tr')
	local row2 = ret:tag('tr')
	local row3 = ret:tag('tr')
	
	local body_cells = row2:tag('td')
		:css('vertical-align', 'middle !important')
	
	local userboxes
	-- Special message for when first argument is blank; otherwise treat it as normal
	if args[1] and args[1]:find('%S') then
		userboxes = frame:preprocess('{{Utilizator '..args[1]..'}}')
	else
		userboxes = '<div style="text-align:center">Acest utilizator nu poate nici să vorbească, nici să scrie în vreo limbă. Are nevoie de ajutor.</div>'
	end
	
	body_cells:wikitext(userboxes)
	
	-- "remove" args[1] so it isn't looked at in the loop
	-- table.remove(args,1) doesn't produce desired result
	args[1] = ''
	
	-- Keep track of how many columns are in this table
	local col_span = 1
	for _, v in ipairs( args ) do
		-- ! indicates a new cell should be created
		if v:find('%S') and v ~= '!' then
			body_cells:wikitext( frame:preprocess('{{Utilizator '..v..'}}') )
		-- Recycling body_cells for <td>
		elseif v and v == '!' then
			col_span = col_span + 1
			body_cells:done()
			body_cells = row2:tag('td')
		end
	end
	
	row1:tag('th')
		:css({ ['background-color'] = color,
			['text-align'] = 'center' })
		:attr('colspan',col_span)
		:wikitext( args.titlu or '[[Wikipedia:Babel|Turnul Babel]]' )
		:done()

	row3:tag('td')
		:css({ ['background-color'] = color,
			['text-align'] = 'center' })
		:attr('colspan',col_span)
		:wikitext( args.subsol or '[[:Categorie:Wikipediști|Caută utilizatori<br />după diverse criterii]]' )
		:done()
	
	if args['cutii_speciale'] then
		body_cells:wikitext(args['cutii_speciale'])
	end
	
	body_cells:done()
	
	return tostring(ret)
end

return p