<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AHighest_archive_number</id>
	<title>Module:Highest archive number - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AHighest_archive_number"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Highest_archive_number&amp;action=history"/>
	<updated>2026-04-21T11:52:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Highest_archive_number&amp;diff=136471&amp;oldid=prev</id>
		<title>imported&gt;Mr. Stradivarius: add a &quot;start&quot; parameter to specify the starting archive number with, and convert to use Module:Exponential search</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Highest_archive_number&amp;diff=136471&amp;oldid=prev"/>
		<updated>2019-10-08T15:47:04Z</updated>

		<summary type="html">&lt;p&gt;add a &amp;quot;start&amp;quot; parameter to specify the starting archive number with, and convert to use &lt;a href=&quot;/research/Module:Exponential_search&quot; title=&quot;Module:Exponential search&quot;&gt;Module:Exponential search&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module finds the highest existing archive number for a set of talk&lt;br /&gt;
-- archive pages.&lt;br /&gt;
&lt;br /&gt;
local expSearch = require(&amp;#039;Module:Exponential search&amp;#039;)&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local function raiseStartNumberError(start)&lt;br /&gt;
	error(string.format(&lt;br /&gt;
		&amp;#039;Invalid start number &amp;quot;%s&amp;quot; supplied to [[Module:Highest archive number]] (must be an integer)&amp;#039;,&lt;br /&gt;
		tostring(start)&lt;br /&gt;
	), 3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function pageExists(page)&lt;br /&gt;
	local success, exists = pcall(function()&lt;br /&gt;
		return mw.title.new(page).exists&lt;br /&gt;
	end)&lt;br /&gt;
	return success and exists&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._main(prefix, start)&lt;br /&gt;
	-- Check our inputs&lt;br /&gt;
	if type(prefix) ~= &amp;#039;string&amp;#039; or not prefix:find(&amp;#039;%S&amp;#039;) then&lt;br /&gt;
		error(&amp;#039;No prefix supplied to [[Module:Highest archive number]]&amp;#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	if start ~= nil and (type(start) ~= &amp;quot;number&amp;quot; or math.floor(start) ~= start) then&lt;br /&gt;
		raiseStartNumberError(start)&lt;br /&gt;
	end&lt;br /&gt;
	start = start or 1&lt;br /&gt;
	&lt;br /&gt;
	-- Do an exponential search for the highest archive number&lt;br /&gt;
	local result = expSearch(function (i)&lt;br /&gt;
		local archiveNumber = i + start - 1&lt;br /&gt;
		local page = prefix .. tostring(archiveNumber)&lt;br /&gt;
		return pageExists(page)&lt;br /&gt;
	end, 10)&lt;br /&gt;
	&lt;br /&gt;
	if result == nil then&lt;br /&gt;
		-- We didn&amp;#039;t find any archives for our prefix + start number&lt;br /&gt;
		return nil&lt;br /&gt;
	else&lt;br /&gt;
		-- We found the highest archive, but the number is always 1-based, so&lt;br /&gt;
		-- adjust it for our start number&lt;br /&gt;
		return result + start - 1&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = require(&amp;#039;Module:Arguments&amp;#039;).getArgs(frame, {&lt;br /&gt;
		trim = false,&lt;br /&gt;
		removeBlanks = false,&lt;br /&gt;
		wrappers = &amp;#039;Template:Highest archive number&amp;#039;&lt;br /&gt;
	})&lt;br /&gt;
	local prefix = args[1]&lt;br /&gt;
	&lt;br /&gt;
	-- Get the start archive number, if specified.&lt;br /&gt;
	local start = args.start&lt;br /&gt;
	if start == &amp;quot;&amp;quot; then&lt;br /&gt;
		start = nil&lt;br /&gt;
	elseif start then&lt;br /&gt;
		start = tonumber(start)&lt;br /&gt;
		if not start then&lt;br /&gt;
			raiseStartNumberError(args.start)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return p._main(prefix, start)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Mr. Stradivarius</name></author>
	</entry>
</feed>