<?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%2Ftrappist_the_monk%2Ftemplate_compare</id>
	<title>Module:Sandbox/trappist the monk/template compare - 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%2Ftrappist_the_monk%2Ftemplate_compare"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/template_compare&amp;action=history"/>
	<updated>2026-07-29T08:38:38Z</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/trappist_the_monk/template_compare&amp;diff=146634&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/trappist_the_monk/template_compare&amp;diff=146634&amp;oldid=prev"/>
		<updated>2022-10-23T21:04:19Z</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;&lt;br /&gt;
--{{#invoke:Sandbox/trappist the monk/template compare|compare|&amp;lt;template A&amp;gt;|&amp;lt;template B&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; T E M P L A T E _ P A R A M S _ G E T &amp;gt;----------------------------------------&lt;br /&gt;
&lt;br /&gt;
gets parameters used by template from unparsed template wikitext and adds each to param_list.&lt;br /&gt;
&lt;br /&gt;
returns true on success; false when template does not exist&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function template_params_get (template, param_list)&lt;br /&gt;
	local content = mw.title.new (template):getContent();						-- get unparsed wikitext from the template&lt;br /&gt;
	if not content then&lt;br /&gt;
		return false;															-- announce failure&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for param in content:gmatch (&amp;#039;{{{([^}|]+)&amp;#039;) do								-- fetch each parameter in the template&lt;br /&gt;
		param_list[param] = true;												-- and add it to its list table&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return true;																-- announce success&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; D I F F _ L I S T _ M A K E &amp;gt;--------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
loop through source template&amp;#039;s parameter list looking for parameters not also found in target&amp;#039;s parameter list.&lt;br /&gt;
when parameter is unique to source, add it to diff list with source template&amp;#039;s name&lt;br /&gt;
&lt;br /&gt;
returns nothing&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function 	diff_list_make (src, tgt, src_name, diff)&lt;br /&gt;
	for param, _ in pairs (src) do												-- look for source template parameters in target template&amp;#039;s parameter list&lt;br /&gt;
		if not tgt[param] then&lt;br /&gt;
			diff[param] = src_name;												-- not found add to diff table with name of source template&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; C O M P A R E &amp;gt;----------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
module entry point&lt;br /&gt;
&lt;br /&gt;
create a list of parameter names not shared between two templates&lt;br /&gt;
&lt;br /&gt;
returns the list of unique parameter names&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function compare (frame)&lt;br /&gt;
	local A = {};																-- table to hold the parameters used in the first of two templates&lt;br /&gt;
	local B = {};																-- table to hold the parameters used in the second of two templates&lt;br /&gt;
	local diff = {};															-- table to hold the parameters that are not shared between the two templates&lt;br /&gt;
&lt;br /&gt;
	local A_src = frame.args[1];												-- get template names&lt;br /&gt;
	local B_src = frame.args[2];&lt;br /&gt;
	&lt;br /&gt;
	if not A_src:match (&amp;#039;^Template:&amp;#039;) then										-- if namespace missing&lt;br /&gt;
		A_src = &amp;#039;Template:&amp;#039; .. A_src;											-- add it&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not B_src:match (&amp;#039;^Template:&amp;#039;) then										-- if namespace missing&lt;br /&gt;
		B_src = &amp;#039;Template:&amp;#039; .. B_src;											-- add it&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local ret_val = template_params_get (A_src, A);								-- get parameters from first template&lt;br /&gt;
	if not ret_val 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 &amp;#039; .. A_src .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
		&lt;br /&gt;
	ret_val = template_params_get (B_src, B);									-- get parameters from second template&lt;br /&gt;
	if not ret_val 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 &amp;#039; .. B_src .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	diff_list_make (A, B, A_src:gsub (&amp;#039;^Template:&amp;#039;, &amp;#039;&amp;#039;), diff);					-- add parameters used in A that are not used in B; strip namespace for readability&lt;br /&gt;
	diff_list_make (B, A, B_src:gsub (&amp;#039;^Template:&amp;#039;, &amp;#039;&amp;#039;), diff);					-- add parameters used in B that are not used in A&lt;br /&gt;
&lt;br /&gt;
	return mw.dumpObject (diff);												-- for now; prettify later&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; L I S T &amp;gt;----------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
module entry point&lt;br /&gt;
&lt;br /&gt;
create a list of parameter names&lt;br /&gt;
&lt;br /&gt;
returns the list of parameter names&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function list (frame)&lt;br /&gt;
	local A = {};																-- table to hold the parameters used in the first of two templates&lt;br /&gt;
&lt;br /&gt;
	local A_src = frame.args[1];												-- get template names&lt;br /&gt;
&lt;br /&gt;
	if not A_src:match (&amp;#039;^Template:&amp;#039;) then										-- if namespace missing&lt;br /&gt;
		A_src = &amp;#039;Template:&amp;#039; .. A_src;											-- add it&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local ret_val = template_params_get (A_src, A);								-- get parameters from first template&lt;br /&gt;
	if not ret_val 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 &amp;#039; .. A_src .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
		&lt;br /&gt;
	return mw.dumpObject (A);													-- for now; prettify later&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;
	compare = compare,&lt;br /&gt;
	list = list,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Legoktm</name></author>
	</entry>
</feed>