<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://capipedia.cap.gov/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://capipedia.cap.gov/index.php?action=history&amp;feed=atom&amp;title=Module%3AHighest_archive_number"/>
	<link rel="alternate" type="text/html" href="https://capipedia.cap.gov/index.php?title=Module:Highest_archive_number&amp;action=history"/>
	<updated>2026-04-20T16:57:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://capipedia.cap.gov/index.php?title=Module:Highest_archive_number&amp;diff=6939&amp;oldid=prev</id>
		<title>NMcLarty27: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://capipedia.cap.gov/index.php?title=Module:Highest_archive_number&amp;diff=6939&amp;oldid=prev"/>
		<updated>2024-01-23T18:24:17Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 14:24, 23 January 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>NMcLarty27</name></author>
	</entry>
	<entry>
		<id>https://capipedia.cap.gov/index.php?title=Module:Highest_archive_number&amp;diff=6938&amp;oldid=prev</id>
		<title>en&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://capipedia.cap.gov/index.php?title=Module:Highest_archive_number&amp;diff=6938&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;/wiki/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>en&gt;Mr. Stradivarius</name></author>
	</entry>
</feed>