<?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%3AArchive_index</id>
	<title>Module:Archive index - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AArchive_index"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Archive_index&amp;action=history"/>
	<updated>2026-05-27T17:16:55Z</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:Archive_index&amp;diff=135243&amp;oldid=prev</id>
		<title>imported&gt;Pppery: Add support for leading_zeros=</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Archive_index&amp;diff=135243&amp;oldid=prev"/>
		<updated>2021-02-15T17:03:20Z</updated>

		<summary type="html">&lt;p&gt;Add support for leading_zeros=&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[&lt;br /&gt;
Derived from https://github.com/legoktm/hbcai/blob/master/index_help.py, which is&lt;br /&gt;
&lt;br /&gt;
Copyright (C) 2012 Legoktm&lt;br /&gt;
Permission is hereby granted, free of charge, to any person obtaining&lt;br /&gt;
a copy of this software and associated documentation files (the &amp;quot;Software&amp;quot;),&lt;br /&gt;
to deal in the Software without restriction, including without limitation&lt;br /&gt;
the rights to use, copy, modify, merge, publish, distribute, sublicense,&lt;br /&gt;
and/or sell copies of the Software, and to permit persons to whom the&lt;br /&gt;
Software is furnished to do so, subject to the following conditions:&lt;br /&gt;
The above copyright notice and this permission notice shall be included in&lt;br /&gt;
all copies or substantial portions of the Software.&lt;br /&gt;
THE SOFTWARE IS PROVIDED &amp;quot;AS IS&amp;quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS&lt;br /&gt;
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,&lt;br /&gt;
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE&lt;br /&gt;
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER&lt;br /&gt;
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING&lt;br /&gt;
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS&lt;br /&gt;
IN THE SOFTWARE.&lt;br /&gt;
]]--&lt;br /&gt;
local p = {}&lt;br /&gt;
local plaintext = require(&amp;quot;Module:Plain text&amp;quot;)&lt;br /&gt;
local yesno = require(&amp;quot;Module:Yesno&amp;quot;)&lt;br /&gt;
local function split_into_threads(text, level3)&lt;br /&gt;
	local threads = {}&lt;br /&gt;
	local current_thread&lt;br /&gt;
	local header_pat &lt;br /&gt;
	text = &amp;quot;\n&amp;quot; .. text&lt;br /&gt;
	if level3 then&lt;br /&gt;
		header_pat = &amp;#039;\n===[	]*([^=].-)[ 	]* === *\n&amp;#039; &lt;br /&gt;
	else&lt;br /&gt;
		header_pat = &amp;#039;\n==[ 	]*([^=].-) *==[ 	]*\n&amp;#039; &lt;br /&gt;
	end&lt;br /&gt;
	local last = 1&lt;br /&gt;
	while true do &lt;br /&gt;
		local start, endindex, topic = text:find(header_pat, last)&lt;br /&gt;
		if current_thread then &lt;br /&gt;
			current_thread.content = text:sub(last, start)&lt;br /&gt;
			threads[#threads + 1] = current_thread&lt;br /&gt;
		end&lt;br /&gt;
		current_thread = {topic = topic}&lt;br /&gt;
		if start == nil then&lt;br /&gt;
			-- hit end of page&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
		last = endindex + 1&lt;br /&gt;
	end&lt;br /&gt;
	if not threads and not level3 then&lt;br /&gt;
		return split_into_threads(text, true)&lt;br /&gt;
	end&lt;br /&gt;
	return threads&lt;br /&gt;
end&lt;br /&gt;
local function parse_archive(title, out)&lt;br /&gt;
	local frame = mw.getCurrentFrame()&lt;br /&gt;
	if title.isRedirect then&lt;br /&gt;
		title = title.redirectTarget&lt;br /&gt;
	end&lt;br /&gt;
	local threads = split_into_threads(title:getContent())&lt;br /&gt;
	local seen = {}&lt;br /&gt;
	for _, thread in ipairs(threads) do&lt;br /&gt;
		local __, reply_count = thread.content:gsub(&amp;quot;%(UTC%)&amp;quot;,&amp;quot;&amp;quot;)&lt;br /&gt;
		local linktopic&lt;br /&gt;
		local topic = thread.topic&lt;br /&gt;
		if seen[topic] then&lt;br /&gt;
			linktopic = topic .. &amp;quot; &amp;quot; .. tostring(seen[topic] + 1)&lt;br /&gt;
		else&lt;br /&gt;
			linktopic = topic&lt;br /&gt;
		end&lt;br /&gt;
		seen[topic] = (seen[topic] or 0) +1&lt;br /&gt;
		local link = string.format(&amp;quot;[[%s#%s]]&amp;quot;, title.prefixedText, frame:callParserFunction(&amp;quot;anchorencode&amp;quot;, {linktopic}))&lt;br /&gt;
		out = out .. string.format(&amp;quot;\n|-\n| %s || %s || %s&amp;quot;, thread.topic, tostring(reply_count), link)&lt;br /&gt;
	end&lt;br /&gt;
	return out&lt;br /&gt;
end	&lt;br /&gt;
-- End of copied code. The below code was written by me, without paying much attention to the relevant Legobot code&lt;br /&gt;
local function resolve_relative(mask, frame) &lt;br /&gt;
	local title = frame:getParent():getTitle()&lt;br /&gt;
	local titleObj = mw.title.new(title)&lt;br /&gt;
	if titleObj.subpageText == &amp;quot;Archive index&amp;quot; then&lt;br /&gt;
		title = titleObj.nsText .. &amp;quot;:&amp;quot; .. titleObj.baseText&lt;br /&gt;
	end&lt;br /&gt;
	return title .. mask&lt;br /&gt;
end&lt;br /&gt;
function p._onemask(mask, frame)&lt;br /&gt;
	if frame == nil then&lt;br /&gt;
		frame = mw.getCurrentFrame()&lt;br /&gt;
	end&lt;br /&gt;
	if mask:sub(1,1) == &amp;quot;/&amp;quot; then&lt;br /&gt;
		mask = resolve_relative(mask, frame)&lt;br /&gt;
	end&lt;br /&gt;
	local out = &amp;quot;&amp;quot;&lt;br /&gt;
	local leading_zeros = tonumber(frame.args.leading_zeros) or 0&lt;br /&gt;
	if mask:find(&amp;quot;&amp;lt;#&amp;gt;&amp;quot;) then&lt;br /&gt;
		local archivecount = 0&lt;br /&gt;
		while true do&lt;br /&gt;
			archivecount = archivecount + 1&lt;br /&gt;
			local archivesuffix = tostring(archivecount)&lt;br /&gt;
			archivesuffix = string.rep(&amp;quot;0&amp;quot;, leading_zeros - #archivesuffix + 1) .. archivesuffix&lt;br /&gt;
			local title = mw.title.new(mask:gsub(&amp;quot;&amp;lt;#&amp;gt;&amp;quot;,tostring(archivesuffix)))&lt;br /&gt;
			if not title.exists then&lt;br /&gt;
				return out&lt;br /&gt;
			end&lt;br /&gt;
			out = parse_archive(title, out)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		local title = mw.title.new(mask)&lt;br /&gt;
		out = parse_archive(title, out)&lt;br /&gt;
	end&lt;br /&gt;
	return out&lt;br /&gt;
end&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local out = &amp;quot;&amp;quot;&lt;br /&gt;
	out = out .. frame:extensionTag(&amp;quot;templatestyles&amp;quot;,&amp;quot;&amp;quot;,{src=&amp;quot;Module:Archive index/styles.css&amp;quot;})&lt;br /&gt;
	out = out .. &amp;#039;\n{| class=&amp;quot;sortable&amp;quot;\n! Discussion Topic !! Replies (estimated) !! Archive Link&amp;#039;&lt;br /&gt;
	if frame.args.mask then&lt;br /&gt;
		out = out .. p._onemask(frame.args.mask, frame)&lt;br /&gt;
	end&lt;br /&gt;
	local masknum = 1&lt;br /&gt;
	while true do&lt;br /&gt;
		local maskArg = frame.args[&amp;quot;mask&amp;quot; .. tostring(masknum)]&lt;br /&gt;
		if maskArg then&lt;br /&gt;
			out = out .. p._onemask(maskArg, frame)&lt;br /&gt;
			masknum = masknum + 1&lt;br /&gt;
		else&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if yesno(frame.args.indexhere) then&lt;br /&gt;
		out = parse_archive(mw.title.new(resolve_relative(&amp;quot;&amp;quot;, frame)), out)&lt;br /&gt;
	end&lt;br /&gt;
	return out&lt;br /&gt;
end&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Pppery</name></author>
	</entry>
</feed>