Module:License/sandbox

require('strict')

local p = {} --p stands for package

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

function p._license(args)
	local frame = mw.getCurrentFrame()
	
	-- Parameters
	local text = frame:preprocess(args.text or '{{{text}}}')
	local image = args.image
	local image_r = args.image_r or args['image-r']
	local image_size = args.image_size or args['image-size'] or 'x48px'
	local image_r_size = args.image_r_size or args['image-r-size'] or image_size
	local warning = args.warning
	
	local category = args.category
	local category2 = args.category2
	if category == '' then
		category = nil
	end
	if category2 == '' then
		category2 = nil
	end
	
	-- license banner
	local leftField = mw.html.create('div')
	if image then
		leftField
			:newline()
			:tag('span')
				:addClass('imageLeft')
				:wikitext('[[File:' .. image .. '|' .. image_size .. '|alt=|link=]]')
				:done()
			:newline()
	else
		leftField
			:newline()
			:tag('span')
				:addClass('noimageLeft')
				:done()
			:newline()
	end
	
	local centerField = mw.html.create('div')
		:tag('div')
			:newline()
			:wikitext(text)
			:newline()
			:allDone()
	if warning then
		centerField
			:tag('div')
				:tag('div')
					:newline()
					:wikitext('[[File:OOjs UI icon alert destructive black-darkred.svg|35px]]')
					:newline()
					:done()
				:tag('div')
					:newline()
					:wikitext(warning)
					:allDone()
	end
	
	local rightField = mw.html.create('div')
	if image_r then
		rightField
			:newline()
			:tag('span')
				:addClass('imageRight')
				:wikitext('[[File:' .. image_r .. '|' .. image_r_size .. '|alt=|link=]]')
				:done()
			:newline()
	else
		rightField
			:newline()
			:tag('span')
				:addClass('noimageRight')
				:done()
			:newline()
	end
	
	local licenseBanner = mw.html.create('div')
		:tag('div')
			:tag('div')
				:node(leftField)
				:node(centerField)
				:node(rightField)
				:allDone()
	
	-- Commons auto-detection
	local commonsAutoDetection = mw.html.create('div')
		:addClass('licensetpl')
		:newline()
		:tag('span')
			:addClass('licensetpl_short')
			:wikitext('Public domain')
			:done()
		:tag('span')
			:addClass('licensetpl_long')
			:wikitext('Public domain')
			:done()
		:tag('span')
			:addClass('licensetpl_link_req')
			:wikitext('false')
			:done()
		:tag('span')
			:addClass('licensetpl_attr_req')
			:wikitext('false')
			:done()
		:newline()
		:allDone()
	
	-- Categorization
	local namespace = args.namespace or mw.title.getCurrentTitle().nsText
	local noCatNamespaces = {
		['Help'] = true,
		['Help talk'] = true,
		['Template'] = true,
		['Template talk'] = true,
		['Wikisource'] = true,
		['Wikisource talk'] = true,
		['Module'] = true,
		['Module talk'] = true,
		['Category'] = true,
		['Category talk'] = true
	}
	local categoryContent = ''
	if not noCatNamespaces[namespace] then
		if namespace == 'Author' or namespace == 'Author talk' then
			if category then
				category = 'Author-' .. category
			end
			if category2 then
				category2 = 'Author-' .. category2
			end
		end
		if category then
			category = '[[Category:' .. category .. ']]'
		end
		if category2 then
			category2 = '[[Category:' .. category2 .. ']]'
		end
		categoryContent = (category or '') .. (category2 or '')
	end
	
	-- licenseContainer is the class that styles depend on
	local overallDiv = mw.html.create('div')
		:addClass('licenseContainer licenseBanner dynlayout-exempt')
		:addClass(args.class)
		:attr('id', args.id)
		:node(licenseBanner)
		:node(commonsAutoDetection)
		:wikitext(categoryContent)
	
	local templateStyles = frame:extensionTag('templatestyles', '', {src = 'Template:License/styles.css'})
	return templateStyles .. tostring(overallDiv)
end

function p.license(frame)
	return p._license(getArgs(frame))
end

return p
Category:Module sandboxes