Jump to content

Module:Infobox military conflict

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jackmcbarn (talk | contribs) at 18:41, 5 October 2014 (begin work on a rewrite of Template:Infobox military conflict). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('Module:No globals')

local p = {}

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

function p.main(frame)
	local args = getArgs(frame, {wrappers = 'Template:Infobox military conflict'})

	local combatants
	if args.combatants then
		combatants = tonumber(args.combatants)
	else
		combatants = args.combatant3 and 3 or 2
	end

	local builder = mw.html.create()
	if args.campaignbox then
		builder = builder:tag('table')
			:css('float', 'right')
			:css('clear', 'right')
			:css('background', 'transparent')
			:css('margin', 0)
			:css('padding', 0)
			:tag('tr'):tag('td')
	end
	builder:wikitext('<table ' .. frame:expandTemplate{title = 'WPMILHIST Infobox style', args = {'main_box', 'vevent'}} .. '>')
	builder:tag('tr')
		:wikitext(string.format('<th class="summary" colspan="%d" %s>%s</th>',
			combatants,
			frame:expandTemplate{title = 'WPMILHIST Infobox style', args = {'header_bar'}},
			args.conflict or mw.title.getCurrentTitle().text
		))
	if args.partof then
		builder:tag('tr')
			:wikitext(string.format('<td colspan="%d" %s>Part of %s</td>',
				combatants,
				frame:expandTemplate{title = 'WPMILHIST Infobox style', args = {'sub_header_bar'}},
				args.partof
			))
	end
	if args.image then
		local alt
		if args.caption then
			alt = (args.alt or '') .. '<br />' .. args.caption
		else
			alt = args.alt
		end
		local imageArgs = {
			image = args.image,
			size = args.image_size,
			sizedefault = 'frameless',
			upright = 1,
			alt = alt
		}
		builder:tag('tr')
			:wikitext(string.format('<td colspan="%d" %s>%s</td>',
				combatants,
				frame:expandTemplate{title = 'WPMILHIST Infobox style', args = {'image_box'}},
				InfoboxImage{args = imageArgs}
			))
	end
end

return p