<?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%3ASandbox%2FCX_Zoom%2FTestPage1</id>
	<title>Module:Sandbox/CX Zoom/TestPage1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FCX_Zoom%2FTestPage1"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/CX_Zoom/TestPage1&amp;action=history"/>
	<updated>2026-04-04T05:01:41Z</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:Sandbox/CX_Zoom/TestPage1&amp;diff=145242&amp;oldid=prev</id>
		<title>imported&gt;Legoktm: Replace Module:No globals with require( &quot;strict&quot; )</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/CX_Zoom/TestPage1&amp;diff=145242&amp;oldid=prev"/>
		<updated>2022-10-23T21:12:09Z</updated>

		<summary type="html">&lt;p&gt;Replace &lt;a href=&quot;/research/Module:No_globals&quot; title=&quot;Module:No globals&quot;&gt;Module:No globals&lt;/a&gt; with require( &amp;quot;strict&amp;quot; )&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--This is a personal Module Testing site of User:CX Zoom. Please consider notifying him, in the event of any issues. Thanks.&lt;br /&gt;
&lt;br /&gt;
require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
--[=[-------------------------&amp;lt; R E M O V E _ W I K I _ L I N K &amp;gt;----------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Gets the display text from a wikilink like [[A|B]] or [[B]] gives B&lt;br /&gt;
&lt;br /&gt;
The str:gsub() returns either A|B froma [[A|B]] or B from [[B]] or B from B (no wikilink markup).&lt;br /&gt;
&lt;br /&gt;
In l(), l:gsub() removes the link and pipe (if they exist); the second :gsub() trims white space from the label&lt;br /&gt;
if str was wrapped in wikilink markup.  Presumably, this is because without wikimarkup in str, there is no match&lt;br /&gt;
in the initial gsub, the replacement function l() doesn&amp;#039;t get called.&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
&lt;br /&gt;
local function remove_wiki_link (str)&lt;br /&gt;
	return (str:gsub( &amp;quot;%[%[([^%[%]]*)%]%]&amp;quot;, function(l)&lt;br /&gt;
		return l:gsub( &amp;quot;^[^|]*|(.*)$&amp;quot;, &amp;quot;%1&amp;quot; ):gsub(&amp;quot;^%s*(.-)%s*$&amp;quot;, &amp;quot;%1&amp;quot;);&lt;br /&gt;
	end));&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[=[-------------------------&amp;lt; M A K E _ W I K I L I N K &amp;gt;----------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Makes a wikilink; when both link and display text is provided, returns a wikilink in the form [[L|D]]; if only&lt;br /&gt;
link is provided, returns a wikilink in the form [[L]]; if neither are provided or link is omitted, returns an&lt;br /&gt;
empty string.&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
&lt;br /&gt;
local function make_wikilink (link, display)&lt;br /&gt;
	if link and (&amp;#039;&amp;#039; ~= link) then&lt;br /&gt;
		if display and (&amp;#039;&amp;#039; ~= display) then&lt;br /&gt;
			return table.concat ({&amp;#039;[[&amp;#039;, link, &amp;#039;|&amp;#039;, display, &amp;#039;]]&amp;#039;});&lt;br /&gt;
		else&lt;br /&gt;
			return table.concat ({&amp;#039;[[&amp;#039;, link, &amp;#039;]]&amp;#039;});&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return display or &amp;#039;&amp;#039;;														-- link not set so return the display text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; S I Z E &amp;gt;----------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
module entry point&lt;br /&gt;
&lt;br /&gt;
create a wikilinked list of &amp;lt;article name&amp;gt;&amp;#039;s sections and their size in bytes in a sortable wikitable&lt;br /&gt;
&lt;br /&gt;
{{#invoke:Section sizes|size|&amp;lt;article name&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function size (frame)&lt;br /&gt;
	local A = {};																-- table to hold section names and sizes&lt;br /&gt;
	local section_name_list = {}												-- an interim list that holds just the section names&lt;br /&gt;
	local section_content;														-- section content used for counting&lt;br /&gt;
	local section = &amp;#039;_LEAD_&amp;#039;;													-- lead section doen&amp;#039;t have a heading&lt;br /&gt;
	local count = {};															-- number of bytes in a section including the header text&lt;br /&gt;
	local totcount = {};&lt;br /&gt;
	local lastlevel;&lt;br /&gt;
	local maxlevels;&lt;br /&gt;
	local levelcounts = {};&lt;br /&gt;
	local upperlevel;&lt;br /&gt;
	local highlight;&lt;br /&gt;
	local highlighttot;&lt;br /&gt;
	local total;																-- sum of all byte counts&lt;br /&gt;
	local max;																	-- largest section so far encountered&lt;br /&gt;
	local totmax;																-- largest section so far encountered (section total)&lt;br /&gt;
	local _;																	-- dummy for using gsub to count bytes&lt;br /&gt;
	local lang = mw.language.getContentLanguage();								-- language object for number formatting appropriate to local language&lt;br /&gt;
	local s;																	-- start position of found heading (returned from string.find())&lt;br /&gt;
	local e = 1;																-- end position of found heading (returned from string.find())&lt;br /&gt;
	local section_name;															-- captured heading name (returned from string.find())&lt;br /&gt;
	local level = {};															-- number of leading &amp;#039;=&amp;#039; in heading markup; used for indenting subsections in the rendered list&lt;br /&gt;
	local wl_name;																-- anchor and display portion for wikilinks in rendered list&lt;br /&gt;
&lt;br /&gt;
	local content = mw.title.new (frame.args[1]):getContent();					-- get unparsed wikitext from the article&lt;br /&gt;
	if not content then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no article:&amp;#039; .. frame.args[1] .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if content:find (&amp;#039;#REDIRECT&amp;#039;) then											-- redirects don&amp;#039;t have sections&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: &amp;#039; .. frame.args[1] .. &amp;#039; is a redirect&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	section_content = content:match (&amp;#039;(.-)===*&amp;#039;);								-- get the lead section&lt;br /&gt;
	if section_content then&lt;br /&gt;
		_, count[0] = section_content:gsub (&amp;#039;.&amp;#039;, &amp;#039;%1&amp;#039;);							-- count the size of the lead section&lt;br /&gt;
	else&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no sections found in: &amp;#039; .. frame.args[1] .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
	total = count[0];&lt;br /&gt;
	max = count[0];&lt;br /&gt;
	&lt;br /&gt;
	table.insert (A, make_wikilink (frame.args[1], section) .. &amp;#039;|| style=&amp;quot;text-align:right&amp;quot;|&amp;#039; .. lang:formatNum (count[0]) .. &amp;#039;|| style=&amp;quot;text-align:right&amp;quot;|&amp;#039; .. lang:formatNum (count[0]));&lt;br /&gt;
&lt;br /&gt;
	while (1) do																-- done this way because some articles reuse section names&lt;br /&gt;
		s, e, section_name = string.find (content, &amp;#039;\n==+ *(.-) *==+&amp;#039;, e);		-- get start, end, and section name beginning a end of last find; newline must precede &amp;#039;==&amp;#039; heading markup&lt;br /&gt;
		if s then&lt;br /&gt;
			table.insert (section_name_list, {section_name, s});				-- save section name and start location of this find&lt;br /&gt;
		else&lt;br /&gt;
			break;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	for i, section_name in ipairs (section_name_list) do&lt;br /&gt;
		local escaped_section_name = string.gsub (section_name[1], &amp;#039;([%(%)%.%%%+%-%*%?%[%^%$%]])&amp;#039;, &amp;#039;%%%1&amp;#039;);		-- escape lua patterns in section name&lt;br /&gt;
		local pattern = &amp;#039;(==+ *&amp;#039; .. escaped_section_name .. &amp;#039; *==+.-)==+&amp;#039;;		-- make a pattern to get the content of a section&lt;br /&gt;
		section_content = string.match (content, pattern, section_name[2]);		-- get the content beginning at the string.find() start location&lt;br /&gt;
		if section_content then&lt;br /&gt;
			_, count[i] = section_content:gsub (&amp;#039;.&amp;#039;, &amp;#039;%1&amp;#039;);						-- count the bytes in the section&lt;br /&gt;
			total = total + count[i];&lt;br /&gt;
			max = max &amp;lt; count[i] and count[i] or max;							-- keep track of largest count&lt;br /&gt;
		else																	-- probably the last section (no proper header follows this section name)&lt;br /&gt;
			pattern = &amp;#039;(==+ *&amp;#039; .. escaped_section_name .. &amp;#039; *==+.+)&amp;#039;;			-- make a new pattern&lt;br /&gt;
			section_content = string.match (content, pattern, section_name[2]);		-- try to get content&lt;br /&gt;
			if section_content then&lt;br /&gt;
				_, count[i] = section_content:gsub (&amp;#039;.&amp;#039;, &amp;#039;%1&amp;#039;);					-- count the bytes in the section&lt;br /&gt;
				total = total + count[i];&lt;br /&gt;
				max = max &amp;lt; count[i] and count[i] or max;						-- keep track of largest count&lt;br /&gt;
			else&lt;br /&gt;
				count[i] = &amp;#039;—&amp;#039;;													-- no content so show that&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		_, level[i] = section_content:find (&amp;#039;^=+&amp;#039;);								-- should always be the first n characters of section content&lt;br /&gt;
		&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	totmax=0;&lt;br /&gt;
	lastlevel=0;&lt;br /&gt;
	maxlevels=7;&lt;br /&gt;
	for j=1,maxlevels do&lt;br /&gt;
		levelcounts[j]=0;&lt;br /&gt;
	end&lt;br /&gt;
    for i=#count,1,-1 do&lt;br /&gt;
    	--totcount[i]=level[i];&lt;br /&gt;
    	if level[i]&amp;lt;lastlevel then	-- reset all&lt;br /&gt;
    		totcount[i]=levelcounts[level[i]]+count[i];&lt;br /&gt;
    		for j=level[i],maxlevels do&lt;br /&gt;
				levelcounts[j]=0;&lt;br /&gt;
			end&lt;br /&gt;
    	end&lt;br /&gt;
    	if level[i]&amp;gt;=lastlevel then&lt;br /&gt;
    		totcount[i]=count[i];&lt;br /&gt;
    	end&lt;br /&gt;
		if level[i]&amp;gt;0 then&lt;br /&gt;
	    	upperlevel=level[i]-1;&lt;br /&gt;
	    	levelcounts[upperlevel]=levelcounts[upperlevel]+totcount[i];&lt;br /&gt;
    	end&lt;br /&gt;
		lastlevel=level[i];&lt;br /&gt;
		if totcount[i]&amp;gt;totmax then&lt;br /&gt;
			totmax=totcount[i];&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for i, section_name in ipairs (section_name_list) do&lt;br /&gt;
&lt;br /&gt;
		if count[i]==max then&lt;br /&gt;
			highlight=&amp;#039;color:red;&amp;quot;|&amp;#039;;&lt;br /&gt;
		else &lt;br /&gt;
			highlight=&amp;#039;&amp;quot;|&amp;#039;;&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		highlighttot=&amp;#039;&amp;#039;;														-- start the style declaration&lt;br /&gt;
		if level[i]==2 then&lt;br /&gt;
			highlighttot=highlighttot .. &amp;#039;font-weight:bold;&amp;#039;;					-- if main section, make it bold&lt;br /&gt;
		elseif totcount[i]==count[i] then&lt;br /&gt;
			highlighttot=&amp;#039;color:transparent;&amp;#039;;									-- hide totals for subsections with no subsubsections, values required for proper sorting&lt;br /&gt;
		end&lt;br /&gt;
		if totcount[i]==totmax then&lt;br /&gt;
			highlighttot=highlighttot .. &amp;#039;color:red;&amp;#039;;							-- if the largest size, make it red&lt;br /&gt;
		end&lt;br /&gt;
		highlighttot=highlighttot .. &amp;#039;&amp;quot;|&amp;#039;;										-- close the style declaration&lt;br /&gt;
		&lt;br /&gt;
		level[i] = (2 &amp;lt; level[i]) and ((level[i]-2) * 1.6) or nil;				-- remove offset and mult by 1.6em (same indent as &amp;#039;:&amp;#039; markup which doesn&amp;#039;t work in a table)&lt;br /&gt;
		&lt;br /&gt;
		wl_name = remove_wiki_link (section_name[1]):gsub (&amp;#039;%b{}&amp;#039;, &amp;#039;&amp;#039;);			-- remove wikilinks and templates from section headings so that we can link to the section&lt;br /&gt;
		wl_name = wl_name:gsub (&amp;#039;[%[%]]&amp;#039;, {[&amp;#039;[&amp;#039;]=&amp;#039;&amp;amp;#91;&amp;#039;, [&amp;#039;]&amp;#039;]=&amp;#039;&amp;amp;#93;&amp;#039;});		-- replace &amp;#039;[&amp;#039; and &amp;#039;]&amp;#039; characters with html entities so that wikilinked section names work&lt;br /&gt;
		wl_name = mw.text.trim (wl_name);										-- trim leading/trailing white space if any because white space buggers up url anchor links&lt;br /&gt;
		&lt;br /&gt;
		table.insert (A, table.concat ({										-- build most of a table row here because here we have heading information that we won&amp;#039;t have later&lt;br /&gt;
			level[i] and &amp;#039;&amp;lt;span style=&amp;quot;margin-left:&amp;#039; .. level[i] .. &amp;#039;em&amp;quot;&amp;gt;&amp;#039; or &amp;#039;&amp;#039;;		-- indent per heading level (number of &amp;#039;=&amp;#039; in heading markup)&lt;br /&gt;
			make_wikilink (frame.args[1] .. &amp;#039;#&amp;#039; .. wl_name, wl_name),			-- section link&lt;br /&gt;
			level[i] and &amp;#039;&amp;lt;/span&amp;gt;&amp;#039; or &amp;#039;&amp;#039;,										-- close the span if opened&lt;br /&gt;
			&amp;#039;||&amp;#039;,																-- table column separator&lt;br /&gt;
			&amp;#039;style=&amp;quot;text-align:right;&amp;#039;,											-- the byte count column is right aligned&lt;br /&gt;
			highlight ,&lt;br /&gt;
			lang:formatNum (count[i]),											-- commafied byte count for section&lt;br /&gt;
			&amp;#039;||&amp;#039;,&lt;br /&gt;
			&amp;#039;style=&amp;quot;text-align:right;&amp;#039;,											-- the section total column is right aligned&lt;br /&gt;
			highlighttot ,&lt;br /&gt;
			lang:formatNum (totcount[i]),										-- section total count!!&lt;br /&gt;
		}));																&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local out = {};																-- make a sortable wikitable for output&lt;br /&gt;
	table.insert (out, string.format (&amp;#039;{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;%s&amp;quot;\n|+Section size for [[%s]] (%d sections)&amp;#039;, frame.args.style or &amp;#039;&amp;#039;, frame.args[1], #A));							-- output table header&lt;br /&gt;
	table.insert (out, &amp;#039;\n!Section name!!Byte&amp;lt;br/&amp;gt;count!!Section&amp;lt;br/&amp;gt;total\n|-\n|&amp;#039;);		-- column headers, and first row pipe&lt;br /&gt;
	table.insert (out, table.concat (A, &amp;#039;\n|-\n|&amp;#039;));							-- section rows with leading pipes (except first row already done)&lt;br /&gt;
	table.insert (out, &amp;#039;\n|-\n!Total!!style=&amp;quot;text-align:right&amp;quot;|&amp;#039; .. lang:formatNum (total) .. &amp;#039;!!style=&amp;quot;text-align:right&amp;quot;|&amp;#039; .. lang:formatNum (total));		-- total number of bytes counted as column headers so that sorting doesn&amp;#039;t move this row from the bottom to top&lt;br /&gt;
	table.insert (out, &amp;#039;\n|}&amp;#039;);													-- close the wikitable&lt;br /&gt;
	&lt;br /&gt;
	--max = lang:formatNum (max);												-- commafy so that the commafied value in the table can be found&lt;br /&gt;
	--local result = table.concat (out, &amp;#039;&amp;#039;):gsub (max, &amp;#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;#039; .. max .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;);		-- make a big string, make largest count(s) red, and done&lt;br /&gt;
	local result = table.concat (out, &amp;#039;&amp;#039;);&lt;br /&gt;
	return result;																-- because gsub returns string and number of replacements&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;
	{&lt;br /&gt;
	size = size,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Legoktm</name></author>
	</entry>
</feed>