Module:PlayerListChart

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_text = require('Module:TextUtil') local m_team = require('Module:Team') local m_country = require('Module:Country')

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 h = {}

function h.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 h.formatResults(result) for i, row in ipairs(result) do		h.formatResult(row) end return end

function h.formatResult(row) row.ID = row.ID and string.format('%s', row._pageName, row.ID) row.Team = row.Team and m_team.rightmediumlinked(row.Team) row.TeamLast = row.TeamLast and m_team.rightmediumlinked(row.TeamLast) row.Country = row.Country and m_country.rightlong(row.Country) 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 h.printTable(result, fieldorder) local tbl = mw.html.create('table') :addClass('cargoTable') :addClass('sortable') h.addHeading(tbl, fieldorder) for _, row in ipairs(result) do		local tr = tbl:tag('tr') for _, v in ipairs(fieldorder) do			tr:tag('td') :addClass('field_' .. v)				:wikitext(row[v]) end end return tbl end

function h.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) local args = util_args.merge(true) local query = util_cargo.queryFromArgs(args, DEFAULTS) local fieldorder = h.getFields(args.fieldorder, query, args.lastteam == 'Yes') local result = util_cargo.queryAndCast(query) h.formatResults(result) return h.printTable(result, fieldorder) end return p