Jump to content

Module:Professional wrestling results table

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Prefall (talk | contribs) at 01:53, 27 May 2023 (test to see visual differences). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	local future_event = false
	local future_note = 'took'
	local results_label = 'Results'
	local times_col = args['time1'] ~= nil and true or false
	local notes = {}
	local notes_active = {}
	local notes_active_filter = {}
	local row_num = 1
	local live_msg = 'was broadcast prior to the pay-per-view on '
	local taped_msg = 'was taped for broadcast on a future episode of '
	local error_msg = {}

	-- Preprocessing
	if args['future'] == 'yes' then
		future_event = true
		future_note = 'will take'
		results_label = 'Matches *'
	end

	notes = {
		dark = { -- Dark match
			id = 'D',
			key = 'was a [[dark match]]'
		},
		pre = { -- Pre-show
			id = 'P',
			key = future_note ..' place on the pre-show'
		},
		aewd = { -- AEW Dark
			id = 'AD',
			key = taped_msg ..'<i>[[AEW Dark]]</i>'
		},
		aewde = { -- AEW Dark: Elevation
			id = 'DE',
			key = taped_msg ..'<i>[[AEW Dark: Elevation]]</i>'
		},
		ffa = { -- WWE Free for All
			id = 'F',
			key = live_msg .. '<i>[[WWE Free for All|Free for All]]</i>'
		},
		fusion = { -- MLW Fusion (taped)
			id = 'FT',
			key = taped_msg ..'<i>[[MLW Fusion|Fusion]]</i>'
		},
		fusionlive = { -- MLW Fusion (live)
			id = 'F',
			key = live_msg ..'<i>[[MLW Fusion|Fusion]]</i>'
		},
		heat = { -- WWE Sunday Night Heat
			id = 'H',
			key = live_msg ..'<i>[[WWE Heat|Sunday Night Heat]]</i>'
		},
		regnxt = { -- WWE NXT (taped)
			id = 'N',
			key = taped_msg ..'<i>[[WWE NXT|NXT]]</i>'
		},
		regnxtuk = { -- WWE NXT UK (taped)
			id = 'UK',
			key = taped_msg ..'<i>[[WWE NXT UK|NXT UK]]</i>'
		},
		slam = { -- WWF Sunday Night Slam
			id = 'S',
			key = live_msg ..'<i>[[WWF Sunday Night Slam|Sunday Night Slam]]</i>'
		},
		wcwme = { -- WCW Main Event
			id = 'ME',
			key = live_msg ..'<i>[[WCW Main Event|Main Event]]</i>'
		},
		wcwsn = { -- WCW Saturday Night
			id = 'SN',
			key = live_msg ..'<i>[[WCW Saturday Night|Saturday Night]]</i>'
		},
		xplosion = { -- Impact! Xplosion
			id = 'X',
			key = taped_msg ..'<i>[[Impact! Xplosion|Xplosion]]</i>'
		}
	}

	-- Table start
	local root = mw.html.create('table')
		:addClass('wikitable')
		:css('margin', args['align'] == 'center' and '1em auto' or nil) -- Optional center align

	if args['caption'] ~= nil then
		root
		:tag('caption')
			:wikitext(args['caption'])
	end

	-- Header
	local header = root:tag('tr')

	header
		:tag('th')
			:attr('scope', 'col')
			:attr('colspan', '2')
			:wikitext('No.')
			:done()
		:tag('th')
			:attr('scope', 'col')
			:wikitext(results_label .. (args['results'] or '')) -- Optional reference
			:done()
		:tag('th')
			:attr('scope', 'col')
			:wikitext('Stipulations')

	if times_col then
		header
		:tag('th')
			:attr('scope', 'col')
			:wikitext('Times'.. (args['times'] or '')) -- Optional reference
	end

	-- Matches
	while args['match'..row_num] ~= nil do
		local row = root:tag('tr')

		-- Notes (new)
		local row_note = args['note'..row_num]
		if row_note ~= nil then
			if notes[row_note] ~= nil then
				table.insert(notes_active, row_note) -- For sorting
				row
				:tag('th')
					:attr('scope', 'row')
					:css('font-size', '90%')
					:wikitext(notes[row_note].id)
			else -- Error: invalid note
				table.insert(error_msg, ' note'.. row_num ..' with args "'.. row_note ..'".')
				row_note = nil
			end
		else -- Notes (old)
			for k,v in pairs(notes) do
				if args[k .. row_num] == 'yes' then
					table.insert(notes_active, k) -- For sorting
					row
					:tag('th')
						:attr('scope', 'row')
						:css('font-size', '90%')
						:wikitext(v.id)
					row_note = k
					break
				end
			end
		end

		row
		-- Match number
		:tag('th')
			:attr('scope', 'row')
			:attr('colspan', row_note == nil and '2' or nil)
			:css('text-align', 'right')
			:wikitext(row_num)
			:done()
		-- Match
		:tag('td')
			:wikitext(args['match'..row_num])
			:done()
		-- Stipulation
		:tag('td')
			:wikitext(args['stip'..row_num])
		-- Time
		if times_col then
			row
			:tag('td')
				:attr('align', 'center')
				:wikitext(args['time'..row_num] or '–')
		end

		row_num = row_num+1
	end

	-- Key
	-- Optionally hide key or champion's note
	if args['hide'] ~= ('key' or 'all') then
		local key = root:tag('tr')
			:tag('th')
				:attr('scope', 'row')
				:attr('colspan', '5')
				:css('border-top', 'solid 2px #aaa')
				:css('font-weight', 'normal')
				:css('text-align', 'left')
				:tag('table')
					:css('margin', '0 auto')
					:css('padding', '0')
					:css('border-spacing', '0')
					:css('line-height', '1.4em')

		if args['hide'] ~= ('champions' or 'champs') then
			key
			:tag('tr')
				:tag('td')
					:attr('align', 'right')
					:wikitext('(c)&nbsp;')
					:done()
				:tag('td')
					:wikitext('– refers to the champion(s) heading into the match')
		end
		for _,v in ipairs(notes_active) do
			if notes_active_filter[v] == nil then -- Filter duplicates
				notes_active_filter[v] = true
				key
				:tag('tr')
					:tag('td')
						:attr('align', 'right')
						:css('font-size', '90%')
						:css('font-weight', 'bold')
						:wikitext(notes[v].id ..'&nbsp;')
						:done()
					:tag('td')
						:wikitext('– indicates the match '.. notes[v].key)
			end
		end
		if future_event then
			key
			:tag('tr')
				:tag('td')
					:attr('align', 'center')
					:attr('colspan', '2')
					:css('font-size', '85%')
					:css('font-weight', 'bold')
					:wikitext('* Card subject to change')
		end
	end

	-- Display errors
	if next(error_msg) ~= nil then
		root
		:tag('strong')
			:addClass('error')
			:wikitext('Error: invalid value at '.. table.concat(error_msg))
		-- Add tracking category later
	end

	return root
end

return p