Module:Babel/sandbox: Difference between revisions
Appearance
Content deleted Content added
Tlustulimu (talk | contribs) m correction |
Tlustulimu (talk | contribs) m correction of the link texts |
||
Line 44: | Line 44: | ||
local v = mw.ustring.sub(args[1],4) |
local v = mw.ustring.sub(args[1],4) |
||
-- removes the internal links |
-- removes the internal links |
||
v = mw.ustring.gsub(v,"%[%[Project:Babel%| |
v = mw.ustring.gsub(v,"%[%[Project:Babel%|Babel user information%]%]","",1) |
||
v = mw.ustring.gsub(v,"%[%[: |
v = mw.ustring.gsub(v,"%[%[:Category:Wikipedians by language%|Users by language%]%]","",1) |
||
v = '<div style="width:246px; float:left;">' .. v .. "</div>" |
v = '<div style="width:246px; float:left;">' .. v .. "</div>" |
||
body_cells:wikitext(v) |
body_cells:wikitext(v) |
||
Line 70: | Line 70: | ||
v = mw.ustring.sub(v,4) |
v = mw.ustring.sub(v,4) |
||
-- removes the internal links |
-- removes the internal links |
||
v = mw.ustring.gsub(v,"%[%[Project:Babel%| |
v = mw.ustring.gsub(v,"%[%[Project:Babel%|Babel user information%]%]","",1) |
||
v = mw.ustring.gsub(v,"%[%[: |
v = mw.ustring.gsub(v,"%[%[:Category:Wikipedians by language%|Users by language%]%]","",1) |
||
v = '<div style="width:246px; float:left;">' .. v .. "</div>" |
v = '<div style="width:246px; float:left;">' .. v .. "</div>" |
||
body_cells:wikitext(v) |
body_cells:wikitext(v) |
Revision as of 12:55, 21 October 2015
![]() | This is the module sandbox page for Module:Babel (diff). |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | 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 Lua module is used on approximately 44,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
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
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')
: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 = (bordercolor or '#99B3FF') .. ' solid ' .. (args.solid or 1)..'px'
} )
if args.shadow and string.lower(args.shadow) == 'yes' then
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
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
-- some code for adding {{#Babel or a table with {| into the first parameter
if mw.ustring.sub(args[1],1,3) == "#b#" or mw.ustring.sub(args[1],1,3) == "#B#" then
local v = mw.ustring.sub(args[1],4)
-- removes the internal links
v = mw.ustring.gsub(v,"%[%[Project:Babel%|Babel user information%]%]","",1)
v = mw.ustring.gsub(v,"%[%[:Category:Wikipedians by language%|Users by language%]%]","",1)
v = '<div style="width:246px; float:left;">' .. v .. "</div>"
body_cells:wikitext(v)
else
userboxes = frame:preprocess('{{User '..args[1]..'}}')
end
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
-- some code for adding {{#Babel or a table with {| into the first parameter
if mw.ustring.sub(v,1,3) == "#b#" or mw.ustring.sub(v,1,3) == "#B#" then
v = mw.ustring.sub(v,4)
-- removes the internal links
v = mw.ustring.gsub(v,"%[%[Project:Babel%|Babel user information%]%]","",1)
v = mw.ustring.gsub(v,"%[%[:Category:Wikipedians by language%|Users by language%]%]","",1)
v = '<div style="width:246px; float:left;">' .. v .. "</div>"
body_cells:wikitext(v)
else
body_cells:wikitext( frame:preprocess('{{User '..v..'}}') )
end
-- 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]]' )
: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:done()
return tostring(ret)
end
return p