Module:Paginate

local p = {}

local page = 1 local perpage = 10 local pagelist = {}

function _handleargs(frame) -- PAGE -- DESC: Current page to display -- DEFAULT: Search subpagename for number, otherwise 1 if frame.args.page ~= nil and frame.args.page ~= "" then page = tonumber(frame.args.page) else --try to get page number from URL page = tonumber(mw.title.getCurrentTitle.subpageText) if page == nil then page = 1 end end

-- PERPAGE -- DESC: Items to show per page -- DEFAULT: 10 if frame.args.perpage ~= nil and frame.args.perpage ~= "" then perpage = tonumber(frame.args.perpage) end end

function p.showall(frame) end

function p.showpage(frame) local result = ''

_handleargs(frame) -- Handle Args

local pagelist = {} for i in string.gmatch(frame.args.list, "([^\n]+)") do    table.insert(pagelist,i) end

-- Show Warnings if frame.args.category ~= nil and frame.args.category ~= "" then if mw.site.stats.pagesInCategory(frame.args.category, "pages") ~= #pagelist then result = result .. '{| class="wikitable cautiontable"\n' result = result .. '! Notice!\n' result = result .. '|-\n' result = result .. '| Number of pages in category changed. Update the page list for Category:' .. frame.args.category .. "\n" result = result .. '|}\n' end end

-- Display Pages for i=1+(page-1)*perpage,math.min(page*perpage,#pagelist) do   result = result..frame:preprocess(mw.title.new(pagelist[i]):getContent) if i ~= math.min(page*perpage,#pagelist) then result = result .. "\n" end end

return result end

-- Show Navigation -- Args: list perpage -- Optional: page, count function p.shownav(frame) _handleargs(frame)

local count = tonumber(frame.args.size) if count == 0 or count == nil then local pagelist = {} for i in string.gmatch(frame.args.list, "([^\n]+)") do     table.insert(pagelist,i) end count = #pagelist end if frame.args.hidenav == nil or frame.args.hidenav ~= "" then local base = mw.title.getCurrentTitle.baseText; local result = '{| class="wikitable" \n |Page: '

--prev if page ~= 1 then result = result .. "" -- next end

result = result .. '\n|}'

return result end end

-- Show Table of Contents -- Args: list perpage function p.showtoc(frame) --- ARGS _handleargs(frame)

local pagelist = {} for i in string.gmatch(frame.args.list, "([^\n]+)") do     table.insert(pagelist,i) end --- END ARGS - local result = '' result = result .. ' \n'

Do this page result = result .. '{| id="toc" style="vertical-align:top;float:left;margin-right:3px;"\n' result = result .. '|Contents \n' for j=(page-1)*perpage+1,math.min(page*perpage,#pagelist) do       local subpage = mw.title.new(pagelist[j]).subpageText result = result .. '* • '.. subpage .. "\n" end result = result .. "|}\n"

Do other pages if frame.args.expand == "yes" then result = result .. ' \n' else result = result .. ' \n' end

for i=1,math.ceil(#pagelist/perpage) do     if i ~= page then result = result .. '{| id="toc" style="vertical-align:top;display:inline-block"\n' result = result .. '| \n'

base = mw.title.getCurrentTitle.baseText for j=(i-1)*perpage+1,math.min(i*perpage,#pagelist) do           local subpage = mw.title.new(pagelist[j]).subpageText result = result .. '* • '.. subpage .. "\n" end

result = result .. "|}\n" end end result = result .. ' '

result = result .. ' '    return result; end

return p