Module:Subpage List

local p = {}

function p.Main(frame) local args = frame:getParent.args local recurse = args["recursive"] return p.main(recurse) end

function p.main(recurse) local title = mw.title.getCurrentTitle local dplResult = mw.getCurrentFrame:callParserFunction('#dpl:', {		namespace= 'Data',		titlematch= '%' .. title.text .. '/%',		["format"]= ",,%PAGE%#,"	}) dplResult = mw.text.trim(dplResult, '#') local subpages = mw.text.split(dplResult, '#') return p.listPages(title, subpages, recurse) end

function p.listPages(title, subpages, recurse) local list = '' mw.logObject(subpages) for i, subpage in ipairs(subpages) do		local subpageTitle = mw.title.new(subpage) if subpageTitle.baseText == title.text then list = list .. string.format('%s', subpageTitle.fullText, subpageTitle.subpageText) if recurse then list = list .. p.listPages(subpageTitle, subpages, recurse) end end end return list .. '' end

return p