Module:DataTabs

local util_args = require('Module:ArgsUtil') local util_dpl = require('Module:DPLUtil') local util_vars = require('Module:VarsUtil') local Tabs = require('Module:TabsHeader').fromTables

local h = {}

local p = {} function p.main(frame) --if mw.title.getCurrentTitle.nsText == 'Data' then local args = util_args.merge(true) local title_obj = mw.title.getCurrentTitle local title = title_obj.text local overviewPage = args.basepage or title:match('^(.*)(/%d+)$') or title local links = h.getDPLDataPages(overviewPage) local lookup = h.makeLookup(links, args.basepage) h.sortLinks(links, lookup) local names = h.getNames(#links) local this = lookup[title_obj.prefixedText] util_vars.setVar('N_Page', this) util_vars.setVar('MVPPoints', args.mvppoints or 1) util_vars.setVar('overviewpage', overviewPage) util_vars.setVar('Bestof', args.bestof) local div = h.makeDiv(overviewPage, args) if #links > 1 then return Tabs(names, links, this), div end return div --end end

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

function h.makeLookup(links, basepage) local lookup = {} for _, v in ipairs(links) do		if basepage then lookup[v] = tonumber(v:match(basepage .. '/(%d+)$') or 1) else lookup[v] = tonumber(v:match('/(%d+)$') or 1) end end return lookup end

function h.sortLinks(links, lookup) table.sort(links, function(a,b)		return lookup[a] < lookup[b]	end) end

function h.getNames(n) local names = {} for i = 1, n do names[i] = 'Page ' .. i	end return names end

function h.makeDiv(overviewPage, args) local div = mw.html.create('div') :attr('id','data-ns-pageinfo') :attr('data-overviewpage', overviewPage) :attr('data-pickban','Yes') if args.fl then div:attr('data-page-link', 'Project:Featured Leagues/' .. args.fl) div:attr('data-template-link', 'Project:Featured Leagues/Template/' .. args.fl) end return div end

return p