Module:Venue performances

local p = {} local cargo = mw.ext.cargo

function p._main(venue, location) local wheres = { 'shows.venue = "' .. venue .. '"' } if location ~= '' then table.insert(wheres, 'location = "' .. location .. '"') end

local rows = cargo.query(		'live_songs, shows, live_show_photos, live_banter',		"shows.poster=poster, shows._pageName=page_name, shows.date=date, shows.artist=artist, shows.featuring_artist=featuring_artist, live_songs.name=setlist, IF(live_show_photos._pageName IS NULL AND shows.poster IS NULL, '', '1')=photos, live_banter._pageName=banter, notes=notes",		{			where = table.concat(wheres, ' AND '),			join = 'shows._pageName = live_songs._pageName, shows._pageName=live_show_photos._pageName, shows._pageName=live_banter._pageName',			groupBy = 'shows._pageName',			orderBy = 'shows.date ASC',			limit = 250,			offset = 0		}	)

-- Build data structure local has_image = false local has_notes = false for r = 1, #rows do		local row = rows[r] row['image'] = rows[r]['poster'] or rows[r]['image'] if row['image'] ~= nil then has_image = true end if row['notes'] ~= nil then has_notes = true end end

local headings = {} if has_image then table.insert(headings, 'Poster') end table.insert(headings, 'Date') table.insert(headings, 'Artist') table.insert(headings, 'Setlist') table.insert(headings, 'Photos') table.insert(headings, 'Banter') if has_notes then table.insert(headings, 'Notes') end

-- Build the actual HTML local root = mw.html.create('table') :addClass('wikitable sortable venue-performances no-red-links jquery-tablesorter')

local heading = root:tag('tr') for r = 1, #headings do		heading:tag('th') :addClass('headerSort') :attr('tabindex', 0) :attr('role', 'columnheader button') :attr('title', 'Sort ascending') :wikitext(headings[r]) end

for r = 1, #rows do		local row = rows[r] local tr = root:tag('tr')

if has_image then tr:tag('td'):wikitext(') end tr:tag('td'):addClass('field_Date') :wikitext( .. row['date'] .. )

local wikitext =  .. row['artist'] ..  if row['featuring_artist'] ~= nil then wikitext = wikitext .. " featuring " .. row['featuring_artist'] .. " " end tr:tag('td'):wikitext(wikitext)

local check_mark = "" if row['setlist'] ~= nil then tr:tag('td'):wikitext(check_mark) else tr:tag('td') end if row['photos'] ~= nil then tr:tag('td'):wikitext(check_mark) else tr:tag('td') end if row['banter'] ~= nil then tr:tag('td'):wikitext(check_mark) else tr:tag('td') end end

return tostring(root) end

function p.main(frame) local venue = frame.args[1] local location = frame.args[2] return p._main(venue, location) end

return p