Jump to content

Module:Highest archive number/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 14:14, 1 October 2019 (convert this to use Module:Exponential search). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- 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 pageExists(page)
	local success, exists = pcall(function()
		return mw.title.new(page).exists
	end)
	return success and exists
end

function p._main(prefix)
	if type(prefix) ~= 'string' or not prefix:find('%S') then
		error('no prefix supplied to [[Module:Highest archive number]]', 2)
	end
	return expSearch(function (i)
		return pageExists(prefix .. tostring(i))
	end, 10)
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		trim = false,
		removeBlanks = false,
		wrappers = 'Template:Highest archive number'
	})
	local prefix = args[1]
	return p._main(prefix)
end

return p