Module:Highest archive number
Appearance
-- This module finds the highest existing archive number for a set of talk
-- archive pages.
local p = {}
local function pageExists(page)
local success, title = pcall(mw.title.new, page)
return success and title and title.exists
end
local function findHighestArchive(prefix, i, lower, upper)
if pageExists(prefix .. tostring(i)) then
lower = i
if upper and i + 1 == upper then
return i
elseif upper then
i = math.floor(lower + (upper - lower) / 2)
else
i = i * 2
end
return findHighestArchive(prefix, i, lower, upper)
else
upper = i
lower = lower or math.floor(i / 2)
i = math.floor(lower + (upper - lower) / 2)
return findHighestArchive(prefix, i, lower, upper)
end
end
p.find = findHighestArchive
function p._main(args)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
return p._main(args)
end
return p