<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://wiki-data.rcsi.science/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://wiki-data.rcsi.science/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://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;action=history"/>
	<updated>2026-04-03T22:41:14Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;diff=690&amp;oldid=prev</id>
		<title>Admin: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;diff=690&amp;oldid=prev"/>
		<updated>2021-11-15T13:05:33Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия 13:05, 15 ноября 2021&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key wikidb:diff::1.12:old-689:rev-690 --&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;diff=689&amp;oldid=prev</id>
		<title>ru&gt;GKFX: Add uncopyable line break opportunities to documentation mode</title>
		<link rel="alternate" type="text/html" href="https://wiki-data.rcsi.science/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Template_wrapper&amp;diff=689&amp;oldid=prev"/>
		<updated>2021-05-08T08:01:01Z</updated>

		<summary type="html">&lt;p&gt;Add uncopyable line break opportunities to documentation mode&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require('Module:No globals');&lt;br /&gt;
&lt;br /&gt;
local error_msg = '&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;';&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;
&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, '=', 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's parameter name (alias)&lt;br /&gt;
	&amp;lt;to&amp;gt; is the target template'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;
&lt;br /&gt;
local function alias_map_get (_alias_map)&lt;br /&gt;
	local T = mw.text.split (_alias_map, '%s*,%s*');							-- 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 ('(.-)%s*:%s*(.+)');					-- 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's 'default' 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;
&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's 'default' parameters&lt;br /&gt;
		if 'string' == type (k) and (v and ('' ~= v)) then						-- do not pass along positional or empty parameters&lt;br /&gt;
			if '_template' == k then&lt;br /&gt;
				template = v;													-- save the name of template that we are wrapping&lt;br /&gt;
			elseif '_exclude' ~= k and '_reuse' ~= k and '_include-positional' ~= k  and '_alias-map' ~= k 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's 'live' parameters; adds live parameters that aren'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;
&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 'string' == type (k) and not is_in_table (exclude, k) then			-- do not pass along excluded parameters&lt;br /&gt;
			if v and ('' ~= v) then												-- pass along only those parameters that have assigned values&lt;br /&gt;
				if 'unset' == v:lower() then									-- special keyword to unset 'default' parameters set in the wrapper template&lt;br /&gt;
					v = '';														-- 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 'unset' == v:lower() then										-- special keyword to unset 'default' parameters set in the wrapper template&lt;br /&gt;
				v = '';															-- 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;
&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) then					-- if there is |_exclude= and it'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) then					-- if there is |_reuse= and it'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['_alias-map'] and ('' ~= frame.args['_alias-map']) then		-- if there is |_alias-map= and it's not empty&lt;br /&gt;
		alias_map = alias_map_get (frame.args['_alias-map']);					-- 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 nil == template or '' == template 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 = 'yes' == frame.args['_include-positional'];			-- when true pass all positional parameters along with non-excluded named parameters to ...&lt;br /&gt;
																				-- ... 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's 'live' 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' 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 'string' == type (k) then											-- only named parameters can be enumerated&lt;br /&gt;
			if alias_map[k..'#'] then											-- non-enumerated alias matches enumerated parameter pattern? enumerator at end only&lt;br /&gt;
				pframe_args[alias_map[k..'#']:gsub('#', '')] = v;				-- remove '#' and copy parameter to pframe_args table&lt;br /&gt;
				pframe_args[k] = nil;											-- unset the alias&lt;br /&gt;
			elseif k:match ('%d+') then											-- if this parameter name contains digits&lt;br /&gt;
				local temp = k:gsub ('%d+', '#');								-- make a copy; digits replaced with single '#'&lt;br /&gt;
				local enum = k:match ('%d+');									-- 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('#', enum)] = v;			-- use canonical name and replace '#' 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 'reused' 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 'execute' the working template&lt;br /&gt;
&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 'display' 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 'name=value'&lt;br /&gt;
&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 = ('[[%s|%s]]'):format(frame:expandTemplate{ title='Transclude', 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('^' .. i .. '=([^=]*)$')&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;lt;code style=&amp;quot;color:inherit; background:inherit; border:none;&amp;quot;&amp;gt;&amp;amp;#123;&amp;amp;#123;',&lt;br /&gt;
		template,&lt;br /&gt;
		('&amp;lt;wbr&amp;gt;&amp;lt;nowiki&amp;gt;|%s&amp;lt;/nowiki&amp;gt;'):rep(#args):format(unpack(args)), '&amp;amp;#125;&amp;amp;#125;&amp;lt;/code&amp;gt;'}));	-- 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>ru&gt;GKFX</name></author>
	</entry>
</feed>