Module:Babel: Difference between revisions

Content deleted Content added
No edit summary
Remove per this discussion, also there is no "mox" it should have been "moz" so this wasn't doing anything for Mozilla browsers :)
 
(19 intermediate revisions by 8 users not shown)
Line 2:
 
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)
Line 8 ⟶ 16:
end
local args = getArgs(frame, {wrappers = 'Template:Babel'})
 
local table_tagret = mw.html.create('table')
:attr('role', 'presentation')
:addClass('userboxes')
:css( {
local table_styling = {
{' 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'
}
} )
 
for _,v in ipairs(table_styling) do
local nocat = args.nocat and string.lower(args.nocat) == 'yes'
table_tag:css(v[1],v[2]..v[3])
 
end
local bordercolor = args.bordercolor or '#99B3FF'
local solid = args.solid or '1'
table_tag:css('border',bordercolor..' solid '..solid..'px')
if args.shadow and string.lower(args.shadow) == 'yes' then
table_tagret:css({ ['box-shadow',] = '0 2px 4px rgb(0,0,0,0.2)' })
:css('-mox-box-shadow','0 2px 4px rgb(0,0,0,0.2)')
:css('-webkit-box-shadow','0 2px 4px rgb(0,0,0,0.2)')
end
 
local extracss =ret:cssText( args.extracss['extra-css'] or '' )
 
table_tag:cssText(extracss)
local color = args.color or 'inherit'
local row1 = mw.html.createret:tag('tr')
local row2 = mw.html.createret:tag('tr')
local row3 = mw.html.createret:tag('tr')
 
local header = args.header or '[[Wikipedia:Babel]]'
local body_cells = row2:tag('td')
local footer = args.footer or '[[:Category:Wikipedians by language|Search user languages]]'
local footer_td = mw.html.create('td')
:css('background-color',color)
:css('text-align','center')
:attr('colspan','10')
:wikitext(footer)
local header_th = mw.html.create('th')
:css('background-color',color)
:css('text-align','center')
:attr('colspan','10')
:wikitext(header)
row1:node(header_th)
row3:node(footer_td)
local body_cells = mw.html.create('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:expandTemplate{title='User, '..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)
local unclosed_td = false
 
for i=2,100,1 do
-- "remove" args[1] so it isn't looked at in the loop
local boxtext
-- table.remove(args,1) doesn't produce desired result
local v = args[i]
args[1] = ''
if v and v:find('%S') and v ~= '!' then
 
boxtext = frame:expandTemplate{title='User '..v}
-- Keep track of how many columns are in this table
userboxes = userboxes..boxtext
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
userboxes = userboxes..'</td>\n<td>'
body_cells:done()
unclosed_td = true
body_cells = row2:tag('td')
end
end
 
row1:tag('th')
if unclosed_td then
:css({ ['background-color'] = color,
userboxes = userboxes..'</td>'
['text-align'] = 'center' })
:attr('colspan',col_span)
:wikitext( args.header or '[[Wikipedia:Babel]]' )
:done()
 
row3:tag('td')
:css({ ['background-color'] = color,
['text-align'] = 'center' })
:attr('colspan',col_span)
:wikitext( args.footer or '[[:Category:Wikipedians by language|Search user languages]]' )
:done()
 
if args['special-boxes'] then
body_cells:wikitext(args['special-boxes'])
end
 
body_cells:wikitext(userboxes)
body_cells:done()
 
row2:node(body_cells)
return tostring(ret)
table_tag:node(row1)
:node(row2)
:node(row3)
return tostring(table_tag)
end