Module:PlayerProfileGallery

local util_args = require('Module:ArgsUtil') local util_cargo = require("Module:CargoUtil") local util_html = require("Module:HtmlUtil") local util_map = require('Module:MapUtil') local util_table = require("Module:TableUtil") local util_text = require("Module:TextUtil") local util_vars = require("Module:VarsUtil") local i18n = require("Module:I18nUtil") local lang = mw.getLanguage('en') local Gallery = require('Module:GalleryClass') local h = {} local p = {} function p.main(frame) local args = util_args.merge local images = h.makeAndRunQuery(args) return Gallery(images):run end

function h.makeAndRunQuery(args) local query = h.getQuery(args) return util_cargo.queryAndCast(query) end

function h.getQuery(args) local query = { tables = { 'PlayerRedirects=PR', 'PlayerImages=PI', 'Tournaments=T', },		join = { 'PR.AllName=PI.Link', 'PI.Tournament=T.OverviewPage', },		where = h.getWhere(args), fields = { 'PI.FileName', 'PI.Caption' }, orderBy = 'COALESCE(PI.SortDate, T.DateStart, T.Date)', }	return query end

function h.getWhere(args) local where = { ('PR._pageName="%s"'):format(args.player), ('PI._pageName IS NOT NULL'), }	return where end

return p