Module:Babel: Difference between revisions

From Test Wiki
Content deleted Content added
Remove per this discussion, also there is no "mox" it should have been "moz" so this wasn't doing anything for Mozilla browsers :)
Importing from https://meta.wikimedia.org/wiki/Module:Babel.
 
(2 intermediate revisions by 2 users not shown)
Line 8: Line 8:
maybeNocat = '|nocat=yes'
maybeNocat = '|nocat=yes'
end
end
return frame:preprocess('{{User '..v..maybeNocat..'}}')
return frame:preprocess('{{User ' .. v .. maybeNocat .. '}}')
end
end


Line 15: Line 15:
getArgs = require('Module:Arguments').getArgs
getArgs = require('Module:Arguments').getArgs
end
end
local args = getArgs(frame, {wrappers = 'Template:Babel'})
local args = getArgs(frame, {
wrappers = 'Template:Babel'

})
local ret = mw.html.create('table')
local ret = mw.html.create('table')
:attr('role', 'presentation')
:attr('role', 'presentation')
:addClass('userboxes')
:addClass('userboxes')
:css( {
:css({
float = args.align or 'right',
float = args.align or 'right',
['margin-left'] = (args.left or '1') .. 'em',
['margin-left'] = (args.left or '1') .. 'em',
['margin-bottom'] = (args.bottom or '0') .. 'em',
['margin-bottom'] = (args.bottom or '0') .. 'em',
width = (args.width or '248') .. 'px',
width = (args.width or '248') .. 'px',
clear = args.align or 'right',
clear = args.align or 'right',
color = args.textcolor or '#000000',
color = args.textcolor or '#000000',
border = (args.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'
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({
ret:css({ ['box-shadow'] = '0 2px 4px rgb(0,0,0,0.2)' })
['box-shadow'] = '0 2px 4px rgb(0, 0, 0, 0.2)'
})
end
end

ret:cssText( args['extra-css'] or '' )
ret:cssText(args['extra-css'] or '')

local color = args.color or 'inherit'
local color = args.color or 'inherit'
local row1 = ret:tag('tr')
local row1 = ret:tag('tr')
Line 44: Line 48:


local body_cells = row2:tag('td')
local body_cells = row2:tag('td')
:css('vertical-align', 'middle !important')
:css('vertical-align', 'middle !important')

local userboxes
local userboxes
-- 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
Line 51: Line 55:
userboxes = showUserbox(frame, args[1], nocat)
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 [[:en:Template:Babel/doc|the template's documentation]] for help.''"
end
end

body_cells:wikitext(userboxes)
body_cells:wikitext(userboxes)

-- "remove" args[1] so it isn't looked at in the loop
-- "remove" args[1] so it isn't looked at in the loop
-- table.remove(args,1) doesn't produce desired result
-- table.remove(args,1) doesn't produce desired result
args[1] = ''
args[1] = ''

-- Keep track of how many columns are in this table
-- Keep track of how many columns are in this table
local col_span = 1
local col_span = 1
for _, v in ipairs( args ) do
for _, v in ipairs(args) do
-- ! 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( showUserbox(frame, v, nocat) )
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 73: Line 78:
end
end
end
end

row1:tag('th')
row1:tag('th')
:attr('colspan', col_span)
:css({ ['background-color'] = color,
:css({
['text-align'] = 'center' })
['background-color'] = color,
:attr('colspan',col_span)
['text-align'] = 'center'
:wikitext( args.header or '[[Wikipedia:Babel]]' )
:done()
})
:wikitext(args.header or '[[:m:User language|User language]]')

:done()
row3:tag('td')
row3:tag('td')
:attr('colspan', col_span)
:css({ ['background-color'] = color,
:css({
['text-align'] = 'center' })
['background-color'] = color,
:attr('colspan',col_span)
['text-align'] = 'center'
:wikitext( args.footer or '[[:Category:Wikipedians by language|Search user languages]]' )
:done()
})
:wikitext(args.footer or '[[:Category:Users by language|Search user languages]]')

:done()
if args['special-boxes'] then
if args['special-boxes'] then
body_cells:wikitext(args['special-boxes'])
body_cells:wikitext(args['special-boxes'])
end
end

body_cells:done()
body_cells:done()

return tostring(ret)
return tostring(ret)
end
end