Module:Navbox/sandbox: Difference between revisions

Content deleted Content added
Remove wrappers
Tag: Reverted
let's see what breaks
Tag: Reverted
Line 7:
local navbar = require('Module:Navbar')._navbar
local getArgs -- lazily initialized
local cfg = mw.loadData('Module:Navbox/configuration')
 
local args
Line 20 ⟶ 21:
-- by parent navboxes. The result is that the category shows all pages
-- where a child navbox is not contained in a parent navbox.
if border == 'subgroup'cfg.keyword.border_subgroup and args[cfg.arg.orphan] ~= 'yes'cfg.keyword.orphan_yes then
local orphanCat = '[[Category:Navbox orphans]]'
if border == 'subgroup' and args.orphan ~= 'yes' then
-- No change; striping occurs in outermost navbox.
return wikitext .. orphanCatcfg.category.orphan
end
local first, second = 'odd'cfg.class.navbox_odd_part, 'even'cfg.class.navbox_even_part
if args[cfg.arg.evenodd] then
if args[cfg.arg.evenodd] == 'swap'cfg.keyword.evenodd_swap then
first, second = second, first
else
first = args[cfg.arg.evenodd]
second = first
end
Line 39:
else
local index = 0
changer = function (code) -- where is code set???
if code == '0' then
-- Current occurrence is for a group before a nested table.
Line 52:
end
end
local regex = orphanCatcfg.category.orphan:gsub('([%[%]])', '%%%1')
return (wikitext:gsub(regex, ''):gsub(REGEX_MARKER, changer)) -- () omits gsub count
end
Line 62:
return '\n' .. item ..'\n'
end
if nowrapitems == 'yes'cfg.keyword.nowrapitems_yes then
local lines = {}
for line in (item .. '\n'):gmatch('([^\n]*)\n') do
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
if prefix and not content:match('^<span class="cfg.pattern.nowrap">') then
line = prefix mw.ustring.format(cfg.nowrap_item, '<span class="nowrap">' ..prefix, content .. '</span>')
end
table.insert(lines, line)
Line 81:
local function renderNavBar(titleCell)
 
if args[cfg.arg.navbar] ~= cfg.keyword.navbar_off and
if args.navbar ~= 'off' and args.navbar ~= 'plain' and not (not args.name and mw.getCurrentFrame():getParent():getTitle():gsub('/sandbox$', '') == 'Template:Navbox') then
args[cfg.arg.navbar] ~= cfg.keyword.navbar_plain and
if (args[cfg.navbar ~= 'off' and argsarg.navbar ~= 'plain'name] and not (not args.name and mw.getCurrentFrame():getParent():getTitle():gsub('/cfg.pattern.sandbox$', '') == 'Template:Navbox'cfg.pattern.navbox) then
titleCell:wikitext(navbar{
args[cfg.arg.name],
[cfg.navbar.mini] = 1,
[cfg.navbar.fontstyle] = (args[cfg.arg.basestyle] or '') .. ';' ..
(args[cfg.arg.titlestyle] or '') ..
';background:none transparent;border:none;box-shadow:none;padding:0;'
})
end
Line 95 ⟶ 99:
--
local function renderTitleRow(tbl)
if not args[cfg.arg.title] then return end
 
local titleRow = tbl:tag('tr')
 
if args[cfg.arg.titlegroup] then
titleRow
:tag('th')
:attr('scope', 'row')
:addClass('navbox-group'cfg.class.navbox_group)
:addClass(args[cfg.arg.titlegroupclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.groupstyle])
:cssText(args[cfg.arg.titlegroupstyle])
:wikitext(args[cfg.arg.titlegroup])
end
 
local titleCell = titleRow:tag('th'):attr('scope', 'col')
 
if args[cfg.arg.titlegroup] then
titleCell
:css('border-left', '2px solid #fdfdfd')
Line 120 ⟶ 124:
 
local titleColspan = 2
if args[cfg.arg.imageleft] then titleColspan = titleColspan + 1 end
if args[cfg.arg.image] then titleColspan = titleColspan + 1 end
if args[cfg.arg.titlegroup] then titleColspan = titleColspan - 1 end
 
titleCell
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.titlestyle])
:addClass('navbox-title'cfg.class.navbox_title)
:attr('colspan', titleColspan)
 
Line 135 ⟶ 139:
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args[cfg.arg.title]))
:addClass(args[cfg.arg.titleclass])
:css('font-size', '114%')
:css('margin', '0 4em')
:wikitext(processItem(args[cfg.arg.title]))
end
 
Line 148 ⟶ 152:
local function getAboveBelowColspan()
local ret = 2
if args[cfg.arg.imageleft] then ret = ret + 1 end
if args[cfg.arg.image] then ret = ret + 1 end
return ret
end
 
