Module:Toolbar
Appearance
| This Lua module is used in system messages, and on approximately 1,460,000 pages, or roughly 2% of all pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This module depends on the following other modules: |
This module implements {{toolbar}}. Please see the template page for documentation.
See also
- {{toolbar}}, {{toolbar/sandbox}}, /testcases
local p = {}
local args = {}
-- Get the keys of the numerical arguments that are present.
local function getArgNums()
local nums = {}
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 makeToolbarItems()
-- Get numerical argument keys.
local nums = getArgNums()
-- Get the separator text.
local sep = (args.separator or 'pipe') .. '-separator'
sep = mw.message.new(sep):plain()
-- Generate the toolbar items.
local ret = ''
for i, v in ipairs(nums) do
ret = ret .. args[v]
if nums[i + 1] then
ret = ret .. sep
end
end
return ret
end
local function makeToolbar()
local class = args.class or ''
local style = (args.style and ('style="' .. args.style .. '"')) or ''
local ret = '<span class="plainlinks ' .. class .. '" ' .. style .. '>'
.. '(' .. makeToolbarItems() .. ')'
.. '</span>'
return ret
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