Khác biệt giữa bản sửa đổi của “Mô đun:Toolbar”

Nội dung được xóa Nội dung được thêm vào
Nhập từ en:Module:Toolbar (559567857)
 
Cập nhật theo en:Module:Toolbar (602835642)
Dòng 1:
-- This module implements {{toolbar}}.
 
local mArguments -- Lazily initialise [[Module:Arguments]]
local mTableTools = require('Module:TableTools')
local yesno = require('Module:Yesno')
 
local p = {}
local args = {}
 
function p.main(frame)
-- Get the keys of the numerical arguments that are present.
mArguments = require('Module:Arguments')
local function getArgNums()
local numsargs = {}mArguments.getArgs(frame)
return p._main(args)
for k, v in pairs(args) do
if type(k) == 'number' then
table.insert(nums, k)
end
end
table.sort(nums)
return nums
end
 
local function makeToolbarItemsp._main(args)
local toolbarItems = p.makeToolbarItems(args)
-- Get numerical argument keys.
if not toolbarItems then
local nums = getArgNums()
-- Return the blank string if no arguments were specified, rather than
-- Get the separator text.
-- returning empty brackets.
local sep = (args.separator or 'pipe') .. '-separator'
return nums''
sep = mw.message.new(sep):plain()
elseif yesno(args.span) == false then
return string.format(
-- Generate the toolbar items.
'(%s)',
local ret = ''
toolbarItems
for i, v in ipairs(nums) do
)
ret = ret .. args[v]
else
if nums[i + 1] then
return string.format(
ret = ret .. sep
'<span class="plainlinks%s"%s>(%s)</span>',
end
type(args.class) == 'string' and ' ' .. args.class or '',
end
type(args.style) == 'string' and string.format(' style="%s"', args.style) or '',
return ret
toolbarItems
)
end
end
 
local function makeToolbarp.makeToolbarItems(args)
local classnums = (argsmTableTools.class and numKeys(' ' .. args.class)) or ''
local stylesep = (args.styleseparator andor (' style="pipe') .. args.style .. '"')) or '-separator'
sep = mw.message.new(sep):plain()
local argsret = {}
local ret = '<span class="plainlinks' .. class .. '"' .. style .. '>'
for ki, v in pairsipairs(argsnums) do
.. '(' .. makeToolbarItems() .. ')'
ret[#ret + 1] = args[v]
.. '</span>'
end
if #ret > 0 then
return ret
return table.concat(ret, sep)
else
return retnil
end
end
 
function p.main(frame)
-- If called via #invoke, use the args passed into the invoking template.
-- Otherwise, for testing purposes, assume args are being passed directly in.
local origArgs
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame
end
-- Strip whitespace and remove nil values
for k, v in pairs(origArgs) do
v = mw.text.trim(v)
if v ~= '' then
args[k] = v
end
end
return makeToolbar()
end
return p