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 07:15, 3 June 2023 (cleanup). 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 warnings = {}

	-- Preprocessing
	local future_event = args['future'] or args['current'] == 'yes' and true or false
	local tense = args['future'] == 'yes' and 'will be ' or 'was '
	local live_msg = tense ..'broadcast prior to the pay-per-view on '
	local taped_msg = 'was taped for a future broadcast of '
	local notes = {
		dark = { 'D', 'was a [[dark match]]' },
		pre = { 'P', tense ..'broadcast on the pre-show' },
		aewd = { 'AD', taped_msg ..'<i>[[AEW Dark]]</i>' },
		aewde = { 'DE', taped_msg ..'<i>[[AEW Dark: Elevation]]</i>' },
		ffa = { 'F', live_msg .. '<i>[[WWE Free for All|Free for All]]</i>' },
		fusion = { 'FT', taped_msg ..'<i>[[MLW Fusion|Fusion]]</i>' },
		fusionlive = { 'F', live_msg ..'<i>[[MLW Fusion|Fusion]]</i>' },
		heat = { 'H', live_msg ..'<i>[[WWE Heat|Sunday Night Heat]]</i>' },
		regnxt = { 'N', taped_msg ..'<i>[[WWE NXT|NXT]]</i>' },
		regnxtuk = { 'UK', taped_msg ..'<i>[[WWE NXT UK|NXT UK]]</i>' },
		slam = { 'S', live_msg ..'<i>[[WWF Sunday Night Slam|Sunday Night Slam]]</i>' },
		wcwme = { 'ME', live_msg ..'<i>[[WCW Main Event|Main Event]]</i>' },
		wcwsn = { 'SN', live_msg ..'<i>[[WCW Saturday Night|Saturday Night]]</i>' },
		xplosion = { 'X', taped_msg ..'<i>[[Impact! Xplosion|Xplosion]]</i>' }
	}
	local notes_active = {}
	local notes_active_filter = {}
	local times_active
	local matches = {}
	local row_num = 1

	-- Fetch old note parameters, to be deprecated
	for k, v in pairs(args) do
		if v == 'yes' then
			local note_key, note_num = string.match(k, "(%a*)(%d*)")
			if notes[note_key] ~= nil then
				args['note'.. note_num] = note_key
			end
		end
	end

	while args['match'.. row_num] ~= nil do
		local row_note = args['note'.. row_num]
		if row_note ~= nil then
			if notes[row_note] ~= nil then
				if notes_active_filter[row_note] == nil then -- Filter duplicates for Key
					notes_active_filter[row_note] = true
					table.insert(notes_active, row_note)
				end
				row_note = notes[row_note][1]
			else -- Warning: invalid note
				table.insert(warnings, '<b>note'.. row_num ..'</b> with "'.. row_note ..'"')
				row_note = nil
			end
		end

		local row_time = args['time'.. row_num]
		if row_time ~= nil then
			row_time = string.lower(row_time)
			if row_time == '—'
			or row_time == '–'
			or row_time == '-'
			or row_time == 'n/a'
			or row_time == 'unknown' then
				-- Consistent formatting for unknown values
				row_time = nil
			elseif not times_active then
				times_active = true
			end
		end
		
		table.insert(matches, {row_note, args['match'.. row_num], args['stip'.. row_num], row_time})
		row_num = row_num+1
	end

	-- Table start
	local root = mw.html.create('table')
		:addClass('wikitable')
		:css('margin', args['align'] == 'center' and '1em auto !important' 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', #notes_active > 0 and '2' or nil)
			:wikitext('No.')
			:done()
		:tag('th')
			:attr('scope', 'col')
			:wikitext(future_event and 'Matches*' or 'Results' .. (args['results'] or '')) -- Optional reference
			:done()
		:tag('th')
			:attr('scope', 'col')
			:wikitext('Stipulations')

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

	-- Matches
	for num, v in ipairs(matches) do
		local row = root:tag('tr')

		-- Note
		if #notes_active > 0 then
			if v[1] ~= nil then
				row
				:tag('th')
					:attr('scope', 'row')
					:tag('span')
						:css('font-size', '90%')
						:wikitext(v[1])
			else
				-- Blank col to maintain consistent alignment of match number
				-- Hide border to draw less attention to blank col
				row
				:tag('th')
					:attr('scope', 'row')
					:css('border-right-color', 'transparent')
			end
		end

		row
		-- Match number
		:tag('th')
			:attr('scope', 'row')
			:wikitext(num)
			:done()
		-- Match
		:tag('td')
			:wikitext(v[2])
			:done()
		-- Stipulation
		:tag('td')
			:wikitext(v[3])

		-- Time
		if times_active then
			if v[4] ~= nil then
				row
				:tag('td')
					:css('text-align', 'center')
					:wikitext(v[4])
			else -- mirror Template:N/a
				row
				:tag('td')
					:addClass('table-na')
					:css('text-align', 'center')
					:css('background-color', '#ececec')
					:css('color', '#2C2C2C')
					:wikitext('—')
			end
		end
	end

	-- Key
	-- Optionally hide key or champions note
	if args['hide'] ~= 'key'
	and args['hide'] ~= '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 !important')
					:css('padding', '0')
					:css('border-spacing', '0')
					:css('line-height', '1.4em')

		if args['hide'] ~= 'champions'
		and args['hide'] ~= 'champs' then
			key
			:tag('tr')
				:tag('td')
					:css('text-align', 'right')
					:wikitext('(c)&nbsp;')
					:done()
				:tag('td')
					:wikitext('– the champion(s) heading into the match')
		end

		for _, v in ipairs(notes_active) do
			key
			:tag('tr')
				:tag('td')
					:css('text-align', 'right')
					:tag('span')
						:css('font-size', '90%')
						:css('font-weight', 'bold')
						:wikitext(notes[v][1] ..'&nbsp;')
						:done()
					:done()
				:tag('td')
					:wikitext('– the match '.. notes[v][2])
		end

		if future_event then
			key
			:tag('tr')
				:tag('td')
					:attr('colspan', '2')
					:css('text-align', 'center')
					:css('font-size', '85%')
					:css('font-weight', 'bold')
					:wikitext('*Card subject to change')
		end
	end

	-- Preview warnings and tracking
	if args['future'] ~= nil
	and args['future'] ~= 'yes' then
		table.insert(warnings, '<b>future</b> with "'.. args['future'] ..'" ("yes" expected)')
	end

	if args['current'] ~= nil
	and args['current'] ~= 'yes' then
		table.insert(warnings, '<b>current</b> with "'.. args['current'] ..'" ("yes" expected)')
	end
	
	if args['align'] ~= nil
	and args['align'] ~= 'center' then
		table.insert(warnings, '<b>align</b> with "'.. args['align'] ..'" ("center" expected)')
	end

	if args['hide'] ~= nil
	and args['hide'] ~= 'key'
	and args['hide'] ~= 'all'
	and args['hide'] ~= 'champions'
	and args['hide'] ~= 'champs' then
		table.insert(warnings, '<b>hide</b> with "'.. args['hide'] ..'" ("key" or "champions" expected)')
	end

	if #warnings > 0 then
		root = require('Module:If preview')._warning({
			'Invalid parameter value at '.. table.concat(warnings, '; ') ..'.'
		}) .. tostring(root)
		-- '[[Category:Pages using professional wrestling results table with invalid parameter values]]'
	end

	return root
end

return p