Module:Template invocation:修订间差异

删除的内容 添加的内容
zhwiki>Xiplus-abot
小 已更改“Module:Template invocation”的保护等级:高風險模板:8728引用<!-- 機器人3 -->([编辑=仅允许模板编辑员和管理员](无限期)[移动=仅允许模板编辑员和管理员](无限期))
 
enwiki>Pppery
Update name call to fix a few edge cases per request
标签:已被回退
第20行:
if type(title) == 'string' then
title = mw.title.new(title)
if not title or #title.prefixedText == 0 or #title.interwiki > 0 then
error("invalid title in parameter #1 of function 'name'", 2)
end
第27行:
end
if title.namespace == 10 then
returnlocal text = title.text
local check = mw.title.new(text, 10)
-- Exclude the prefix, unless we have something like "Template:Category:Foo", which can't be abbreviated to "Category:Foo".
return check and mw.title.equals(title, check) and text or title.prefixedText
elseif title.namespace == 0 then
return ':' .. title.prefixedText
第34行 ⟶ 第37行:
end
end
 
------------------------------------------------------------------------
-- Name: p.invocation
第41行 ⟶ 第43行:
-- name and the arguments given. Note that it isn't
-- perfect: we have no way of knowing what whitespace was
-- in the original invocation, the ordernamed ofparameters thewill parametersbe
-- mayalphabetically be changedsorted, and any parameters with duplicate keys
-- will be removed.
-- Parameters: name - the template name, formatted as it will appear
第93行 ⟶ 第95行:
ret[#ret + 1] = name
for k, v in ipairs(invArgs) do
if type(v) == 'string' and v:find('=', 1, true) then
-- Likely something like 1=foo=bar, wewhich needneeds to dobe itdisplayed as a named arg.
breakelse
ret[#ret + 1] = seps.pipe▼
ret[#ret + 1] = v▼
invArgs[k] = nil -- Erase the key so that we don't add the value twice▼
end
▲ ret[#ret + 1] = seps.pipe
▲ ret[#ret + 1] = v
▲ invArgs[k] = nil -- Erase the key so that we don't add the value twice
end
local keys = {} -- sort parameter list; better than arbitrary order
for k, v_ in pairs(invArgs) do
ret[#ret + 1] = seps.pipe▼
retkeys[#retkeys + 1] = k
end
table.sort(keys,
function (a, b)
-- Sort with keys of type number first, then string.
if type(a) == type(b) then
return a < b
elseif type(a) == 'number' then
return true
end
end
)
local maybeSpace = '' -- First named parameter should not be separated by a space
for _, v in ipairs(keys) do -- Add named args based on sorted parameter list
▲ ret[#ret + 1] = maybeSpace .. seps.pipe
ret[#ret + 1] = tostring(v)
ret[#ret + 1] = seps.equals
ret[#ret + 1] = invArgs[v]
maybeSpace = ' '
end
ret[#ret + 1] = seps.closeb