Module:Babel: Difference between revisions
Content added Content deleted
Vivaporius (talk | contribs) m (1 revision imported) |
en>T0oxi22 No edit summary |
||
Line 2: | Line 2: | ||
local getArgs |
local getArgs |
||
local function showUserbox(frame, v, nocat) |
|||
local maybeNocat = '' |
|||
if nocat then |
|||
maybeNocat = '|nocat=yes' |
|||
end |
|||
return frame:preprocess('{{User '..v..maybeNocat..'}}') |
|||
end |
|||
function p.main(frame) |
function p.main(frame) |
||
Line 10: | Line 18: | ||
local ret = mw.html.create('table') |
local ret = mw.html.create('table') |
||
:attr('role', 'presentation') |
|||
:addClass('userboxes') |
:addClass('userboxes') |
||
:css( { |
:css( { |
||
Line 18: | Line 27: | ||
clear = args.align or 'right', |
clear = args.align or 'right', |
||
color = args.textcolor or '#000000', |
color = args.textcolor or '#000000', |
||
border = (bordercolor or '#99B3FF') .. ' solid ' .. (args.solid or 1)..'px' |
border = (args.bordercolor or '#99B3FF') .. ' solid ' .. (args.solid or 1)..'px' |
||
} ) |
} ) |
||
local nocat = args.nocat and string.lower(args.nocat) == 'yes' |
|||
if args.shadow and string.lower(args.shadow) == 'yes' then |
if args.shadow and string.lower(args.shadow) == 'yes' then |
||
ret:css({ ['box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)' |
ret:css({ ['box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)' }) |
||
['-mox-box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)', |
|||
['-webkit-box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)' }) |
|||
end |
end |
||
Line 40: | Line 49: | ||
-- Special message for when first argument is blank; otherwise treat it as normal |
-- Special message for when first argument is blank; otherwise treat it as normal |
||
if args[1] and args[1]:find('%S') then |
if args[1] and args[1]:find('%S') then |
||
userboxes = |
userboxes = showUserbox(frame, args[1], nocat) |
||
else |
else |
||
userboxes = args.noboxestext or "''You haven't set up any languages. Please see [[Template:Babel/doc]] for help.''" |
userboxes = args.noboxestext or "''You haven't set up any languages. Please see [[Template:Babel/doc]] for help.''" |
||
Line 56: | Line 65: | ||
-- ! indicates a new cell should be created |
-- ! indicates a new cell should be created |
||
if v:find('%S') and v ~= '!' then |
if v:find('%S') and v ~= '!' then |
||
body_cells:wikitext( |
body_cells:wikitext( showUserbox(frame, v, nocat) ) |
||
-- Recycling body_cells for <td> |
-- Recycling body_cells for <td> |
||
elseif v and v == '!' then |
elseif v and v == '!' then |
||
Line 69: | Line 78: | ||
['text-align'] = 'center' }) |
['text-align'] = 'center' }) |
||
:attr('colspan',col_span) |
:attr('colspan',col_span) |
||
:wikitext( args.header or '[[Wikipedia:Babel]]' ) |
:wikitext( args.header or '[[Wikipedia:Babel|Conworlds:Babel]]' ) |
||
:done() |
:done() |
||
Line 76: | Line 85: | ||
['text-align'] = 'center' }) |
['text-align'] = 'center' }) |
||
:attr('colspan',col_span) |
:attr('colspan',col_span) |
||
:wikitext( args.footer or '[[:Category: |
:wikitext( args.footer or '[[:Category:Conworlders by language|Search user languages]]' ) |
||
:done() |
:done() |
||
Revision as of 22:39, 25 March 2022
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. |
Usage
Implements Template:Babel, allowing users to group together any number of userboxes in a single, customizable table
{{#invoke:Babel|main}}
local p = {}
local getArgs
local function showUserbox(frame, v, nocat)
local maybeNocat = ''
if nocat then
maybeNocat = '|nocat=yes'
end
return frame:preprocess('{{User '..v..maybeNocat..'}}')
end
function p.main(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {wrappers = 'Template:Babel'})
local ret = mw.html.create('table')
:attr('role', 'presentation')
:addClass('userboxes')
:css( {
float = args.align or 'right',
['margin-left'] = (args.left or '1') .. 'em',
['margin-bottom'] = (args.bottom or '0') .. 'em',
width = (args.width or '248') .. 'px',
clear = args.align or 'right',
color = args.textcolor or '#000000',
border = (args.bordercolor or '#99B3FF') .. ' solid ' .. (args.solid or 1)..'px'
} )
local nocat = args.nocat and string.lower(args.nocat) == 'yes'
if args.shadow and string.lower(args.shadow) == 'yes' then
ret:css({ ['box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)' })
end
ret:cssText( args['extra-css'] or '' )
local color = args.color or 'inherit'
local row1 = ret:tag('tr')
local row2 = ret:tag('tr')
local row3 = ret:tag('tr')
local body_cells = row2:tag('td')
:css('vertical-align', 'middle !important')
local userboxes
-- Special message for when first argument is blank; otherwise treat it as normal
if args[1] and args[1]:find('%S') then
userboxes = showUserbox(frame, args[1], nocat)
else
userboxes = args.noboxestext or "''You haven't set up any languages. Please see [[Template:Babel/doc]] for help.''"
end
body_cells:wikitext(userboxes)
-- "remove" args[1] so it isn't looked at in the loop
-- table.remove(args,1) doesn't produce desired result
args[1] = ''
-- Keep track of how many columns are in this table
local col_span = 1
for _, v in ipairs( args ) do
-- ! indicates a new cell should be created
if v:find('%S') and v ~= '!' then
body_cells:wikitext( showUserbox(frame, v, nocat) )
-- Recycling body_cells for <td>
elseif v and v == '!' then
col_span = col_span + 1
body_cells:done()
body_cells = row2:tag('td')
end
end
row1:tag('th')
:css({ ['background-color'] = color,
['text-align'] = 'center' })
:attr('colspan',col_span)
:wikitext( args.header or '[[Wikipedia:Babel|Conworlds:Babel]]' )
:done()
row3:tag('td')
:css({ ['background-color'] = color,
['text-align'] = 'center' })
:attr('colspan',col_span)
:wikitext( args.footer or '[[:Category:Conworlders by language|Search user languages]]' )
:done()
if args['special-boxes'] then
body_cells:wikitext(args['special-boxes'])
end
body_cells:done()
return tostring(ret)
end
return p