Database changes have finished applying - please report any issues you're (still) seeing to support@shoutwiki.com.
Module:Toolbar
From TechInfoDepot
Jump to navigationJump to search
![]() | This Lua module is used on 1,000,000 pages. To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its /sandbox or /testcases subpages. The tested changes can then be added to this page in one single edit. Please consider discussing any changes on the talk page before implementing them. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module implements {{toolbar}}. Please see the template page for documentation.
The above documentation is transcluded from Module:Toolbar/doc. (edit | history) Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages. Subpages of this module. |
1 -- This module implements {{toolbar}}.
2
3 local mArguments -- Lazily initialise [[Module:Arguments]]
4 local mTableTools = require('Module:TableTools')
5 local yesno = require('Module:Yesno')
6
7 local p = {}
8
9 function p.main(frame)
10 mArguments = require('Module:Arguments')
11 local args = mArguments.getArgs(frame)
12 return p._main(args)
13 end
14
15 function p._main(args)
16 local toolbarItems = p.makeToolbarItems(args)
17 if not toolbarItems then
18 -- Return the blank string if no arguments were specified, rather than
19 -- returning empty brackets.
20 return ''
21 elseif yesno(args.span) == false then
22 return string.format(
23 '(%s)',
24 toolbarItems
25 )
26 else
27 return string.format(
28 '<span class="plainlinks%s"%s>(%s)</span>',
29 type(args.class) == 'string' and ' ' .. args.class or '',
30 type(args.style) == 'string' and string.format(' style="%s"', args.style) or '',
31 toolbarItems
32 )
33 end
34 end
35
36 function p.makeToolbarItems(args)
37 local nums = mTableTools.numKeys(args)
38 local sep = (args.separator or 'pipe') .. '-separator'
39 sep = mw.message.new(sep):plain()
40 local ret = {}
41 for i, v in ipairs(nums) do
42 ret[#ret + 1] = mw.ustring.gsub(args[v], "%[%[::+(.-)%]%]", "[[:%1]]")
43 end
44 if #ret > 0 then
45 return table.concat(ret, sep)
46 else
47 return nil
48 end
49 end
50
51 return p