کاربر ناشناس
پودمان:Template wrapper: تفاوت میان نسخهها
update
imported>Dalba جز («پودمان:Template wrapper» را محافظت کرد: الگوهای حساس: Special:Permalink/25972711#پود:Template_wrapper، نزدیک به 18 هزار کاربرد ([ویرایش=تنها مدیران] (بیپایان) [انتقال=تنها مدیران] (بیپایان))) |
(update) |
||
خط ۱: | خط ۱: | ||
require('Module:No globals'); | require('Module:No globals'); | ||
local error_msg = '<span style=\"font-size:100%\" class=\"error\"><code style=\"color:inherit; border:inherit; padding:inherit;\">|_template=</code> | local error_msg = '<span style=\"font-size:100%\" class=\"error\">پارامتر <code style=\"color:inherit; border:inherit; padding:inherit;\">|_template=</code> ناموجود یا خالی</span>'; | ||
خط ۵۹: | خط ۵۹: | ||
for _, alias_pair in ipairs (T) do -- loop through the table of alias pairs | for _, alias_pair in ipairs (T) do -- loop through the table of alias pairs | ||
l_name, t_name = | l_name, t_name = mw.ustring.match (alias_pair, '(.-)%s*:%s*(.+)'); -- from each pair, get local and target parameter names | ||
if l_name and t_name then -- if both are set | if l_name and t_name then -- if both are set | ||
if | if mw.getContentLanguage():parseFormattedNumber(l_name) then | ||
l_name = | l_name = mw.getContentLanguage():parseFormattedNumber(l_name); -- convert number-as-text to a number | ||
end | end | ||
mapped_aliases[l_name] = t_name; -- add them to the map table | mapped_aliases[l_name] = t_name; -- add them to the map table | ||
خط ۱۸۷: | خط ۱۸۷: | ||
if 'string' == type (k) then -- only named parameters can be enumerated | if 'string' == type (k) then -- only named parameters can be enumerated | ||
if alias_map[k..'#'] then -- non-enumerated alias matches enumerated parameter pattern? enumerator at end only | if alias_map[k..'#'] then -- non-enumerated alias matches enumerated parameter pattern? enumerator at end only | ||
pframe_args[alias_map[k..'#'] | pframe_args[mw.ustring.gsub(alias_map[k..'#'], '#', '')] = v; -- remove '#' and copy parameter to pframe_args table | ||
pframe_args[k] = nil; -- unset the alias | pframe_args[k] = nil; -- unset the alias | ||
elseif | elseif mw.ustring.match (k, '%d+') then -- if this parameter name contains digits | ||
local temp = | local temp = mw.ustring.gsub (k, '%d+', '#'); -- make a copy; digits replaced with single '#' | ||
local enum = | local enum = mw.ustring.match (k, '%d+'); -- get the enumerator | ||
if alias_map[temp] then -- if this parameter is a recognized enumerated alias | if alias_map[temp] then -- if this parameter is a recognized enumerated alias | ||
pframe_args[alias_map[temp] | pframe_args[mw.ustring.gsub(alias_map[temp], '#', enum)] = v; -- use canonical name and replace '#' with enumerator and add to pframe_args | ||
pframe_args[k] = nil; -- unset the alias | pframe_args[k] = nil; -- unset the alias | ||
end | end | ||
خط ۲۴۱: | خط ۲۴۱: | ||
Template entry point. Call this function to 'display' the source for the working template. This function added | Template entry point. Call this function to 'display' the source for the working template. This function added | ||
as a result of a TfD here: | as a result of a TfD here: imamatpedia:Templates_for_discussion/Log/2018_April_28#Module:PassArguments | ||
This function replaces a similarly named function which was used in {{cite compare}} and {{cite compare2}} | This function replaces a similarly named function which was used in {{cite compare}} and {{cite compare2}} | ||
خط ۲۴۹: | خط ۲۴۹: | ||
]] | ]] | ||
local function list(frame, do_link) | |||
local args = {}; -- table of default and live parameters and their values to be passed to the listed template | |||
local template; -- the name of the listed template | |||
template = _main (frame, args, true); -- get default and live parameters and the name of the listed template | |||
if not template then -- template name is required | |||
return error_msg; -- emit error message and abandon if template name not present | |||
end | |||
template = _main (frame, args, true); | if do_link then | ||
if not template then | template = mw.ustring.format(('[[%s|%s]]'), frame:expandTemplate{ title='Transclude', args = {template} }, template) | ||
return error_msg; | end | ||
table.sort(args) | |||
for i = 1, #args do | |||
local stripped = mw.ustring.match(args[i], '^' .. i .. '=([^=]*)$') | |||
if stripped then args[i] = stripped else break end | |||
end | end | ||
return frame:preprocess(table.concat({ | |||
'<code style="color:inherit; background:inherit; border:none;">{{', | |||
template, | |||
('<wbr><nowiki>|%s</nowiki>'):rep(#args):format(unpack(args)), '}}</code>'})); -- render the template | |||
end | |||
return frame | local function link (frame) | ||
return list(frame, true) | |||
end | end | ||
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------ | --[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------ | ||
خط ۲۶۷: | خط ۲۷۹: | ||
return { | return { | ||
link = link, | |||
list = list, | list = list, | ||
wrap = wrap, | wrap = wrap, | ||
}; | }; |