Module:GetEventPageInfo

local util_cargo = require('Module:CargoUtil') local util_dpl = require('Module:DPLUtil') local util_vars = require('Module:VarsUtil')

local subpages = mw.loadData('Module:SubpageSettings').tournaments.names

local h = {}

function h.parseTitle(title) local titleparts = mw.text.split(title, '/') local event = {} local subpage = {} local parsed = {} for _,titlepart in ipairs(titleparts) do		if subpages[titlepart] then -- event is everything leading up to here event = subpage -- subpage will be the rest subpage = {[1] = titlepart} else -- just keep adding to whichever part we are in			subpage[#subpage+1] = titlepart end end -- case regular page if event[1] or subpages[titleparts[1]] then parsed.event = table.concat(event,'/') parsed.subpage = table.remove(subpage, 1) parsed.subsubpage = table.concat(subpage, '/') -- case overview page else parsed.event = table.concat(subpage, '/') parsed.subpage = '' parsed.subsubpage = '' end return parsed end

function h.getDataInfo(page) local div = mw.html.create('div') :attr('id','datapage-info') :attr('data-datapages', h.getDPLDataPageNumber(page)) :attr('data-overviewpage', page) return div end

function h.getDPLDataPageNumber(page) local query = { titleregexp = ('^%s(/[0-9]+)?$'):format(page), namespace = 'Data', }	local result = util_dpl.getListOfPagenames(query) return #result end

function h.setScoreboardVars(page) local row = h.doScoreboardQuery(page) for k, v in pairs(row) do util_vars.setVar('sb' .. k, v)	end end

function h.doScoreboardQuery(page) local query = { tables = 'CCMTournaments', fields = { 'Region', 'RegionLevel', 'TournamentLevel', 'IsQualifier', 'IsPlayoffs', 'IsOfficial', 'Year', 'League', 'OverviewPage' }, where = ('OverviewPage="%s"'):format(page) }	return util_cargo.getOneRow(query) end

local p = {}

function p.getEventPageInfo(frame) local title = mw.title.getCurrentTitle.text local parsed = h.parseTitle(title) local subpage = parsed.subpage .. (parsed.subsubpage ~=  and '/' or ) .. parsed.subsubpage util_vars.setVar('overviewpage', parsed.event, frame) util_vars.setVar('subpage', subpage, frame) util_vars.setVar('subpagetype', parsed.subpage, frame) if parsed.subpage == 'Scoreboards' then h.setScoreboardVars(parsed.event) end local datadiv = h.getDataInfo(parsed.event) return datadiv end

return p