local function renderAboveRow(tbl)
if not args[cfg.arg.above] then return end
 
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow'cfg.class.navbox_abovebelow)
:addClass(args[cfg.arg.aboveclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.abovestyle])
:attr('colspan', getAboveBelowColspan())
:tag('div')
-- id for aria-labelledby attribute, if no title
:attr('id', args[cfg.arg.title] and nil or mw.uri.anchorEncode(args[cfg.arg.above]))
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems]))
end
 
local function renderBelowRow(tbl)
if not args[cfg.arg.below] then return end
 
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow'cfg.class.navbox_abovebelow)
:addClass(args[cfg.arg.belowclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.belowstyle])
:attr('colspan', getAboveBelowColspan())
:tag('div')
:wikitext(processItem(args[cfg.arg.below], args[cfg.arg.nowrapitems]))
end
 
Line 189 ⟶ 193:
local row = tbl:tag('tr')
 
if index == 1 and args[cfg.arg.imageleft] then
row
:tag('td')
:addClass('cfg.class.noviewer')
:addClass('navbox-cfg.class.image')
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '0px0 2px 0px0 0px0')
:cssText(args[cfg.arg.imageleftstyle])
:attr('rowspan', #listnums)
:tag('div')
:wikitext(processItem(args[cfg.arg.imageleft]))
end
 
if args['group'cfg.arg.group_part .. listnum] then
local groupCell = row:tag('th')
 
-- id for aria-labelledby attribute, if lone group with no title or above
if listnum == 1 and not (args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group2]) then
groupCell
:attr('id', mw.uri.anchorEncode(args[cfg.arg.group1]))
end
 
groupCell
:attr('scope', 'row')
:addClass('navbox-group'cfg.class.navbox_group)
:addClass(args[cfg.arg.groupclass])
:cssText(args[cfg.arg.basestyle])
:css('width', args[cfg.arg.groupwidth] or '1%') -- If groupwidth not specified, minimize width
 
groupCell
:cssText(args[cfg.arg.groupstyle])
:cssText(args['group'cfg.arg.group_part .. listnum .. 'style'cfg.arg.style_part])
:wikitext(args['group'cfg.arg.group_part .. listnum])
end
 
local listCell = row:tag('td')
 
if args['group'cfg.arg.group_part .. listnum] then
listCell
:css('text-align', 'left')
Line 236 ⟶ 240:
end
 
if not args[cfg.arg.groupwidth] then
listCell:css('width', '100%')
end
Line 242 ⟶ 246:
local rowstyle -- usually nil so cssText(rowstyle) usually adds nothing
if index % 2 == 1 then
rowstyle = args[cfg.arg.oddstyle]
else
rowstyle = args[cfg.arg.evenstyle]
end
 
local listText = args['list'cfg.arg.list_part .. listnum]
local oddEven = ODD_EVEN_MARKER
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automatic striping for this row.
oddEven = listText:find('<th[^>]*"navbox%-title"'cfg.pattern.navbox_title) and RESTART_MARKER or 'odd'cfg.class.navbox_odd_part
end
listCell
:css('padding', '0px0')
:cssText(args[cfg.arg.liststyle])
:cssText(rowstyle)
:cssText(args['list'cfg.arg.list_part .. listnum .. 'style'cfg.arg.style_part])
:addClass('navbox-list'cfg.class.navbox_list)
:addClass('navbox-'cfg.class.navbox_part .. oddEven)
:addClass(args[cfg.arg.listclass])
:addClass(args['list'cfg.arg.list_part .. listnum .. 'class'cfg.arg.class_part])
:tag('div')
:css('padding', (index == 1 and args[cfg.arg.list1padding]) or args[cfg.arg.listpadding] or '0em0 0.25em')
:wikitext(processItem(listText, args[cfg.arg.nowrapitems]))
 
