<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://vion.tail5ecd76.ts.net/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3ATemplate_wrapper</id>
	<title>Модуль:Template wrapper - История изменений</title>
	<link rel="self" type="application/atom+xml" href="https://vion.tail5ecd76.ts.net/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3ATemplate_wrapper"/>
	<link rel="alternate" type="text/html" href="https://vion.tail5ecd76.ts.net/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;action=history"/>
	<updated>2026-11-08T00:36:44Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://vion.tail5ecd76.ts.net/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;diff=7329&amp;oldid=prev</id>
		<title>wp&gt;ru.wikipedia: Импорт из русской Википедии, версия 136859216</title>
		<link rel="alternate" type="text/html" href="https://vion.tail5ecd76.ts.net/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;diff=7329&amp;oldid=prev"/>
		<updated>2024-03-24T23:35:48Z</updated>

		<summary type="html">&lt;p&gt;Импорт из русской Википедии, версия 136859216&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require(&amp;#039;strict&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local error_msg = &amp;#039;&amp;lt;span style=\&amp;quot;font-size:100%;\&amp;quot; class=\&amp;quot;error\&amp;quot;&amp;gt;&amp;lt;code style=\&amp;quot;color:inherit; border:inherit; padding:inherit;\&amp;quot;&amp;gt;&amp;amp;#124;_template=&amp;lt;/code&amp;gt; missing or empty&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[----------------------&amp;lt; I S _ I N _ T A B L E &amp;gt;-----------------------------&lt;br /&gt;
&lt;br /&gt;
scan through tbl looking for value; return true if found, false else&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function is_in_table(tbl, value)&lt;br /&gt;
	for k, v in pairs(tbl) do&lt;br /&gt;
		if v == value then return true end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[----------------------&amp;lt; A D D _ P A R A M E T E R &amp;gt;-------------------------&lt;br /&gt;
&lt;br /&gt;
adds parameter name and its value to args table according to the state of boolean list argument; kv pair for&lt;br /&gt;
template execution; k=v string for template listing.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
local function add_parameter(k, v, args, list)&lt;br /&gt;
	if list then&lt;br /&gt;
		table.insert(args, table.concat({k, &amp;#039;=&amp;#039;, v}))  -- write parameter names and values to args table as string&lt;br /&gt;
	else&lt;br /&gt;
		args[k] = v  -- copy parameters to args table&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[----------------------&amp;lt; A L I A S _ M A P _ G E T &amp;gt;-------------------------&lt;br /&gt;
&lt;br /&gt;
returns a table of local template (parent frame) parameter names and the target template names that match where&lt;br /&gt;
in [key]=&amp;lt;value&amp;gt; pairs where:&lt;br /&gt;
	[key] is local template parameter name (an alias)&lt;br /&gt;
	&amp;lt;value&amp;gt; is target template parameter name (the canonical parameter name used in the working template)&lt;br /&gt;
&lt;br /&gt;
The parameter |_alias-map= has the form:&lt;br /&gt;
	|_alias-map=&amp;lt;list&amp;gt;&lt;br /&gt;
where &amp;lt;list&amp;gt; is a comma-separated list of alias / canonical parameter name pairs in the form&lt;br /&gt;
	&amp;lt;from&amp;gt; : &amp;lt;to&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
	&amp;lt;from&amp;gt; is the local template&amp;#039;s parameter name (alias)&lt;br /&gt;
	&amp;lt;to&amp;gt; is the target template&amp;#039;s parameter name (canonical)&lt;br /&gt;
	for enumerated parameters place an octothorp (#) where the enumerator digits are placed in the parameter names:&lt;br /&gt;
		&amp;lt;from#&amp;gt; : &amp;lt;to#&amp;gt;&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
local function alias_map_get(_alias_map)&lt;br /&gt;
	local T = mw.text.split(_alias_map, &amp;#039;%s*,%s*&amp;#039;)  -- convert the comma-separated list into a table of alias pairs&lt;br /&gt;
	local mapped_aliases = {}  -- mapped aliases will go here&lt;br /&gt;
	local l_name, t_name  -- parameter names&lt;br /&gt;
&lt;br /&gt;
	for _, alias_pair in ipairs(T) do  -- loop through the table of alias pairs&lt;br /&gt;
		l_name, t_name = alias_pair:match(&amp;#039;(.-)%s*:%s*(.+)&amp;#039;)  -- from each pair, get local and target parameter names&lt;br /&gt;
		if l_name and t_name then  -- if both are set&lt;br /&gt;
			if tonumber(l_name) then&lt;br /&gt;
				l_name = tonumber(l_name)  -- convert number-as-text to a number&lt;br /&gt;
			end&lt;br /&gt;
			mapped_aliases[l_name] = t_name  -- add them to the map table&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return mapped_aliases&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[----------------------&amp;lt; F R A M E _ A R G S _ G E T &amp;gt;-----------------------&lt;br /&gt;
&lt;br /&gt;
Fetch the wrapper template&amp;#039;s &amp;#039;default&amp;#039; and control parameters; adds default parameters to args&lt;br /&gt;
&lt;br /&gt;
returns content of |_template= parameter(name of the working template); nil else&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
local function frame_args_get(frame_args, args, list)&lt;br /&gt;
	local template&lt;br /&gt;
&lt;br /&gt;
	for k, v in pairs(frame_args) do  -- here we get the wrapper template&amp;#039;s &amp;#039;default&amp;#039; parameters&lt;br /&gt;
		if type(k) == &amp;#039;string&amp;#039; and (v and (v ~= &amp;#039;&amp;#039;)) then  -- do not pass along positional or empty parameters&lt;br /&gt;
			if k == &amp;#039;_template&amp;#039; then&lt;br /&gt;
				template = v  -- save the name of template that we are wrapping&lt;br /&gt;
			elseif k ~= &amp;#039;_exclude&amp;#039; and k ~= &amp;#039;_reuse&amp;#039; and k ~= &amp;#039;_include-positional&amp;#039; and k ~= &amp;#039;_alias-map&amp;#039; then -- these already handled so ignore here&lt;br /&gt;
				add_parameter(k, v, args, list)  -- add all other parameters to args in the style dictated by list&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return template  -- return contents of |_template= parameter&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[=[---------------------&amp;lt; P F R A M E _ A R G S _ G E T &amp;gt;---------------------&lt;br /&gt;
&lt;br /&gt;
Fetches the wrapper template&amp;#039;s &amp;#039;live&amp;#039; parameters; adds live parameters that aren&amp;#039;t members of the exclude table to&lt;br /&gt;
args table; positional parameters may not be excluded&lt;br /&gt;
&lt;br /&gt;
no return value&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
local function pframe_args_get(pframe_args, args, exclude, _include_positional, list)&lt;br /&gt;
	for k, v in pairs(pframe_args) do&lt;br /&gt;
		if type(k) == &amp;#039;string&amp;#039; and not is_in_table(exclude, k) then  -- do not pass along excluded parameters&lt;br /&gt;
			if v and (v ~= &amp;#039;&amp;#039;) then  -- pass along only those parameters that have assigned values&lt;br /&gt;
				if v:lower() == &amp;#039;unset&amp;#039; then  -- special keyword to unset &amp;#039;default&amp;#039; parameters set in the wrapper template&lt;br /&gt;
					v = &amp;#039;&amp;#039;  -- unset the value in the args table&lt;br /&gt;
				end&lt;br /&gt;
				add_parameter(k, v, args, list)  -- add all other parameters to args in the style dictated by list; alias map only supported for local-template parameters&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if _include_positional then&lt;br /&gt;
		for i, v in ipairs(pframe_args) do  -- pass along positional parameters&lt;br /&gt;
			if v:lower() == &amp;#039;unset&amp;#039; then  -- special keyword to unset &amp;#039;default&amp;#039; parameters set in the wrapper template&lt;br /&gt;
				v = &amp;#039;&amp;#039;  -- unset the value in the args table&lt;br /&gt;
			end&lt;br /&gt;
			add_parameter(i, v, args, list)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[----------------------&amp;lt; _ M A I N &amp;gt;-----------------------------------------&lt;br /&gt;
&lt;br /&gt;
Collect the various default and live parameters into args styled according to boolean list.&lt;br /&gt;
&lt;br /&gt;
returns name of the working or listed template or nil for an error message&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
local function _main(frame, args, list)&lt;br /&gt;
	local template&lt;br /&gt;
	local exclude = {}  -- table of parameter names for parameters that are not passed to the working template&lt;br /&gt;
	local reuse_list = {}  -- table of pframe parameter names whose values are modified before they are passed to the working template as the same name&lt;br /&gt;
	local alias_map = {}  -- table that maps parameter aliases to working template canonical parameter names&lt;br /&gt;
	local _include_positional&lt;br /&gt;
&lt;br /&gt;
	if frame.args._exclude and (frame.args._exclude ~= &amp;#039;&amp;#039;) then  -- if there is |_exclude= and it&amp;#039;s not empty&lt;br /&gt;
		exclude = mw.text.split(frame.args._exclude, &amp;quot;%s*,%s*&amp;quot;)  -- make a table from its contents&lt;br /&gt;
	end&lt;br /&gt;
  -- TODO: |_reuse= needs a better name (|_reuse=)&lt;br /&gt;
	if frame.args._reuse and (frame.args._reuse ~= &amp;#039;&amp;#039;) then  -- if there is |_reuse= and it&amp;#039;s not empty&lt;br /&gt;
		reuse_list = mw.text.split(frame.args._reuse, &amp;quot;%s*,%s*&amp;quot;)  -- make a table from its contents&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if frame.args[&amp;#039;_alias-map&amp;#039;] and (frame.args[&amp;#039;_alias-map&amp;#039;] ~= &amp;#039;&amp;#039;) then  -- if there is |_alias-map= and it&amp;#039;s not empty&lt;br /&gt;
		alias_map = alias_map_get(frame.args[&amp;#039;_alias-map&amp;#039;])  -- make a table from its contents&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	template = frame_args_get(frame.args, args, list)  -- get parameters provided in the {{#invoke:template wrapper| .. .| .. .}}&lt;br /&gt;
	if template == nil or template == &amp;#039;&amp;#039; then  -- this is the one parameter that is required by this module&lt;br /&gt;
		return nil  -- not present, tell calling function to emit an error message&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	_include_positional = frame.args[&amp;#039;_include-positional&amp;#039;] == &amp;#039;yes&amp;#039;  -- when true pass all positional parameters along with non-excluded named parameters to the working template; positional parameters are not excludable&lt;br /&gt;
&lt;br /&gt;
	local _pframe_args = frame:getParent().args  -- here we get the wrapper template&amp;#039;s &amp;#039;live&amp;#039; parameters from pframe.args&lt;br /&gt;
	local pframe_args = {}  -- a local table that we can modify&lt;br /&gt;
&lt;br /&gt;
	for k, v in pairs(_pframe_args) do  -- make a copy that we can modify&lt;br /&gt;
		pframe_args[k] = v&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- here we look for pframe parameters that are aliases of canonical parameter names; when found&lt;br /&gt;
	-- we replace the alias with the canonical.  We do this here because the reuse_list works on&lt;br /&gt;
	-- canonical parameter names so first we convert alias parameter names to canonical names and then&lt;br /&gt;
	-- we remove those canonical names from the pframe table that are reused (provided to the working&lt;br /&gt;
	-- template through the frame args table)&lt;br /&gt;
&lt;br /&gt;
	for k, v in pairs(alias_map) do  -- k is alias name, v is canonical name&lt;br /&gt;
		if pframe_args[k] then  -- if pframe_args has parameter with alias name&lt;br /&gt;
			pframe_args[v] = _pframe_args[k]  -- create new canonical name with alias&amp;#039; value&lt;br /&gt;
			pframe_args[k] = nil  -- unset the alias&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for k, v in pairs(pframe_args) do  -- do enumerated parameter alias -&amp;gt; canonical translation&lt;br /&gt;
		if type(k) == &amp;#039;string&amp;#039; then  -- only named parameters can be enumerated&lt;br /&gt;
			if alias_map[k .. &amp;#039;#&amp;#039;] then  -- non-enumerated alias matches enumerated parameter pattern? enumerator at end only&lt;br /&gt;
				pframe_args[alias_map[k .. &amp;#039;#&amp;#039;]:gsub(&amp;#039;#&amp;#039;, &amp;#039;&amp;#039;)] = v  -- remove &amp;#039;#&amp;#039; and copy parameter to pframe_args table&lt;br /&gt;
				pframe_args[k] = nil  -- unset the alias&lt;br /&gt;
			elseif k:match(&amp;#039;%d+&amp;#039;) then  -- if this parameter name contains digits&lt;br /&gt;
				local temp = k:gsub(&amp;#039;%d+&amp;#039;, &amp;#039;#&amp;#039;)  -- make a copy; digits replaced with single &amp;#039;#&amp;#039;&lt;br /&gt;
				local enum = k:match(&amp;#039;%d+&amp;#039;)  -- get the enumerator&lt;br /&gt;
&lt;br /&gt;
				if alias_map[temp] then  -- if this parameter is a recognized enumerated alias&lt;br /&gt;
					pframe_args[alias_map[temp]:gsub(&amp;#039;#&amp;#039;, enum)] = v  -- use canonical name and replace &amp;#039;#&amp;#039; with enumerator and add to pframe_args&lt;br /&gt;
					pframe_args[k] = nil  -- unset the alias&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- pframe parameters that are _reused are &amp;#039;reused&amp;#039; have the form something like this:&lt;br /&gt;
	-- |chapter=[[wikisource:{{{chapter}}}|{{{chapter}}}]]&lt;br /&gt;
	-- where a parameter in the wrapping template is modified and then passed to the working template&lt;br /&gt;
	-- using the same parameter name (in this example |chapter=)&lt;br /&gt;
&lt;br /&gt;
	-- remove parameters that will be reused&lt;br /&gt;
	for k, v in ipairs(reuse_list) do  -- k is numerical index, v is canonical parameter name to ignore&lt;br /&gt;
		if pframe_args[v] then  -- if pframe_args has parameter that should be ignored&lt;br /&gt;
			pframe_args[v] = nil  -- unset the ignored parameter&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	pframe_args_get(pframe_args, args, exclude, _include_positional, list) -- add parameters and values to args that are not listed in the exclude table&lt;br /&gt;
&lt;br /&gt;
	return template  -- args now has all default and live parameters, return working template name&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[----------------------&amp;lt; W R A P &amp;gt;-------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Template entry point.  Call this function to &amp;#039;execute&amp;#039; the working template&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
local function wrap(frame)&lt;br /&gt;
	local args = {}  -- table of default and live parameters and their values to be passed to the wrapped template&lt;br /&gt;
	local template  -- the name of the working template&lt;br /&gt;
&lt;br /&gt;
	template = _main(frame, args, false)  -- get default and live parameters and the name of the working template&lt;br /&gt;
	if not template then  -- template name is required&lt;br /&gt;
		return error_msg  -- emit error message and abandon if template name not present&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return frame:expandTemplate({title=template, args=args})  -- render the working template&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;
Template entry point.  Call this function to &amp;#039;display&amp;#039; the source for the working template.  This function added&lt;br /&gt;
as a result of a TfD here: Wikipedia:Templates_for_discussion/Log/2018_April_28#Module:PassArguments&lt;br /&gt;
&lt;br /&gt;
This function replaces a similarly named function which was used in {{cite compare}} and {{cite compare2}}&lt;br /&gt;
&lt;br /&gt;
Values in the args table are numerically indexed strings in the form &amp;#039;name=value&amp;#039;&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
local function list(frame, do_link)&lt;br /&gt;
	local args = {}  -- table of default and live parameters and their values to be passed to the listed template&lt;br /&gt;
	local template  -- the name of the listed template&lt;br /&gt;
&lt;br /&gt;
	template = _main(frame, args, true)  -- get default and live parameters and the name of the listed template&lt;br /&gt;
	if not template then  -- template name is required&lt;br /&gt;
		return error_msg  -- emit error message and abandon if template name not present&lt;br /&gt;
	end&lt;br /&gt;
	if do_link then&lt;br /&gt;
		template = (&amp;#039;[[%s|%s]]&amp;#039;):format(frame:expandTemplate({title=&amp;#039;Transclude&amp;#039;, args={template}}), template)&lt;br /&gt;
	end&lt;br /&gt;
	table.sort(args)&lt;br /&gt;
	for i=1, #args do&lt;br /&gt;
		local stripped = args[i]:match(&amp;#039;^&amp;#039; .. i .. &amp;#039;=([^=]*)$&amp;#039;)&lt;br /&gt;
		if stripped then args[i] = stripped else break end&lt;br /&gt;
	end&lt;br /&gt;
	return frame:preprocess(table.concat({&lt;br /&gt;
		&amp;#039;&amp;lt;code style=&amp;quot;color:inherit; background:inherit; border:none;&amp;quot;&amp;gt;&amp;amp;#123;&amp;amp;#123;&amp;#039;,&lt;br /&gt;
		template,&lt;br /&gt;
		(&amp;#039;&amp;lt;wbr&amp;gt;&amp;lt;nowiki&amp;gt;|%s&amp;lt;/nowiki&amp;gt;&amp;#039;):rep(#args):format(unpack(args)), &amp;#039;&amp;amp;#125;&amp;amp;#125;&amp;lt;/code&amp;gt;&amp;#039;})) -- render the template&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function link(frame)&lt;br /&gt;
	return list(frame, true)&lt;br /&gt;
end&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;
	link = link,&lt;br /&gt;
	list = list,&lt;br /&gt;
	wrap = wrap,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>wp&gt;ru.wikipedia</name></author>
	</entry>
</feed>