-- This module finds the highest existing archive number for a set of talk-- archive pages.
local expSearch = require('Module:Exponential search')local p =
local function raiseStartNumberError(start) error(string.format('Invalid start number "%s" supplied to (must be an integer)', tostring(start) ), 3)end
local function pageExists(page) local success, exists = pcall(function return mw.title.new(page).exists end) return success and existsend
function p._main(prefix, start) -- Check our inputs if type(prefix) ~= 'string' or not prefix:find('%S') then error('No prefix supplied to ', 2) end if start ~= nil and (type(start) ~= "number" or math.floor(start) ~= start) then raiseStartNumberError(start) end start = start or 1 -- Do an exponential search for the highest archive number local result = expSearch(function (i) local archiveNumber = i + start - 1 local page = prefix .. tostring(archiveNumber) return pageExists(page) end, 10) if result
function p.main(frame) local args = require('Module:Arguments').getArgs(frame,) local prefix = args[1] -- Get the start archive number, if specified. local start = args.start if start
return p._main(prefix, start)end
return p