Mô đun:CA
Tài liệu mô đun[tạo]
local p = {}
local function makeError(msg)
msg = 'Lỗi: ' .. msg
return mw.text.tag('strong', {['class']='error'}, msg)
end
function p.CA(frame)
local origArgs = frame:getParent().args
local args = {}
local maxArg = 1
local usernames = 0
local j = 3
for j, a in pairs(origArgs) do
a = j - 2
args[a] = args[j]
end
for k, v in pairs(origArgs) do
if type(k) == 'number' then
if mw.ustring.match(v,'%S') then
if k - 2 > maxArg then maxArg = k - 2 end
usernames = usernames + 1
local title = mw.title.new(v)
if not title then return makeError('Dữ liệu vào chứa các ký tự bị cấm.') end
args[k] = title.rootText
end
end
local isfirst = true
for i = 1, maxArg do
if args[i] then
if isfirst then
isfirst = false
else
if ( (usernames > 2) or ((usernames == 2) and (args['c'] == '')) ) then outStr = outStr..', ' end
if i == maxArg - 2 then outStr = outStr..' '..(args['c'] or 'và') .. ' ' end
outStr = string.format(
'%s[[Special:CentralAuth/%s|%s]]',
outStr,
args[i],
args[i]
)
end
end
end
return mw.text.tag('span', {['class']='template-ping'}, outStr)
end
end
return p