<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/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://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AFootnotes%2Fwhitelist%2Fsort"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Footnotes/whitelist/sort&amp;action=history"/>
	<updated>2026-06-13T04:07:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:Footnotes/whitelist/sort&amp;diff=471768&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Footnotes/whitelist/sort&amp;diff=471768&amp;oldid=prev"/>
		<updated>2021-07-15T21:46:07Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&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 'CITEREF'.  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 '#' == index then&lt;br /&gt;
		pattern = '%[\'CITEREF%d';												-- first character is a digit&lt;br /&gt;
	else&lt;br /&gt;
		pattern = '%[\'CITEREF[' .. index .. index:lower() .. ']';&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 ('\t*([^\r\n]+)') do&lt;br /&gt;
		citeref = mw.text.trim (citeref);&lt;br /&gt;
		citeref = citeref:gsub (' *%[ *\' *', '[\'');							-- normalize opening sq brackets&lt;br /&gt;
		citeref = citeref:gsub (' *\' *%] *', '\']');							-- normalize closing sq brackets&lt;br /&gt;
		citeref = citeref:gsub (' *{ *\' *', '{\'');							-- normalize opening braces&lt;br /&gt;
		citeref = citeref:gsub (' *\' *} *', '\'}');							-- normalize closing braces&lt;br /&gt;
		citeref = citeref:gsub ('([%]}]) *, *', '%1,');							-- normalize trailing comma&lt;br /&gt;
		citeref = citeref:gsub (' *= *', ' = ');								-- 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 'key' 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 '#').  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('Module:Footnotes/whitelist'):getContent();	-- read the module plain text&lt;br /&gt;
	&lt;br /&gt;
	local find_pattern = '%s*local%s+whitelist%s+=%s+';							-- find the whitelist table&lt;br /&gt;
	local tstart, tend = content:find (find_pattern);&lt;br /&gt;
&lt;br /&gt;
	content = content:match ('%b{}', tstart);									-- get the content of the whitelist table&lt;br /&gt;
	content = content:gsub ('^{[\r\n]+', ''):gsub ('[\r\n]+}$', '');			-- remove leading and trailing braces and newlines&lt;br /&gt;
	&lt;br /&gt;
	for header in content:gmatch ('%-+&amp;lt;([#%a%d%s]+)&amp;gt;%-+') 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;lt;%s*' .. header .. '%s*&amp;gt;%-+';&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;lt;]-)%-+&amp;lt;', tend+1));	-- begin at end of header; +1 to leave-off the last '-' 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 ('.*', tend+1));		-- begin at end of header; +1 to leave-off the last '-' in the header&lt;br /&gt;
		else&lt;br /&gt;
			error ('shouldn\'t be here; header: ' .. header or '(nil or empty string)' .. '; tstart: ' .. tstart or '(nil or empty string)');&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	list_parse ('UNSORTED', list, unsorted);									-- make a separate unsorted list&lt;br /&gt;
	list['UNSORTED'] = '';														-- 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 'key' 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 'emptied' by setting v nil; don'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;lt; ' .. v .. ' &amp;gt;----------\n\t' .. table.concat (temp2, '\n\t') .. '\n\n');	-- 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='local whitelist = {\n'.. table.concat (result) .. '\t}', 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>Zoran</name></author>
	</entry>
</feed>