Module:Tour personnel

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

local function getWikitext(person, personRow) local urlParts = {} table.insert(urlParts, mw.uri.encode('shows.lineup HOLDS "' .. person .. '"')) if personRow['catalog_artist'] ~= nil then table.insert(urlParts, mw.uri.encode('shows.artist="' .. personRow['catalog_artist'] .. '"')) end if personRow['tour'] ~= nil then table.insert(urlParts, mw.uri.encode('shows.tour="' .. personRow['tour'] .. '"')) end if personRow['year'] ~= nil then table.insert(urlParts, 'YEAR(shows.year)=' .. personRow['year']) end if personRow['festival'] ~= nil then table.insert(urlParts, mw.uri.encode('shows.festival="' .. personRow['festival'] .. '"')) end

local url = "https://spcodex.wiki/wiki/Special:CargoQuery?tables=shows%2C+live_show_photos%2C+live_show_videos&fields=shows._pageName%3Dpage_name%2C+shows.date%3Ddate%2C+shows.artist%3Dartist%2C+shows.featuring_artist%3Dfeaturing_artist%2C+shows.venue%3Dvenue%2C+shows.location%3Dlocation%2C+shows.festival%3Dfestival%2C+shows.notes%3Dnotes%2C+IF%28live_show_photos._pageName+IS+NULL+AND+shows.poster+IS+NULL%2C+%27%27%2C+%271%27%29%3Dphotos%2C+live_show_videos._ID%3Dvideo&where=" url = url .. table.concat(urlParts, '%20AND%20') .. '&join_on=shows._pageName%3Dlive_show_photos._pageName%2C+shows._pageName%3Dlive_show_videos._pageName&group_by=shows._pageName&having=&order_by%5B0%5D=shows.date+ASC&order_by_options%5B0%5D=ASC&limit=1000&offset=&format=template&template=Live+show+row&named+args=yes' out = '' .. person .. ' ([' .. url .. ' ' .. personRow['count']	if tonumber(personRow['count']) == 1 then		out = out .. ' show])' else out = out .. ' shows])'	end

return out end

function p._main(artist, tour, year, festival) local selects = {} local wheres = {}

if artist ~= '' then table.insert(selects, 'shows.artist=artist, CONCAT("", "' .. artist .. '")=catalog_artist') table.insert(wheres, '(shows.artist = "' .. artist .. '" OR shows.featuring_artist="' .. artist .. '")') end if tour ~= '' then table.insert(selects, 'shows.tour=tour') table.insert(wheres, 'shows.tour="' .. tour .. '"') end if year ~= '' then table.insert(selects, 'YEAR(shows.date)=year') table.insert(wheres, 'YEAR(shows.date)=' .. year) end if festival ~= '' then table.insert(selects, 'shows.festival=festival') table.insert(wheres, 'shows.festival="' .. festival .. '"') end

personRows = cargo.query(		'shows',		'lineup=person, COUNT(_ID)=count, ' .. table.concat(selects, ', '),		{			where = table.concat(wheres, ' AND '),			groupBy = 'lineup',			orderBy = 'Count DESC, person ASC',			limit = 250,			offset = 0		}	)

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

local root = mw.html.create local ul = root:tag('ul')

for r = 1, #personRows do		local personRow = personRows[r] local person = personRow['person'] if person ~= 'others' and person ~= nil then ul:tag('li'):wikitext(getWikitext(person, personRow)) 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] return p._main(artist, tour, year, festival) end

return p