<?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%3AFootnotes%2Fwhitelist%2Fsort</id>
	<title>Module:Footnotes/whitelist/sort - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AFootnotes%2Fwhitelist%2Fsort"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Footnotes/whitelist/sort&amp;action=history"/>
	<updated>2026-05-07T02:51:20Z</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:Footnotes/whitelist/sort&amp;diff=136283&amp;oldid=prev</id>
		<title>imported&gt;Trappist the monk at 19:11, 21 July 2020</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Footnotes/whitelist/sort&amp;diff=136283&amp;oldid=prev"/>
		<updated>2020-07-21T19:11:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[--------------------------&amp;lt; U N S O R T E D _ A D D &amp;gt;------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
add members of the unsorted list based on first character(upper or lower case) following &amp;#039;CITEREF&amp;#039;.  If &amp;lt;index&amp;gt;&lt;br /&gt;
is longer than one character (ODNB, UNSORTED, whatever), return without making any additions&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function unsorted_add (index, unsorted, temp)&lt;br /&gt;
	local pattern;&lt;br /&gt;
&lt;br /&gt;
	if 1 &amp;lt; index:len() then														-- only add citerefs to the single-character lists&lt;br /&gt;
		return;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if &amp;#039;#&amp;#039; == index then&lt;br /&gt;
		pattern = &amp;#039;%[\&amp;#039;CITEREF%d&amp;#039;;												-- first character is a digit&lt;br /&gt;
	else&lt;br /&gt;
		pattern = &amp;#039;%[\&amp;#039;CITEREF[&amp;#039; .. index .. index:lower() .. &amp;#039;]&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	for k, v in pairs (unsorted) do												-- spin through the unsorted listing&lt;br /&gt;
		if v and k:match (pattern) then											-- if not nil and matches the pattern&lt;br /&gt;
			temp[k] = true;														-- add to the alpha listing&lt;br /&gt;
			unsorted[k] = nil;													-- and then disable this one in the unsorted listing&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; L I S T _ P A R S E &amp;gt;----------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
parse apart plain-text list of a key / value pair into a table where the plain-text k/v becomes the key in a lua&lt;br /&gt;
table with the assigned value true.  Do this to catch multiples of the same k/v and to support the easy insertion&lt;br /&gt;
of k/v pairs from the unsorted list.&lt;br /&gt;
&lt;br /&gt;
also normalize k/v format&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function list_parse (index, list, temp)&lt;br /&gt;
	for citeref in list[index]:gmatch (&amp;#039;\t*([^\r\n]+)&amp;#039;) do&lt;br /&gt;
		citeref = mw.text.trim (citeref);&lt;br /&gt;
		citeref = citeref:gsub (&amp;#039; *%[ *\&amp;#039; *&amp;#039;, &amp;#039;[\&amp;#039;&amp;#039;);							-- normalize opening sq brackets&lt;br /&gt;
		citeref = citeref:gsub (&amp;#039; *\&amp;#039; *%] *&amp;#039;, &amp;#039;\&amp;#039;]&amp;#039;);							-- normalize closing sq brackets&lt;br /&gt;
		citeref = citeref:gsub (&amp;#039; *{ *\&amp;#039; *&amp;#039;, &amp;#039;{\&amp;#039;&amp;#039;);							-- normalize opening braces&lt;br /&gt;
		citeref = citeref:gsub (&amp;#039; *\&amp;#039; *} *&amp;#039;, &amp;#039;\&amp;#039;}&amp;#039;);							-- normalize closing braces&lt;br /&gt;
		citeref = citeref:gsub (&amp;#039;([%]}]) *, *&amp;#039;, &amp;#039;%1,&amp;#039;);							-- normalize trailing comma&lt;br /&gt;
		citeref = citeref:gsub (&amp;#039; *= *&amp;#039;, &amp;#039; = &amp;#039;);								-- normalize assignment operator&lt;br /&gt;
		if not temp[citeref] then&lt;br /&gt;
			temp[citeref] = true;												-- a constant value so that we can know if the &amp;#039;key&amp;#039; already exists (avoid duplication)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; W H I T E L I S T _ S O R T &amp;gt;--------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
maintenance utility for Module:Footnotes/whitelist.  The whitelist is segregated into sections according to the&lt;br /&gt;
section heading (single alpha character A-Z and &amp;#039;#&amp;#039;).  This utility adds whitelist entries from the UNSORTED&lt;br /&gt;
heading to the correct alpha heading.  After appropriate unsorted entries have been added to a section, the&lt;br /&gt;
section is sorted and then saved.&lt;br /&gt;
&lt;br /&gt;
for this to work, the unsorted header name must be: UNSORTED&lt;br /&gt;
&lt;br /&gt;
this utility take no arguments from frame.  frame is provided only for expandTemplate()&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function whitelist_sort(frame)&lt;br /&gt;
	local headers = {};															-- headings are stored here and used for loop control&lt;br /&gt;
	local list = {}																-- table of tables of the plain-text citerefs&lt;br /&gt;
	local unsorted = {};														-- table of k/v pairs where k is the unsorted citerefs and v is true or nil (after added to alpha list)&lt;br /&gt;
	local result = {};															-- sorted and formatted section end up here&lt;br /&gt;
	local temp, temp2 = {}, {};&lt;br /&gt;
&lt;br /&gt;
	local content = mw.title.new(&amp;#039;Module:Footnotes/whitelist&amp;#039;):getContent();	-- read the module plain text&lt;br /&gt;
	&lt;br /&gt;
	local find_pattern = &amp;#039;%s*local%s+whitelist%s+=%s+&amp;#039;;							-- find the whitelist table&lt;br /&gt;
	local tstart, tend = content:find (find_pattern);&lt;br /&gt;
&lt;br /&gt;
	content = content:match (&amp;#039;%b{}&amp;#039;, tstart);									-- get the content of the whitelist table&lt;br /&gt;
	content = content:gsub (&amp;#039;^{[\r\n]+&amp;#039;, &amp;#039;&amp;#039;):gsub (&amp;#039;[\r\n]+}$&amp;#039;, &amp;#039;&amp;#039;);			-- remove leading and trailing braces and newlines&lt;br /&gt;
	&lt;br /&gt;
	for header in content:gmatch (&amp;#039;%-+&amp;lt;([#%a%d%s]+)&amp;gt;%-+&amp;#039;) do					-- get pseudo-headers&lt;br /&gt;
		table.insert (headers, mw.text.trim (header));							-- save the captures in the headers table&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for i, header in ipairs (headers) do										-- separate whitelist entries into individual alpha groupings&lt;br /&gt;
		local pattern = &amp;#039;%-+&amp;lt;%s*&amp;#039; .. header .. &amp;#039;%s*&amp;gt;%-+&amp;#039;;&lt;br /&gt;
		tstart, tend = content:find (pattern);									-- find this header&lt;br /&gt;
		if tstart and headers[1+i] then											-- if not the last header&lt;br /&gt;
			list[header] =  mw.text.trim (content:match (&amp;#039;([^&amp;lt;]-)%-+&amp;lt;&amp;#039;, tend+1));	-- begin at end of header; +1 to leave-off the last &amp;#039;-&amp;#039; in the header&lt;br /&gt;
		elseif tstart then														-- must be the last header (usually UNSORTED)&lt;br /&gt;
			list[header] =  mw.text.trim (content:match (&amp;#039;.*&amp;#039;, tend+1));		-- begin at end of header; +1 to leave-off the last &amp;#039;-&amp;#039; in the header&lt;br /&gt;
		else&lt;br /&gt;
			error (&amp;#039;shouldn\&amp;#039;t be here; header: &amp;#039; .. header or &amp;#039;(nil or empty string)&amp;#039; .. &amp;#039;; tstart: &amp;#039; .. tstart or &amp;#039;(nil or empty string)&amp;#039;);&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	list_parse (&amp;#039;UNSORTED&amp;#039;, list, unsorted);									-- make a separate unsorted list&lt;br /&gt;
	list[&amp;#039;UNSORTED&amp;#039;] = &amp;#039;&amp;#039;;														-- blank the unsorted source&lt;br /&gt;
&lt;br /&gt;
	for i, v in ipairs (headers) do&lt;br /&gt;
		temp, temp2 = {}, {};													-- reinit temp &amp;amp;  temp2&lt;br /&gt;
&lt;br /&gt;
		list_parse (v, list, temp);												-- parse the list&lt;br /&gt;
		unsorted_add (v, unsorted, temp);										-- then add appropriate citerefs from the unsorted list&lt;br /&gt;
&lt;br /&gt;
		for k, v in pairs (temp) do												-- get &amp;#039;key&amp;#039; value from temp{} and make a sequence from it in temp2{} so it can be sorted&lt;br /&gt;
			if v then&lt;br /&gt;
				table.insert (temp2, k);										-- unsorted listing gets &amp;#039;emptied&amp;#039; by setting v nil; don&amp;#039;t add nil citerefs to temp2&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		table.sort (temp2);														-- sort this section&lt;br /&gt;
		table.insert (result, &amp;#039;----------&amp;lt; &amp;#039; .. v .. &amp;#039; &amp;gt;----------\n\t&amp;#039; .. table.concat (temp2, &amp;#039;\n\t&amp;#039;) .. &amp;#039;\n\n&amp;#039;);	-- add a header, make a long string, and add to result{}&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return frame:extensionTag {name=&amp;quot;syntaxhighlight&amp;quot;, content=&amp;#039;local whitelist = {\n&amp;#039;.. table.concat (result) .. &amp;#039;\t}&amp;#039;, args = {lang=&amp;quot;lua&amp;quot;}};&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[-------------------------&amp;lt; E X P O R T E D   F U N C T I O N S &amp;gt;------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	whitelist_sort = whitelist_sort,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Trappist the monk</name></author>
	</entry>
</feed>