if index == 1 and args[cfg.arg.image] then
row
:tag('td')
:addClass('cfg.class.noviewer')
:addClass('navbox-image'cfg.class.navbox_image)
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '0px0 0px0 0px0 2px')
:cssText(args[cfg.arg.imagestyle])
:attr('rowspan', #listnums)
:tag('div')
:wikitext(processItem(args[cfg.arg.image]))
end
end
Line 287 ⟶ 291:
 
local function needsHorizontalLists()
if border == 'subgroup'cfg.keyword.border_subgroup or args[cfg.arg.tracking] == 'no'cfg.keyword.tracking_no then
return false
end
-- FIXME: These should be finding the classes in list_classes, not looking for equality.
local listClasses = {
return not (listClasseslist_classes[args[cfg.arg.listclass]] or listClasseslist_classes[args[cfg.arg.bodyclass]])
['plainlist'] = true, ['hlist'] = true, ['hlist hnum'] = true,
['hlist hwrap'] = true, ['hlist vcard'] = true, ['vcard hlist'] = true,
['hlist vevent'] = true,
}
return not (listClasses[args.listclass] or listClasses[args.bodyclass])
end
 
local function hasBackgroundColors()
for _, key in ipairs({'cfg.arg.titlestyle', 'cfg.arg.groupstyle', '
cfg.arg.basestyle', 'cfg.arg.abovestyle', 'cfg.arg.belowstyle'}) do
if tostring(args[key]):find('background', 1, true) then
return true
Line 307 ⟶ 308:
 
local function hasBorders()
for _, key in ipairs({'cfg.arg.groupstyle', 'cfg.arg.basestyle', '
cfg.arg.abovestyle', 'cfg.arg.belowstyle'}) do
if tostring(args[key]):find('border', 1, true) then
return true
Line 318 ⟶ 320:
 
for key, style in pairs(args) do
if tostring(key):match("cfg.pattern.style$") then
if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then
return true
Line 329 ⟶ 331:
local function getTrackingCategories()
local cats = {}
if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists'cfg.category.horizontal_lists) end
if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours'cfg.category.background_colors) end
if isIllegible() then table.insert(cats, 'Potentially cfg.category.illegible navboxes') end
if hasBorders() then table.insert(cats, 'Navboxes using cfg.category.borders') end
return cats
end
Line 340 ⟶ 342:
if title.namespace ~= 10 then return end -- not in template space
local subpage = title.subpageText
if subpage == 'doc'cfg.keyword.subpage_doc or subpage == 'sandbox' or subpage == 'testcases' then return endcfg.keyword.subpage_sandbox
or subpage == cfg.keyword.subpage_testcases then return end
 
for _, cat in ipairs(getTrackingCategories()) do
Line 352 ⟶ 355:
local function renderMainTable()
local tbl = mw.html.create('table')
:addClass('cfg.class.nowraplinks')
:addClass(args[cfg.arg.bodyclass])
 
if args[cfg.arg.title] and (args[cfg.arg.state] ~= 'plain'cfg.keyword.state_plain and args.state ~= 'off') then
if args[cfg.arg.state] =~= 'collapsed'cfg.keyword.state_off) then args.state = 'mw-collapsed' end
if args[cfg.arg.state] == cfg.keyword.state_collapsed then args[cfg.arg.state] = cfg.class.collapsed end
tbl
:addClass('mw-cfg.class.collapsible')
:addClass(args[cfg.arg.state] or 'cfg.class.autocollapse')
end
 
tbl:css('border-spacing', 0)
if border == 'subgroup'cfg.keyword.border_subgroup or border == 'none'cfg.keyword.border_none then
tbl
:addClass('navbox-subgroup'cfg.class.navbox_subgroup)
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
else -- regular navbox - bodystyle and style will be applied to the wrapper table
tbl
:addClass('navbox-inner'cfg.class.navbox_inner)
:css('background', 'transparent')
:css('color', 'inherit')
end
tbl:cssText(args[cfg.arg.innerstyle])
 
renderTitleRow(tbl)
Line 392 ⟶ 396:
for k, _ in pairs(args) do
if type(k) == 'string' then
local listnum = k:match('^cfg.pattern.list(%d+)$')
if listnum then table.insert(listnums, tonumber(listnum)) end
end
Line 398 ⟶ 402:
table.sort(listnums)
 
border = mw.text.trim(args[cfg.arg.border] or args[1] or '')
if border == 'child'cfg.keyword.border_child then
border = 'subgroup'cfg.keyword.border_subgroup
end
 
Line 408 ⟶ 412:
-- render the appropriate wrapper around the navbox, depending on the border param
local res = mw.html.create()
if border == 'none'cfg.keyword.border_none then
local nav = res:tag('div')
:attr('role', 'navigation')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args[cfg.arg.title] or args[cfg.arg.above] or (args[cfg.arg.group1] and not args[cfg.arg.group2]) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group1]))
else
nav:attr('aria-label', 'Navbox'cfg.aria_label)
end
elseif border == 'subgroup'cfg.keyword.border_subgroup then
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
Line 429 ⟶ 433:
local nav = res:tag('div')
:attr('role', 'navigation')
:addClass('cfg.class.navbox')
:addClass(args[cfg.arg.navboxclass])
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
:css('padding', '3px')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args[cfg.arg.title] or args[cfg.arg.above] or (args[cfg.arg.group1] and not args[cfg.arg.group2]) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group1]))
else
nav:attr('aria-label', 'Navbox'cfg.aria_label)
end
end
 
if (args[cfg.arg.nocat] or 'false'cfg.keyword.nocat_false):lower() == 'false'cfg.keyword.nocat_false then
renderTrackingCategories(res)
end
Line 457 ⟶ 461:
-- Read the arguments in the order they'll be output in, to make references number in the right order.
local _
_ = args[cfg.arg.title]
_ = args[cfg.arg.above]
for i = 1, 20 do
_ = args["group"cfg.arg.group_part .. tostring(i)]
_ = args["list"cfg.arg.list_part .. tostring(i)]
end
_ = args[cfg.arg.below]
 
return p._navbox(args)