<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AInfobox%2Futilities</id>
	<title>Module:Infobox/utilities - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AInfobox%2Futilities"/>
	<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Infobox/utilities&amp;action=history"/>
	<updated>2026-04-05T03:06:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://the-democratika.com/wiki/index.php?title=Module:Infobox/utilities&amp;diff=6880&amp;oldid=prev</id>
		<title>&gt;Trappist the monk at 13:41, 14 August 2024</title>
		<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Infobox/utilities&amp;diff=6880&amp;oldid=prev"/>
		<updated>2024-08-14T13:41: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;require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
local getArgs = require (&amp;#039;Module:Arguments&amp;#039;).getArgs;&lt;br /&gt;
&lt;br /&gt;
--[=[--------------------------&amp;lt; I N T E R L A N G _ W I K I S O U R C E _ L I N K _ M A K E &amp;gt;------------------&lt;br /&gt;
&lt;br /&gt;
created as a test function to figure out why the wikitext for |data36= in [[Special:Permalink/1236589613|this version]]&lt;br /&gt;
of the template doesn&amp;#039;t work in [[Salammbô]] when |title_orig= exists but does not have a value.  When that&lt;br /&gt;
happened, the infobox returned plain wikitext [[s:fr:Salammbô|]] which should have been a functioning link.&lt;br /&gt;
Placing that wikilink in the article body and previewing produced a working inter-language/inter-project link.&lt;br /&gt;
&lt;br /&gt;
{{#invoke:Infobox/utilities|interlang_wikisource_link_make|{{{orig_lang_code|}}}|{{{native_wikisource|}}}|{{{title_orig|}}}|{{{name|}}} }}&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
&lt;br /&gt;
local function interlang_wikisource_link_make (frame)&lt;br /&gt;
	local lang_mod = require (&amp;#039;Module:Lang&amp;#039;);									-- used to wrap non-English wikisource links in proper html markup&lt;br /&gt;
&lt;br /&gt;
	local args_t = getArgs (frame);												-- parameter values that are emptyspace or only white space are converted to nil&lt;br /&gt;
	local orig_lang_code = args_t[1];											-- &amp;#039;all of them sensible everyday names&amp;#039;&lt;br /&gt;
	local native_wikisource = args_t[2];&lt;br /&gt;
	local title_orig = args_t[3];&lt;br /&gt;
	local name = args_t[4];&lt;br /&gt;
&lt;br /&gt;
	local orig_lang_name = mw.language.fetchLanguageName (orig_lang_code, &amp;#039;en&amp;#039;);	-- get the English name associated with &amp;lt;orig_lang_code&amp;gt;; only language tags known to MediaWiki allowed&lt;br /&gt;
	if &amp;#039;&amp;#039; == orig_lang_name then												-- empty string when &amp;lt;orig_lang_code&amp;gt; invalid&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;color:#d33&amp;quot;&amp;gt;invalid language tag: &amp;lt;span style=&amp;quot;font-family:monospace&amp;quot;&amp;gt;&amp;#039; .. orig_lang_code .. &amp;#039;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local out_t = {};															-- output goes here&lt;br /&gt;
	table.insert (out_t, &amp;#039;[[s:&amp;#039;);												-- open inter-language/inter-project wikilink&lt;br /&gt;
	table.insert (out_t, orig_lang_code);										-- the language tag&lt;br /&gt;
	table.insert (out_t, &amp;#039;:&amp;#039;);													-- add the required separator&lt;br /&gt;
&lt;br /&gt;
	table.insert (out_t, native_wikisource);									-- insert wikisource title&lt;br /&gt;
	table.insert (out_t, &amp;#039;|&amp;#039;);													-- done with link; start label&lt;br /&gt;
	table.insert (out_t, title_orig or name or mw.title.getCurrentTitle().baseText);	-- insert the label&lt;br /&gt;
	table.insert (out_t, &amp;#039;]]&amp;#039;);													-- close inter-language/inter-project wikilink&lt;br /&gt;
	&lt;br /&gt;
	out_t = {lang_mod._lang ({orig_lang_code, table.concat (out_t)})};			-- replace content of out_t with a big string of its contents wrapped in {{lang}}&lt;br /&gt;
&lt;br /&gt;
	table.insert (out_t, &amp;#039; at &amp;#039;);												-- begin other language wikisource wikilinklink&lt;br /&gt;
	table.insert (out_t, orig_lang_name);										-- add the MediaWiki-known language name associated with |orig_lang_code=&lt;br /&gt;
	table.insert (out_t, &amp;#039; [[Wikisource]]&amp;#039;);									-- insert wikisource link static text&lt;br /&gt;
	&lt;br /&gt;
	return table.concat (out_t);												-- make a big string of all and done&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; I S _ C J K _ C O D E &amp;gt;--------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
return true if code is one of the listed Chinese, Japanese, Korean ISO 639 codes, false else.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function is_cjk_code (code)&lt;br /&gt;
local cjk =&lt;br /&gt;
		{&lt;br /&gt;
		[&amp;#039;zh&amp;#039;] = true, [&amp;#039;cdo&amp;#039;] = true, [&amp;#039;cjy&amp;#039;] = true, [&amp;#039;cmn&amp;#039;] = true,			-- Chinese language codes&lt;br /&gt;
		[&amp;#039;cpi&amp;#039;] = true, [&amp;#039;cpx&amp;#039;] = true, [&amp;#039;czh&amp;#039;] = true, [&amp;#039;czo&amp;#039;] = true,&lt;br /&gt;
		[&amp;#039;gan&amp;#039;] = true, [&amp;#039;hak&amp;#039;] = true, [&amp;#039;hsn&amp;#039;] = true, [&amp;#039;ltc&amp;#039;] = true,&lt;br /&gt;
		[&amp;#039;lzh&amp;#039;] = true, [&amp;#039;mnp&amp;#039;] = true, [&amp;#039;nan&amp;#039;] = true, [&amp;#039;och&amp;#039;] = true,&lt;br /&gt;
		[&amp;#039;wuu&amp;#039;] = true, [&amp;#039;yue&amp;#039;] = true, [&amp;#039;zhx&amp;#039;] = true,&lt;br /&gt;
		[&amp;#039;ja&amp;#039;] = true, [&amp;#039;jpx&amp;#039;] = true, [&amp;#039;ojp&amp;#039;] = true,							-- Japanese language codes&lt;br /&gt;
		[&amp;#039;ko&amp;#039;] = true, [&amp;#039;okm&amp;#039;] = true, [&amp;#039;oko&amp;#039;] = true,							-- Korean language codes&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	return cjk[code] or false;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; S E T _ I T A L I C S &amp;gt;--------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Created for use with Template:Infobox book and Template:Infobox document and perhaps others to replace hard-coded&lt;br /&gt;
italic markup in the call to {{lang}}.  This module attempts to make sure that {{lang}} correctly applies italic&lt;br /&gt;
markup according to MOS:FOREIGNITALIC.&lt;br /&gt;
&lt;br /&gt;
|italics={{#invoke:Infobox/utilities|set_italics|{{{orig_lang_code|}}}|{{{title_orig}}}}}}}&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function set_italics (frame)&lt;br /&gt;
	local args=getArgs(frame); &lt;br /&gt;
	local code = args[1] or args[&amp;#039;code&amp;#039;] or &amp;#039;&amp;#039;;									-- empty string causes &amp;#039;yes&amp;#039; return; {{lang}} will handle the missing code error&lt;br /&gt;
	local text = args[2] or args[&amp;#039;text&amp;#039;] or &amp;#039;&amp;#039;;									-- empty string causes &amp;#039;yes&amp;#039; return; {{lang}} will handle the missing text error&lt;br /&gt;
&lt;br /&gt;
	local is_latn = require (&amp;quot;Module:Unicode data&amp;quot;).is_Latin;&lt;br /&gt;
	&lt;br /&gt;
	code = code:gsub (&amp;#039;^(%a+).*&amp;#039;, &amp;#039;%1&amp;#039;);										-- strip subtags from IETF tag to leave just the language subtag&lt;br /&gt;
	if is_cjk_code (code) and not is_latn (text) then							-- is_latn() is in Module:Unicode data&lt;br /&gt;
		return  &amp;#039;no&amp;#039;;															-- only case for &amp;#039;no&amp;#039; &lt;br /&gt;
	end&lt;br /&gt;
	return &amp;#039;yes&amp;#039;;																-- everything else is yes&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; C O M P &amp;gt;----------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
compare function for result{} table descending sort&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function comp (a, b)&lt;br /&gt;
	return tonumber (a[1]) &amp;gt; tonumber (b[1]);&lt;br /&gt;
end&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; S O R T _ C O M M O N &amp;gt;--------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
common function to render sorted distribution, ethnicity, and occupation lists.&lt;br /&gt;
&lt;br /&gt;
inputs:&lt;br /&gt;
	result - table of percentages and labels&lt;br /&gt;
	ref - value from |distribution ref=, |ethnicity ref=, or |occupation ref= as appropriate&lt;br /&gt;
	frame - calling frame required for expandTemplate()&lt;br /&gt;
	&lt;br /&gt;
returns sorted list on success; empty string else&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function sort_common (result, ref, frame)&lt;br /&gt;
	for i=#result, 1, -1 do&lt;br /&gt;
		if not tonumber (result[i][1]) then										-- if cannot be converted to a number&lt;br /&gt;
			table.remove (result, i);											-- delete&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if 0 == #result then														-- if we get here and the result table is empty&lt;br /&gt;
		return &amp;#039;&amp;#039;;																-- abandon returning empty string&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	table.sort (result, comp);													-- sort what remains&lt;br /&gt;
&lt;br /&gt;
	for i, v in ipairs (result) do&lt;br /&gt;
		result[i] = table.concat (result[i]);									-- make each table in result{} a string&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	result[1] = table.concat ({result[1], ref and ref or &amp;#039;&amp;#039;});					-- add reference(s) from |&amp;lt;list&amp;gt; ref= to first item in the list&lt;br /&gt;
	&lt;br /&gt;
	return frame:expandTemplate { title = &amp;#039;Unbulleted list&amp;#039;, args = result};	-- render the unbulleted list&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; D I S R I B U T I O N _ S O R T &amp;gt;----------------------------------------------&lt;br /&gt;
&lt;br /&gt;
{{#invoke:Infobox/utilities|distribution_sort|{{{percent urban|}}}|{{{percent rural|}}}|{{{distribution ref|}}} }}&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function distribution_sort (frame)&lt;br /&gt;
	local args=getArgs(frame);&lt;br /&gt;
	&lt;br /&gt;
	local result = {															-- initialize; table will be sorted according to values in result[n][1]&lt;br /&gt;
		{args[1], &amp;#039;% urban&amp;#039;},&lt;br /&gt;
		{args[2], &amp;#039;% rural&amp;#039;},&lt;br /&gt;
	};&lt;br /&gt;
	&lt;br /&gt;
	return sort_common (result, args[#result+1], frame);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E T H N I C I T Y _ S O R T &amp;gt;--------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
{{#invoke:Infobox/utilities|ethnicity_sort|{{{percent white|}}}|{{{percent black|}}}|{{{percent asian|}}}|{{{percent hispanic|}}}|{{{percent native american|}}}|{{{percent native hawaiian|}}}|{{{percent more than one race|}}}|{{{percent other race|}}}|{{{ethnicity ref|}}} }}&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function ethnicity_sort (frame)&lt;br /&gt;
	local args=getArgs(frame);&lt;br /&gt;
	&lt;br /&gt;
	local result = {															-- initialize; table will be sorted according to values in result[n][1]&lt;br /&gt;
		{args[1], &amp;#039;% [[White Americans|White]]&amp;#039;},&lt;br /&gt;
		{args[2], &amp;#039;% [[African Americans|Black]]&amp;#039;},&lt;br /&gt;
		{args[3], &amp;#039;% [[Asian Americans|Asian]]&amp;#039;},&lt;br /&gt;
		{args[4], &amp;#039;% [[Hispanic and Latino Americans|Hispanic]]&amp;#039;},&lt;br /&gt;
		{args[5], &amp;#039;% [[Native Americans in the United States|Native American]]&amp;#039;},&lt;br /&gt;
		{args[6], &amp;#039;% [[Pacific Islander Americans]]&amp;#039;},&lt;br /&gt;
		{args[7], &amp;#039;% [[Multiracial Americans|Two or more races]]&amp;#039;},&lt;br /&gt;
		{args[8], &amp;#039;% other&amp;#039;},													-- TODO: make other always last?&lt;br /&gt;
	};&lt;br /&gt;
	&lt;br /&gt;
	return sort_common (result, args[#result+1], frame);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; O C C U P A T I O N _ S O R T &amp;gt;------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
{{#invoke:Infobox/utilities|distribution_sort|{{{percent blue collar|}}}|{{{percent white collar|}}}|{{{percent grey collar|}}}|{{{occupation ref|}}} }}&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function occupation_sort (frame)&lt;br /&gt;
	local args=getArgs(frame);&lt;br /&gt;
	&lt;br /&gt;
	local result = {															-- initialize; table will be sorted according to values in result[n][1]&lt;br /&gt;
		{args[1], &amp;#039;% [[Blue-collar worker|Blue-collar]]&amp;#039;},&lt;br /&gt;
		{args[2], &amp;#039;% [[White-collar worker|White-collar]]&amp;#039;},&lt;br /&gt;
		{args[3], &amp;#039;% [[Gray-collar]]&amp;#039;},&lt;br /&gt;
	};&lt;br /&gt;
	&lt;br /&gt;
	return sort_common (result, args[#result+1], frame)&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;
&lt;br /&gt;
return {&lt;br /&gt;
	distribution_sort = distribution_sort,										-- {{Infobox U.S. congressional district}}&lt;br /&gt;
	ethnicity_sort = ethnicity_sort,&lt;br /&gt;
	occupation_sort = occupation_sort,&lt;br /&gt;
	&lt;br /&gt;
	set_italics = set_italics,													-- {{Infobox book}}&lt;br /&gt;
	interlang_wikisource_link_make = interlang_wikisource_link_make,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>&gt;Trappist the monk</name></author>
	</entry>
</feed>