Module:PlayerListChart

local util_text = require('Module:Text') local util_cargo = require('Module:CargoUtil')

local Team = require('Module:Team').team local Country = require('Module:Country').main

local sep = '%s*,%s*'

local DEFAULTS = { tables = 'InfoboxPlayer', groupBy = '_pageName', orderBy='ID', limit = '999' }

local FIELDS = { 'InfoboxPlayer._pageName=_pageName', 'InfoboxPlayer.ID=ID', 'InfoboxPlayer.NameFull=NameFull', 'InfoboxPlayer.Team=Team', 'InfoboxPlayer.TeamLast=TeamLast', 'InfoboxPlayer.Country=Country', 'InfoboxPlayer.Role=Role', 'InfoboxPlayer.Stream=Stream', 'InfoboxPlayer.Twitter=Twitter', 'InfoboxPlayer.Birthdate=Birthdate', 'InfoboxPlayer.Age=Age' } local FIELDORDER = { 'ID', 'NameFull', 'Team', 'Country', 'Role', 'Stream', 'Twitter', 'Birthdate', 'Age' } local DISPLAY = { TeamLast = 'Last Team', NameFull = 'Name', Birthdate = 'Birthday', Askfm = 'AskFM' } local EVENODD = { [true] = 'odd', [false] = 'even' }

function getFields(fieldorder, query, lastteam) if not query.fields then query.fields = mw.clone(FIELDS) local order = mw.clone(FIELDORDER) if lastteam then order[3] = 'TeamLast' end return order else return util_text.split(fieldorder or query.fields,sep) end end

function formatResults(result) for i, row in ipairs(result) do		formatResult(row) end return end

function formatResult(row) row.ID = row.ID and string.format('%s', row._pageName, row.ID) row.Team = row.Team and Team{row.Team, 'rightmediumlinked'} row.TeamLast = row.TeamLast and Team{row.TeamLast, 'rightmediumlinked'} row.Country = row.Country and Country{row.Country, 'rightlong'} row.Stream = row.Stream and string.format('[%s Stream]', row.Stream) row.Twitter = row.Twitter and string.format(		'%s',		row.Twitter,		row.Twitter	) row.Askfm = row.Askfm and string.format(		'%s',		row.Askfm,		row.Askfm	) return end

function printTable(result, fieldorder) local tbl = mw.html.create('table') :addClass('cargoTable') :addClass('sortable') addHeading(tbl, fieldorder) local evenodd = false for _, row in ipairs(result) do		local tr = tbl:tag('tr') evenodd = not evenodd for _, v in ipairs(fieldorder) do			tr:tag('td') :addClass('field_' .. v)				:addClass(EVENODD[evenodd]) :wikitext(row[v]) end end return tbl end

function addHeading(tbl, fieldorder) local tr = tbl:tag('tr') for _, v in ipairs(fieldorder) do		tr:tag('th'):wikitext(DISPLAY[v] or v)	end return end

local p = {} function p.main(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end local query = util_cargo.queryFromArgs(args, DEFAULTS) local fieldorder = getFields(args.fieldorder, query, args.lastteam == 'Yes') local result = util_cargo.queryAndCast(query) formatResults(result) return printTable(result, fieldorder) end return p