Module:Live performances by date

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

function p._main(artist, tour, year, festival, noposter) local selects = { "shows._pageName=page_name", "(CASE WHEN shows.date__precision = 1 THEN shows.date WHEN shows.date__precision = 2 THEN DATE_FORMAT(shows.date, '%Y-%d-XX') ELSE DATE_FORMAT(shows.date, '%Y-XX-XX') END)=date", "shows.venue=venue", "shows.venue_wikitext=venue_wikitext", "shows.location=location", "live_songs.name=setlist", "IF(live_show_photos._pageName IS NULL AND shows.poster IS NULL, NULL, '1')=photos", "live_banter._pageName=banter" }	local wheres = {} local headings = {}

if noposter == '' then table.insert(headings, 'Poster') table.insert(selects, 'shows.poster=poster') end table.insert(headings, 'Date') if artist == '' then table.insert(headings, 'Artist') table.insert(selects, 'shows.artist=artist, shows.featuring_artist=featuring_artist') else table.insert(wheres, '(shows.artist="' .. artist .. '" OR shows.featuring_artist="' .. artist .. '")') end if year ~= '' then table.insert(wheres, 'YEAR(shows.date)=' .. year) end if tour ~= '' then table.insert(wheres, 'shows.tour="' .. tour .. '"') end if festival ~= '' then table.insert(wheres, 'shows.festival="' .. festival .. '"') end table.insert(headings, 'Venue') table.insert(headings, 'Location') table.insert(headings, 'Setlist') table.insert(headings, 'Photos') table.insert(headings, 'Banter')

rows = cargo.query(		'shows, live_show_photos, live_songs, live_banter',		table.concat(selects, ', '),		{			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		}	)

if next(rows) == nil then return '' end

local root = mw.html.create local rootTable = root:tag('table') rootTable:addClass('wikitable sortable live-performances no-red-links jquery-tablesorter') local heading = rootTable: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] mw.logObject(row) local tr = rootTable:tag('tr')

if row['poster'] ~= nil then tr:tag('td'):wikitext('') elseif noposter == '' then tr:tag('td') end

tr:tag('td'):addClass('field_Date') :wikitext( .. row['date'] .. )

if artist == '' then local wikitext =  .. row['artist'] .. 

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

if row['venue_wikitext'] ~= nil then tr:tag('td'):wikitext(row['venue_wikitext']) else tr:tag('td'):wikitext(row['venue']) end

tr:tag('td'):wikitext(row['location'])

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 artist = frame.args[1] local tour = frame.args[2] local year = frame.args[3] local festival = frame.args[4] local noposter = frame.args[5] return p._main(artist, tour, year, festival, noposter) end

return p