Module:Navigation

local getArgs = require('Module:Arguments').getArgs

local p = {}

local subpages = {}

function p.add_subpage(subpage) for i = 1, #subpages, 1 do		if subpages[i] == subpage then return end end subpages[#subpages + 1] = subpage end

function p.get_subpages(args) if args.baseText == args.subpageText then return end local title = mw.title.new(args.baseText) local content = title.getContent(title)

if content == nil then return end

for link in string.gmatch(content, '%[%[.-%]%]') do		link = string.gsub(link, '%[%[Category:.-%]%]', '') link = string.gsub(link, '%[%[category:.-%]%]', '') link = string.gsub(link, '%', '') link = string.gsub(link, '%', '') link = string.gsub(link, '%', '') link = string.gsub(link, '%', '') link = string.gsub(link, '%|.-%]%]', ']]') link = string.gsub(link, '%[%[/', '' .. args.baseText .. '/')		link = string.gsub(link, "%/%]%]", "") link = string.sub(link, 3, string.len(link) - 2)

if string.sub(link, 1, string.len(args.baseText) + 1) == args.baseText .. '/' then p.add_subpage(link) end end end

function p.subpage_navbar(frame) local args = getArgs(frame) local title = mw.title.getCurrentTitle args.baseText = title.baseText args.subpageText = title.subpageText return p._subpage_navbar(args) end

function p._subpage_navbar(args) local result = {} result[#result + 1] = '' result[#result + 1] = ' ' result[#result + 1] = p.subpage_previous(args) .. ' '	result[#result + 1] = ' ' result[#result + 1] = '' .. args.baseText .. ' ' result[#result + 1] = ' ' result[#result + 1] = p.subpage_next(args) .. ' '	return table.concat(result) end

function p.subpage_next(frame) local args = getArgs(frame) local title = mw.title.getCurrentTitle args.baseText = title.baseText args.subpageText = title.subpageText return p._subpage_next(args) end

function p._subpage_next(args) if #subpages == 0 then p.get_subpages(args) end for i = 1, #subpages - 1, 1 do		subpage = subpages[i] subpage = string.gsub(subpage, '.*/', '') if subpage == args.subpageText then return  .. string.gsub(subpages[i + 1], '.*/', ) .. ' &rarr;' end end return '' end

function p.subpage_previous(frame) local args = getArgs(frame) local title = mw.title.getCurrentTitle args.baseText = title.baseText args.subpageText = title.subpageText return p._subpage_previous(args) end

function p._subpage_previous(args) if #subpages == 0 then p.get_subpages(args) end for i = 2, #subpages, 1 do		subpage = subpages[i] subpage = string.gsub(subpage, '.*/', '') if subpage == args.subpageText then return '&larr; ' .. string.gsub(subpages[i - 1], '.*/', ) ..  end end return '' end

return p