Modul:Kép

A Wikipédiából, a szabad enciklopédiából

Kép[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

require('strict')

local p = {}

local getArgs = require('Modul:Arguments').getArgs

local directions = {
	right  = 'right',
	jobbra = 'right',
	jobb   = 'right',
	left   = 'left',
	balra  = 'left',
	bal    = 'left',
	[0]    = 'right'
}

local function getWidth(size, file)
	if type(size) ~= 'string' then
		return size
	end
	if tonumber(size) then
		return size .. 'px'
	end
	local height = tonumber(size:match('^x(%d+)px$'))
	if not height then
		return size
	end
	if mw.ustring.sub(mw.title.getCurrentTitle().prefixedText, 0, 21) == 'Wikipédia:Évfordulók/' then
		return size
	end
	local title = mw.title.new('Fájl:' .. file)
	if not title or not title.file.exists then
		return size
	end
	local filewidth  = title.file.width
	local fileheight = title.file.height
	local width = height * filewidth / fileheight
	return tostring(math.floor(width)) .. 'px'
end

function p.main(frame)
	local args = getArgs(frame)
	local file = args[1] or args['kép'] or '{{{kép}}}'
	local size = args[2] or args['méret'] or '{{{méret}}}'
	local align= args[3] or args['oldal']
	align = directions[align] or directions[0]
	local caption = args[4] or args['szöveg'] or ''
	local width = getWidth(size, file) -- for IE11, it doesn’t support width:min-content
	local class = 'image modul-kep modul-kep-float' .. align .. (args.clear and ' modul-kep-clear' or '')
	local style = ('width:%s; %s'):format(width, args.style or '')
	local templatestyles 
	return (('<div class="%s" style="%s">'):format(class, style)
		.. mw.getCurrentFrame():extensionTag('templatestyles', nil, {src = 'Modul:Kép/styles.css'})
		.. ('<div>[[Fájl:%s|%s|%s]]</div><small>%s</small>'):format(file, size, caption, caption)
		.. '</div>')
end

return p