Module:Subpage List

local p = {}

function p.Main(frame) local args = frame:getParent.args local pageName = args[1] local recurse = tonumber(args["recurse"]) return p.main(pageName, recurse) end

function p.main(pageName, recurse) local title if pageName then title = mw.title.new(pageName) else title = mw.title.getCurrentTitle end local dplResult = mw.getCurrentFrame:callParserFunction('#dpl:', {		namespace= title.nsText,		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 = '' 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 == nil or recurse > 0 then list = list .. p.listPages(subpageTitle, subpages, recurse and recurse - 1) end end end return list .. '' end

return p