Module:Babel: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
hm
 
No edit summary
 
(37 intermediate revisions by 10 users not shown)
Line 3: Line 3:
local getArgs
local getArgs


function main(frame)
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
if not getArgs then
getArgs = require('Module:Arguments').getArgs
getArgs = require('Module:Arguments').getArgs
end
end
local args = getArgs(frame, {removeBlanks = true, wrappers = 'Template:Babel'})
local args = getArgs(frame, {wrappers = 'Template:Babel'})

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

table_tag:css(v[1],v[2]..v[3])
local nocat = args.nocat and string.lower(args.nocat) == 'yes'
end

local bordercolor = args.bordercolor or '#99B3FF'
local solid = args.solid or '1'
table_styling:css('border',bordercolor..' solid '..solid..'px')
if args.shadow and string.lower(args.shadow) == 'yes' then
if args.shadow and string.lower(args.shadow) == 'yes' then
table_styling: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)' })
: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
end

local extracss = args.extracss or ''
ret:cssText( args['extra-css'] or '' )

table_styling:cssText(extracss)
local color = args.color or 'inherit'
local color = args.color or 'inherit'
local table_body = mw.html.create('tbody')
local row1 = ret:tag('tr')
local row1 = mw.html.create('tr')
local row2 = ret:tag('tr')
local row2 = mw.html.create('tr')
local row3 = ret:tag('tr')

local row3 = mw.html.create('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 th1 = mw.html.create('th')
:css('background-color',color)
:css('text-align','center')
:attr('colspan','10')
:wikitext(header)
local footer = mw.html.create('tr')
:css('background-color',color)
:css('text-align','center')
:attr('colspan','10')
:wikitext(footer)
row1:node(header)
row2:node(footer)
local body_cells = mw.html.create('td')
:css('vertical-align', 'middle !important')
:css('vertical-align', 'middle !important')


local userboxes
local arg1 = args[1] or "''You haven't set up any languages. Please see [[Template:Babel/doc]] for help.''"
-- 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] = ''
args[1] = ''

-- Keep track of how many columns are in this table
local userboxes = arg1
local unclosed_td = false
local col_span = 1
for _,v in ipairs(args) do
for _, v in ipairs( args ) do
-- ! indicates a new cell should be created
local boxtext
if v:find('%S') and not v == '!' then
if v:find('%S') and v ~= '!' then
body_cells:wikitext( showUserbox(frame, v, nocat) )
boxtext = frame:expandTemplate{title='User '..v}
-- Recycling body_cells for <td>
userboxes = userboxes..boxtext
elseif v == '!' then
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
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 '[[WP:Wikipedia:Babel|Babel]]' )
:done()

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

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

body_cells:wikitext(userboxes)
body_cells:done()

row2:node(body_cells)
return tostring(ret)
table_body:node(row1)
:node(row2)
:node(row3)
table_tag:node(table_body)
return tostring(table_tag)
end
end



Latest revision as of 16:53, 12 March 2024

Documentation for this module may be created at Module:Babel/doc

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 '[[WP:Wikipedia:Babel|Babel]]' )
			:done()

	row3:tag('td')
			:css({ ['background-color'] = color,
					['text-align'] = 'center' })
			:attr('colspan',col_span)
			:wikitext( args.footer or '[[:Category:Test Wiki users 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