Модуль:Navbox: различия между версиями

Материал из ChronoWiki
Перейти к навигацииПерейти к поиску
м (1 версия импортирована)
(фикс порядка сносок)
Строка 1: Строка 1:
 
--
 
--
-- Реализует {{Навигационная таблица}} и {{Подгруппы навигационной таблицы}}.
+
-- Реализует {{навигационная таблица}}, {{подгруппы навигационной таблицы}} и {{навигационная таблица с блоками}}.
 
-- Основной объём кода заимствован из английского Module:Navbox.
 
-- Основной объём кода заимствован из английского Module:Navbox.
 
--
 
--
Строка 8: Строка 8:
 
local getArgs -- lazily initialized
 
local getArgs -- lazily initialized
 
local yesno -- lazily initialized
 
local yesno -- lazily initialized
 +
local styleratio
  
local args
 
local border
 
local listnums = {}
 
 
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
 
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
 
local RESTART_MARKER = '\127_ODDEVEN0_\127'
 
local RESTART_MARKER = '\127_ODDEVEN0_\127'
 
local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127'
 
local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127'
  
local maintitle
+
-- общие параметры для всех шаблонов
local name
+
local commonAliases = {
local navigation
+
name = {'name', 'имя'},
local navbar
+
navigation = {'navigation', 'навигация'},
local above
+
navbar = {'navbar', 'ссылка_на_просмотр'},
local image
+
state = {'state'},
local below
+
orphan = {'orphan'},
 +
tracking = {'tracking'},
 +
border = {'border', 1},
 +
title = {'title', 'заголовок'},
 +
titlegroup = {'titlegroup'},
 +
above = {'above', 'вверху'},
 +
image = {'image', 'изображение'},
 +
imageleft = {'imageleft', 'изображение2', 'изображение_слева'},
 +
below = {'below', 'внизу'},
 +
 +
bodyclass = {'bodyclass', 'класс_тела'},
 +
titleclass = {'titleclass', 'класс_заголовка'},
 +
titlegroupclass = {'titlegroupclass'},
 +
aboveclass = {'aboveclass', 'класс_вверху'},
 +
belowclass = {'belowclass', 'класс_внизу'},
 +
groupclass = {'groupclass', 'класс_групп'},
 +
listclass = {'listclass', 'класс_списков'},
 +
imageclass = {'imageclass', 'класс_изображения'},
 +
 +
basestyle = {'basestyle', 'стиль', 'стиль_базовый'},
 +
bodystyle = {'style', 'bodystyle', 'стиль_тела'},
 +
titlestyle = {'titlestyle', 'стиль_основного_заголовка', 'стиль_заголовка'},
 +
titlegroupstyle = {'titlegroupstyle'},
 +
innerstyle = {'innerstyle'},
 +
abovestyle = {'abovestyle', 'стиль_вверху'},
 +
belowstyle = {'belowstyle', 'стиль_внизу'},
 +
imagestyle = {'imagestyle', 'стиль_изображения'},
 +
imageleftstyle = {'imageleftstyle', 'imagestyle2', 'стиль_изображения_слева'},
 +
}
 +
 
 +
-- параметры {{навигационная таблица}} и {{подгруппы навигационной таблицы}}
 +
local standardAliases = {
 +
groupstyle = {'groupstyle', 'стиль_заголовков', 'стиль_групп'},
 +
liststyle = {'liststyle', 'стиль_списков'},
 +
evenodd = {'evenodd', 'чётные_нечётные', 'четные_нечетные'},
 +
groupwidth = {'groupwidth', 'ширина_групп'},
 +
listpadding = {'listpadding', 'отступ_списков'},
 +
}
  
local titlestyle
+
-- параметры {{навигационная таблица}} и {{подгруппы навигационной таблицы}} с нумерацией
local groupstyle
+
local standardElementAliases = {
local bodystyle
+
group = {'group%s', 'заголовок%s', 'группа%s'},
local basestyle
+
list = {'list%s', 'список%s'},
local liststyle
+
groupstyle = {'group%sstyle', 'стиль_заголовка%s', 'стиль_группы%s'},
local evenodd_VARIABLE
+
liststyle = {'list%sstyle', 'стиль_списка%s'},
local abovestyle
+
listpadding = {'list%spadding'}
local belowstyle
+
}
local imageleft
 
local imageleftstyle
 
local style
 
  
local groupwidth
+
-- параметры {{навигационная таблица с блоками}}
local listpadding
+
-- с нижнего подчеркивания начинаются параметры, конфликтующие с standardAliases
 +
local groupsParentAliases = {
 +
selected = {'selected', 'открытый_блок', 'развернуть'},
 +
secttitlestyle = {'secttitlestyle', 'стиль_заголовков'},
 +
_groupstyle = {'groupstyle', 'стиль_блоков'},
 +
_liststyle = {'liststyle', 'стиль_списков', 'contentstyle'},
 +
_listpadding = {'listpadding', 'отступ_списка', 'отступ_списков'}
 +
}
 +
 
 +
-- параметры {{навигационная таблица с блоками}} с нумерацией
 +
local groupsChildAliases = {
 +
groupname = {'abbr%s', 'имя_блока%s', 'аббр%s'},
 +
state = {'state%s'},
 +
title = {'group%s', 'блок%s', 'заголовок%s', 'группа%s', 'sect%s', 'section%s', 'секция%s'},
 +
list1 = {'list%s', 'список%s', 'content%s'},
 +
image = {'image%s', 'изображение%s'},
 +
imageleft = {'imageleft%s', 'изображение_слева%s'},
 +
 
 +
secttitlestyle = {'sect%stitlestyle', 'стиль%sзаголовка', 'стиль_секции%s'},
 +
groupstyle = {'group%sstyle', 'стиль%sблока', 'стиль_группы%s', 'стиль_блока%s'},
 +
liststyle = {'list%sstyle', 'стиль%sсписка', 'стиль_списка%s', 'content%sstyle'},
 +
color = {'цвет%s'}
 +
}
 +
 
 +
local function checkAliases(args, aliases, index)
 +
for _, alias in ipairs(aliases) do
 +
local arg
 +
if index then
 +
arg = args[string.format(alias, index)]
 +
else
 +
arg = args[alias]
 +
end
 +
 +
if arg then
 +
return arg
 +
end
 +
end
 +
 +
return nil
 +
end
  
local bodyclass
+
local function checkElAliases(args, name, index)
local titleclass
+
return checkAliases(args, standardElementAliases[name], index)
local aboveclass
+
end
local belowclass
 
local groupclass
 
local listclass
 
local imageclass
 
  
local function striped(wikitext)
+
local function concatStyles(t)
 +
local res
 +
for k, v in pairs(t) do
 +
if v then
 +
res = res and res .. ';' .. v or v
 +
end
 +
end
 +
return res
 +
end
 +
 
 +
local function striped(wikitext, args)
 
-- Return wikitext with markers replaced for odd/even striping.
 
-- Return wikitext with markers replaced for odd/even striping.
 
-- Child (subgroup) navboxes are flagged with a category that is removed
 
-- Child (subgroup) navboxes are flagged with a category that is removed
Строка 53: Строка 130:
 
-- where a child navbox is not contained in a parent navbox.
 
-- where a child navbox is not contained in a parent navbox.
 
local orphanCat = '[[Категория:Навигационные шаблоны без родителя]]'
 
local orphanCat = '[[Категория:Навигационные шаблоны без родителя]]'
if border == 'subgroup' and args.orphan ~= 'yes' then
+
if args.border == 'subgroup' and args.orphan ~= 'yes' then
 
-- No change; striping occurs in outermost navbox.
 
-- No change; striping occurs in outermost navbox.
 
return wikitext .. orphanCat
 
return wikitext .. orphanCat
 
end
 
end
 
local first, second = 'odd', 'even'
 
local first, second = 'odd', 'even'
if evenodd_VARIABLE then
+
if args.evenodd then
if evenodd_VARIABLE == 'swap' then
+
if args.evenodd == 'swap' then
 
first, second = second, first
 
first, second = second, first
 
else
 
else
first = evenodd_VARIABLE
+
first = args.evenodd
 
second = first
 
second = first
 
end
 
end
Строка 96: Строка 173:
 
end
 
end
  
local function renderNavBar(titleCell)
+
local function renderNavBar(titleCell, args)
  
if navbar ~= 'off' and navbar ~= 'plain' and not (not name and mw.getCurrentFrame():getParent():getTitle():gsub('/песочница$', '') == 'Шаблон:Навигационная таблица') then
+
if args.navbar ~= 'off' and args.navbar ~= 'plain'  
 +
and (args.name or not mw.getCurrentFrame():getParent():getTitle():gsub('/песочница$', '') == 'Шаблон:Навигационная таблица') then
 
 
 
-- Check color contrast of the gear icon
 
-- Check color contrast of the gear icon
local styleratio = require('Module:Color contrast')._styleratio
+
if not styleratio then
 +
styleratio = require('Module:Color contrast')._styleratio
 +
end
 
local gearColor = ''
 
local gearColor = ''
local contrastStyle = titlestyle or basestyle
+
local contrastStyle = args.titlestyle or args.basestyle
 
local gearStyleBlack = (contrastStyle and mw.text.unstripNoWiki(contrastStyle) .. '; color:#666;' or '')
 
local gearStyleBlack = (contrastStyle and mw.text.unstripNoWiki(contrastStyle) .. '; color:#666;' or '')
 
local gearStyleWhite = (contrastStyle and mw.text.unstripNoWiki(contrastStyle) .. '; color:#fff;' or '')
 
local gearStyleWhite = (contrastStyle and mw.text.unstripNoWiki(contrastStyle) .. '; color:#fff;' or '')
Строка 109: Строка 189:
 
gearColor = ' white'
 
gearColor = ' white'
 
end
 
end
 +
local gear = string.format(
 +
'[[Файл:Wikipedia interwiki section gear icon%s.svg|14px|Просмотр этого шаблона|link=Шаблон:%s|alt=⛭]]',
 +
gearColor, args.name
 +
)
 
 
 
--- Gear creation
 
--- Gear creation
Строка 118: Строка 202:
 
:css('width', '5em')
 
:css('width', '5em')
 
:css('margin-right', '0.5em')
 
:css('margin-right', '0.5em')
:wikitext('[[Файл:Wikipedia interwiki section gear icon' .. gearColor .. '.svg|14px|Просмотр этого шаблона|link=Шаблон:' .. name .. '|alt=⛭]]')
+
:wikitext(gear)
 
end
 
end
  
Строка 126: Строка 210:
 
--  Title row
 
--  Title row
 
--
 
--
local function renderTitleRow(tbl)
+
local function renderTitleRow(tbl, args)
if not maintitle then return end
+
if not args.title then return end
  
 
local titleRow = tbl:tag('tr')
 
local titleRow = tbl:tag('tr')
Строка 137: Строка 221:
 
:addClass('navbox-group')
 
:addClass('navbox-group')
 
:addClass(args.titlegroupclass)
 
:addClass(args.titlegroupclass)
:cssText(basestyle)
+
:cssText(args.basestyle)
:cssText(groupstyle)
+
:cssText(args.groupstyle)
 
:cssText(args.titlegroupstyle)
 
:cssText(args.titlegroupstyle)
 
:wikitext(args.titlegroup)
 
:wikitext(args.titlegroup)
Строка 152: Строка 236:
  
 
local titleColspan = 2
 
local titleColspan = 2
if imageleft then titleColspan = titleColspan + 1 end
+
if args.imageleft then titleColspan = titleColspan + 1 end
if image then titleColspan = titleColspan + 1 end
+
if args.image then titleColspan = titleColspan + 1 end
 
if args.titlegroup then titleColspan = titleColspan - 1 end
 
if args.titlegroup then titleColspan = titleColspan - 1 end
  
 
titleCell
 
titleCell
:cssText(basestyle)
+
:cssText(args.basestyle)
:cssText(titlestyle)
+
:cssText(args.titlestyle)
 
:addClass('navbox-title')
 
:addClass('navbox-title')
 
:attr('colspan', titleColspan)
 
:attr('colspan', titleColspan)
  
renderNavBar(titleCell)
+
renderNavBar(titleCell, args)
  
 
titleCell
 
titleCell
 
:tag('div')
 
:tag('div')
:attr('id', mw.uri.anchorEncode(maintitle))
+
:attr('id', mw.uri.anchorEncode(args.title))
:addClass(titleclass)
+
:addClass(args.titleclass)
 
:css('font-size', '114%')
 
:css('font-size', '114%')
 
:css('margin', '0 5em')
 
:css('margin', '0 5em')
:wikitext(addNewline(maintitle))
+
:wikitext(addNewline(args.title))
 
end
 
end
  
Строка 177: Строка 261:
 
--
 
--
  
local function getAboveBelowColspan()
+
local function getAboveBelowColspan(args)
 
local ret = 2
 
local ret = 2
if imageleft then ret = ret + 1 end
+
if args.imageleft then ret = ret + 1 end
if image then ret = ret + 1 end
+
if args.image then ret = ret + 1 end
 
return ret
 
return ret
 
end
 
end
  
local function renderAboveRow(tbl)
+
local function renderAboveRow(tbl, args)
if not above then return end
+
if not args.above then return end
  
 
tbl:tag('tr')
 
tbl:tag('tr')
 
:tag('td')
 
:tag('td')
 
:addClass('navbox-abovebelow')
 
:addClass('navbox-abovebelow')
:addClass(aboveclass)
+
:addClass(args.aboveclass)
:cssText(basestyle)
+
:cssText(args.basestyle)
:cssText(abovestyle)
+
:cssText(args.abovestyle)
:attr('colspan', getAboveBelowColspan())
+
:attr('colspan', getAboveBelowColspan(args))
 
:tag('div')
 
:tag('div')
:wikitext(addNewline(above))
+
:wikitext(addNewline(args.above))
 
end
 
end
  
local function renderBelowRow(tbl)
+
local function renderBelowRow(tbl, args)
if not below then return end
+
if not args.below then return end
  
 
tbl:tag('tr')
 
tbl:tag('tr')
 
:tag('td')
 
:tag('td')
 
:addClass('navbox-abovebelow')
 
:addClass('navbox-abovebelow')
:addClass(belowclass)
+
:addClass(args.belowclass)
:cssText(basestyle)
+
:cssText(args.basestyle)
:cssText(belowstyle)
+
:cssText(args.belowstyle)
:attr('colspan', getAboveBelowColspan())
+
:attr('colspan', getAboveBelowColspan(args))
 
:tag('div')
 
:tag('div')
:wikitext(addNewline(below))
+
:wikitext(addNewline(args.below))
 
end
 
end
  
Строка 216: Строка 300:
 
--
 
--
  
local function haveSubgroups()
+
local function haveSubgroups(args)
 
for i = 1, 23 do
 
for i = 1, 23 do
if (args['group' .. i] or args['заголовок' .. i] or args['группа' .. i]) and (args['list' .. i] or args['список' .. i]) then
+
if checkElAliases(args, 'group', i) and checkElAliases(args, 'list', i) then
 
return true
 
return true
 
end
 
end
Строка 225: Строка 309:
 
end
 
end
  
local function renderListRow(tbl, index, listnum)
+
local function renderListRow(tbl, args, index, rowspan, rowArgs)
 
local row = tbl:tag('tr')
 
local row = tbl:tag('tr')
  
if index == 1 and imageleft then
+
if index == 1 and args.imageleft then
 
row
 
row
 
:tag('td')
 
:tag('td')
 
:addClass('navbox-image')
 
:addClass('navbox-image')
:addClass(imageclass)
+
:addClass(args.imageclass)
 
:css('width', '1px')
 
:css('width', '1px')
 
:css('padding', '0px 7px 0px 0px')
 
:css('padding', '0px 7px 0px 0px')
:cssText(imageleftstyle)
+
:cssText(args.imageleftstyle)
:attr('rowspan', #listnums)
+
:attr('rowspan', rowspan)
 
:tag('div')
 
:tag('div')
:wikitext(addNewline(imageleft))
+
:wikitext(addNewline(args.imageleft))
 
end
 
end
  
if (args['group' .. listnum] or args['заголовок' .. listnum] or args['группа' .. listnum]) then
+
if rowArgs.group then
 
local groupCell = row:tag('th')
 
local groupCell = row:tag('th')
  
Строка 247: Строка 331:
 
:attr('scope', 'row')
 
:attr('scope', 'row')
 
:addClass('navbox-group')
 
:addClass('navbox-group')
:addClass(groupclass)
+
:addClass(args.groupclass)
:cssText(basestyle)
+
:cssText(args.basestyle)
:css('width', groupwidth or '1px') -- If groupwidth not specified, minimize width
+
:css('width', args.groupwidth or '1px') -- If groupwidth not specified, minimize width
  
 
groupCell
 
groupCell
:cssText(groupstyle)
+
:cssText(args.groupstyle)
:cssText(args['group' .. listnum .. 'style'] or args['стиль_группы' .. listnum] or args['стиль_заголовка' .. listnum])
+
:cssText(rowArgs.groupstyle)
:wikitext(args['group' .. listnum] or args['заголовок' .. listnum] or args['группа' .. listnum])
+
:wikitext(rowArgs.group)
 
end
 
end
  
 
local listCell = row:tag('td')
 
local listCell = row:tag('td')
  
if (args['group' .. listnum] or args['заголовок' .. listnum] or args['группа' .. listnum]) then
+
if rowArgs.group then
 
listCell
 
listCell
 
:css('text-align', 'left')
 
:css('text-align', 'left')
Строка 265: Строка 349:
 
:css('border-left-style', 'solid')
 
:css('border-left-style', 'solid')
 
else
 
else
if haveSubgroups() then
+
if haveSubgroups(args) then
 
listCell
 
listCell
 
:attr('colspan', 2)
 
:attr('colspan', 2)
Строка 271: Строка 355:
 
end
 
end
  
if not groupwidth then
+
if not args.groupwidth then
 
listCell:css('width', '100%')
 
listCell:css('width', '100%')
 
end
 
end
  
local listText = args['list' .. listnum] or args['список' .. listnum]
+
local listText = rowArgs.list
 
local oddEven = ODD_EVEN_MARKER
 
local oddEven = ODD_EVEN_MARKER
 
if listText:sub(1, 12) == '</div><table' then
 
if listText:sub(1, 12) == '</div><table' then
Строка 283: Строка 367:
 
listCell
 
listCell
 
:css('padding', '0px')
 
:css('padding', '0px')
:cssText(liststyle)
+
:cssText(args.liststyle)
:cssText(args['list' .. listnum .. 'style'] or args['стиль_списка' .. listnum])
+
:cssText(rowArgs.liststyle)
 
:addClass('navbox-list')
 
:addClass('navbox-list')
 
:addClass('navbox-' .. oddEven)
 
:addClass('navbox-' .. oddEven)
:addClass(listclass)
+
:addClass(args.listclass)
 
:tag('div')
 
:tag('div')
:css('padding', args['list' .. listnum .. 'padding'] or listpadding or '0em 0.25em')
+
:css('padding', rowArgs.listpadding or args.listpadding or '0em 0.25em')
 
:wikitext(addNewline(listText))
 
:wikitext(addNewline(listText))
  
if index == 1 and image then
+
if index == 1 and args.image then
 
row
 
row
 
:tag('td')
 
:tag('td')
 
:addClass('navbox-image')
 
:addClass('navbox-image')
:addClass(imageclass)
+
:addClass(args.imageclass)
 
:css('width', '1px')
 
:css('width', '1px')
 
:css('padding', '0px 0px 0px 7px')
 
:css('padding', '0px 0px 0px 7px')
:cssText(imagestyle)
+
:cssText(args.imagestyle)
:attr('rowspan', #listnums)
+
:attr('rowspan', rowspan)
 
:tag('div')
 
:tag('div')
:wikitext(addNewline(image))
+
:wikitext(addNewline(args.image))
 
end
 
end
 
end
 
end
Строка 309: Строка 393:
 
--  Tracking categories
 
--  Tracking categories
 
--
 
--
local function needsChangetoSubgroups()
+
local function needsChangetoSubgroups(args)
 
for i = 1, 23 do
 
for i = 1, 23 do
if (args['group' .. i] or args['заголовок' .. i] or args['группа' .. i]) and not (args['list' .. i] or args['список' .. i]) then
+
if (checkElAliases(args, 'group', i)) and not (checkElAliases(args, 'list', i)) then
 
return true
 
return true
 
end
 
end
Строка 318: Строка 402:
 
end
 
end
  
local function needsHorizontalLists()
+
local function needsHorizontalLists(args)
if border == 'subgroup' or args.tracking == 'no' then
+
if args.border == 'subgroup' or args.tracking == 'no' then
 
return false
 
return false
 
end
 
end
Строка 327: Строка 411:
 
['hlist vevent'] = true, ['hlist hlist-items-nowrap'] = true, ['hlist-items-nowrap'] = true,
 
['hlist vevent'] = true, ['hlist hlist-items-nowrap'] = true, ['hlist-items-nowrap'] = true,
 
}
 
}
return not (listClasses[listclass] or listClasses[bodyclass])
+
return not (listClasses[args.listclass] or listClasses[args.bodyclass])
 
end
 
end
  
Строка 334: Строка 418:
 
-- end
 
-- end
  
local function isIllegible()
+
local function isIllegible(args)
local styleratio = require('Module:Color contrast')._styleratio
+
if not styleratio then
 +
styleratio = require('Module:Color contrast')._styleratio
 +
end
  
 
for key, style in pairs(args) do
 
for key, style in pairs(args) do
Строка 347: Строка 433:
 
end
 
end
  
local function getTrackingCategories()
+
local function getTrackingCategories(args)
 
local cats = {}
 
local cats = {}
if needsChangetoSubgroups() then table.insert(cats, 'Навигационные шаблоны с ошибочным использованием заголовков') end
+
if needsChangetoSubgroups(args) then table.insert(cats, 'Навигационные шаблоны с ошибочным использованием заголовков') end
if needsHorizontalLists() then table.insert(cats, 'Навигационные шаблоны без горизонтальных списков') end
+
if needsHorizontalLists(args) then table.insert(cats, 'Навигационные шаблоны без горизонтальных списков') end
if isIllegible() then table.insert(cats, 'Потенциально нечитаемые навигационные шаблоны') end
+
if isIllegible(args) then table.insert(cats, 'Потенциально нечитаемые навигационные шаблоны') end
 
return cats
 
return cats
 
end
 
end
  
local function renderTrackingCategories(builder)
+
local function renderTrackingCategories(builder, args)
 
local title = mw.title.getCurrentTitle()
 
local title = mw.title.getCurrentTitle()
 
if title.namespace ~= 10 then return end -- not in template space
 
if title.namespace ~= 10 then return end -- not in template space
Строка 361: Строка 447:
 
if subpage == 'doc' or subpage == 'песочница' or subpage == 'тесты' then return end
 
if subpage == 'doc' or subpage == 'песочница' or subpage == 'тесты' then return end
  
for i, cat in ipairs(getTrackingCategories()) do
+
for i, cat in ipairs(getTrackingCategories(args)) do
 
builder:wikitext('[[Категория:' .. cat .. ']]')
 
builder:wikitext('[[Категория:' .. cat .. ']]')
 
end
 
end
Строка 369: Строка 455:
 
--  Main navbox tables
 
--  Main navbox tables
 
--
 
--
local function renderMainTable()
+
local function renderMainTable(args, listnums)
 
local tbl = mw.html.create('table')
 
local tbl = mw.html.create('table')
 
:addClass('nowraplinks')
 
:addClass('nowraplinks')
:addClass(bodyclass)
+
:addClass(args.bodyclass)
  
if maintitle and (args.state ~= 'plain' and args.state ~= 'off') then
+
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
 
tbl
 
tbl
 
:addClass('collapsible')
 
:addClass('collapsible')
Строка 381: Строка 467:
  
 
tbl:css('border-spacing', 0)
 
tbl:css('border-spacing', 0)
if border == 'subgroup' or border == 'none' then
+
if args.border == 'subgroup' or args.border == 'none' then
 
tbl
 
tbl
 
:addClass('navbox-subgroup')
 
:addClass('navbox-subgroup')
:cssText(bodystyle)
+
:cssText(args.bodystyle)
:cssText(style)
 
 
else -- regular navbox - bodystyle and style will be applied to the wrapper table
 
else -- regular navbox - bodystyle and style will be applied to the wrapper table
 
tbl
 
tbl
Строка 394: Строка 479:
 
tbl:cssText(args.innerstyle)
 
tbl:cssText(args.innerstyle)
  
renderTitleRow(tbl)
+
renderTitleRow(tbl, args)
renderAboveRow(tbl)
+
renderAboveRow(tbl, args)
 
for i, listnum in ipairs(listnums) do
 
for i, listnum in ipairs(listnums) do
renderListRow(tbl, i, listnum)
+
local rowArgs = {
 +
group = checkElAliases(args, 'group', listnum),
 +
list = checkElAliases(args, 'list', listnum),
 +
groupstyle = checkElAliases(args, 'groupstyle', listnum),
 +
liststyle = checkElAliases(args, 'liststyle', listnum),
 +
listpadding = checkElAliases(args, 'listpadding', listnum)
 +
}
 +
renderListRow(tbl, args, i, #listnums, rowArgs)
 
end
 
end
renderBelowRow(tbl)
+
renderBelowRow(tbl, args)
  
 
return tbl
 
return tbl
 
end
 
end
  
function p._navbox(navboxArgs)
+
-- Read the arguments in the order they'll be output in, to make references number in the right order.
args = navboxArgs
+
local function readInTheRightOrder(args, groupAliases, listAliases)
 +
local _
 +
_ = checkAliases(args, commonAliases.title)
 +
_ = checkAliases(args, commonAliases.above)
 +
for i = 1, 23 do
 +
_ = checkAliases(args, groupAliases, i)
 +
_ = checkAliases(args, listAliases, i)
 +
end
 +
_ = checkAliases(args, commonAliases.below)
 +
end
 +
 
 +
function p._navbox(args)
 
if not yesno then
 
if not yesno then
yesno = require('Module:Yesno');
+
yesno = require('Module:Yesno')
 
end
 
end
  
 +
local listnums = {}
 
for k, v in pairs(args) do
 
for k, v in pairs(args) do
 
local listnum = ('' .. k):match('^list(%d+)$') or ('' .. k):match('^список(%d+)$')
 
local listnum = ('' .. k):match('^list(%d+)$') or ('' .. k):match('^список(%d+)$')
Строка 417: Строка 521:
 
table.sort(listnums)
 
table.sort(listnums)
  
border = mw.text.trim(args.border or args[1] or '')
+
args.border = mw.text.trim(args.border or args[1] or '')
if border == 'child' then
+
if args.border == 'child' then
border = 'subgroup'
+
args.border = 'subgroup'
 
end
 
end
 
 
maintitle = args.title or args['заголовок']
+
for argname, aliasesList in pairs(commonAliases) do
navbar = args.navbar or args['ссылка_на_просмотр']
+
args[argname] = checkAliases(args, aliasesList)
name = args.name or args['имя']
+
end
navigation = yesno(args.navigation or args['навигация'], '')
+
for argname, aliasesList in pairs(standardAliases) do
above = args.above or args['вверху']
+
args[argname] = checkAliases(args, aliasesList)
image = args.image or args['изображение']
+
end
imagestyle = args.imagestyle or args['стиль_изображения']
+
 
imageleft = args.imageleft or args['изображение2'] or args['изображение_слева']
+
args.navigation = yesno(args.navigation, '')
imageleftstyle = args.imageleftstyle or args.imagestyle2 or args['стиль_изображения_слева']
 
below = args.below or args['внизу']
 
titlestyle = args.titlestyle or args['стиль_основного_заголовка'] or args['стиль_заголовка']
 
groupstyle = args.groupstyle or args['стиль_заголовков'] or args['стиль_групп']
 
bodystyle = args.bodystyle or args['стиль_тела']
 
basestyle = args.basestyle or args['стиль_базовый'] or args['стиль']
 
style = args.style
 
liststyle = args.liststyle or args['стиль_списков']
 
abovestyle = args.abovestyle or args['стиль_вверху']
 
belowstyle = args.belowstyle or args['стиль_внизу']
 
evenodd_VARIABLE = args.evenodd or args['чётные_нечётные'] or args['четные_нечетные']
 
 
groupwidth = args.groupwidth or args['ширина_групп']
 
listpadding = args.listpadding or args['отступ_списков']
 
 
bodyclass = args.bodyclass or args['класс_тела']
 
titleclass = args.titleclass or args['класс_заголовка']
 
aboveclass = args.aboveclass or args['класс_вверху']
 
belowclass = args.belowclass or args['класс_внизу']
 
groupclass = args.groupclass or args['класс_групп']
 
listclass = args.listclass or args['класс_списков']
 
imageclass = args.imageclass or args['класс_изображения']
 
 
 
 
-- render the main body of the navbox
 
-- render the main body of the navbox
local tbl = renderMainTable()
+
local tbl = renderMainTable(args, listnums)
  
 
-- render the appropriate wrapper around the navbox, depending on the border param
 
-- render the appropriate wrapper around the navbox, depending on the border param
 
local res = mw.html.create()
 
local res = mw.html.create()
if border == 'none' then
+
if args.border == 'none' then
 
local nav = res:tag('div')
 
local nav = res:tag('div')
 
:attr('role', 'navigation')
 
:attr('role', 'navigation')
 
:node(tbl)
 
:node(tbl)
if maintitle then
+
if args.title then
nav:attr('aria-labelledby', mw.uri.anchorEncode(maintitle))
+
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
 
else
 
else
 
nav:attr('aria-label', 'Навигационный шаблон')
 
nav:attr('aria-label', 'Навигационный шаблон')
 
end
 
end
if name and name ~= '-' then
+
if args.name and args.name ~= '-' then
nav:attr('data-name', name)
+
nav:attr('data-name', args.name)
 
end
 
end
if navigation == true then
+
if args.navigation == true then
 
nav:attr('data-navboxnavigation', '1')
 
nav:attr('data-navboxnavigation', '1')
elseif navigation == false then
+
elseif args.navigation == false then
 
nav:attr('data-navboxnavigation', '0')
 
nav:attr('data-navboxnavigation', '0')
 
end
 
end
elseif border == 'subgroup' then
+
elseif args.border == 'subgroup' then
 
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
 
-- 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
 
-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
Строка 487: Строка 569:
 
:attr('role', 'navigation')
 
:attr('role', 'navigation')
 
:addClass('navbox')
 
:addClass('navbox')
:cssText(bodystyle)
+
:cssText(args.bodystyle)
:cssText(style)
 
 
:css('padding', '3px')
 
:css('padding', '3px')
 
:node(tbl)
 
:node(tbl)
if maintitle then
+
if args.title then
nav:attr('aria-labelledby', mw.uri.anchorEncode(maintitle))
+
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
 
else
 
else
 
nav:attr('aria-label', 'Навигационный шаблон')
 
nav:attr('aria-label', 'Навигационный шаблон')
 
end
 
end
if name and name ~= '-' then
+
if args.name and args.name ~= '-' then
nav:attr('data-name', name)
+
nav:attr('data-name', args.name)
 
end
 
end
if navigation == true then
+
if args.navigation == true then
 
nav:attr('data-navboxnavigation', '1')
 
nav:attr('data-navboxnavigation', '1')
elseif navigation == false then
+
elseif args.navigation == false then
 
nav:attr('data-navboxnavigation', '0')
 
nav:attr('data-navboxnavigation', '0')
 
end
 
end
Строка 507: Строка 588:
 
end
 
end
  
renderTrackingCategories(res)
+
renderTrackingCategories(res, args)
  
return striped(tostring(res))
+
return striped(tostring(res), args)
 
end
 
end
  
Строка 517: Строка 598:
 
end
 
end
 
if not yesno then
 
if not yesno then
yesno = require('Module:Yesno');
+
yesno = require('Module:Yesno')
 
end
 
end
 
args = getArgs(frame, {wrappers = {'Шаблон:Навигационная таблица', 'Шаблон:Подгруппы навигационной таблицы'}})
 
args = getArgs(frame, {wrappers = {'Шаблон:Навигационная таблица', 'Шаблон:Подгруппы навигационной таблицы'}})
Строка 525: Строка 606:
 
end
 
end
 
 
-- Read the arguments in the order they'll be output in, to make references number in the right order.
+
readInTheRightOrder(args, standardElementAliases.group, standardElementAliases.list)
local _
 
_ = maintitle
 
_ = above
 
for i = 1, 23 do
 
_ = args["group" .. tostring(i)] and args["заголовок" .. tostring(i)] and args["группа" .. tostring(i)]
 
_ = args["list" .. tostring(i)] and args["список" .. tostring(i)]
 
end
 
_ = below
 
  
 
return p._navbox(args)
 
return p._navbox(args)
 +
end
 +
 +
function p.navboxWithCollapsibleGroups(frame)
 +
if not getArgs then
 +
getArgs = require('Module:Arguments').getArgs
 +
end
 +
local args = getArgs(frame, {wrappers = {'Шаблон:Навигационная таблица с блоками'}})
 +
 +
readInTheRightOrder(args, groupsChildAliases.title, groupsChildAliases.list1)
 +
 +
local parent = {}
 +
for argname, aliasesList in pairs(commonAliases) do
 +
parent[argname] = checkAliases(args, aliasesList)
 +
end
 +
for argname, aliasesList in pairs(groupsParentAliases) do
 +
parent[argname] = checkAliases(args, aliasesList)
 +
end
 +
 +
for i = 1, 20 do
 +
local child = {}
 +
for argname, aliasesList in pairs(groupsChildAliases) do
 +
child[argname] = checkAliases(args, aliasesList, i)
 +
end
 +
 +
child.color = child.color and string.format('background:%s;', child.color) or ''
 +
child.border = 'child'
 +
child.navbar = 'plain'
 +
 +
if parent.selected and parent.selected == child.groupname then
 +
child.state = 'uncollapsed'
 +
end
 +
 +
child.state = child.state or 'collapsed'
 +
 +
child.basestyle = concatStyles{parent.basestyle, parent.secttitlestyle, child.secttitlestyle}
 +
    child.titlestyle = concatStyles{parent._groupstyle, child.groupstyle, child.color}
 +
    child.liststyle  = concatStyles{parent._liststyle, child.liststyle}
 +
    child.lispadding = parent._listpadding
 +
 +
if child.title then
 +
parent['list' .. i] = p._navbox(child)
 +
else
 +
parent['list' .. i] = child.list1
 +
end
 +
end
 +
 +
return p._navbox(parent)
 +
 
end
 
end
  
 
return p
 
return p

Версия 13:55, 2 марта 2021

Этот модуль используется группой основных навигационных шаблонов — {{Навигационные шаблоны}}. В частности шаблоном {{Навигационная таблица}}. Пожалуйста, просмотрите страницу шаблона, чтобы увидеть инструкцию по его использованию.

Отслеживающие/служебные категории


--
-- Реализует {{навигационная таблица}}, {{подгруппы навигационной таблицы}} и {{навигационная таблица с блоками}}.
-- Основной объём кода заимствован из английского Module:Navbox.
--

local p = {}

local getArgs -- lazily initialized
local yesno -- lazily initialized
local styleratio

local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
local RESTART_MARKER = '\127_ODDEVEN0_\127'
local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127'

-- общие параметры для всех шаблонов
local commonAliases = {
	name = {'name', 'имя'},
	navigation = {'navigation', 'навигация'},
	navbar = {'navbar', 'ссылка_на_просмотр'},
	state = {'state'},
	orphan = {'orphan'},
	tracking = {'tracking'},
	border = {'border', 1},
	title = {'title', 'заголовок'},
	titlegroup = {'titlegroup'},
	above = {'above', 'вверху'},
	image = {'image', 'изображение'},
	imageleft = {'imageleft', 'изображение2', 'изображение_слева'},
	below = {'below', 'внизу'},
		
	bodyclass = {'bodyclass', 'класс_тела'},
	titleclass = {'titleclass', 'класс_заголовка'},
	titlegroupclass = {'titlegroupclass'},
	aboveclass = {'aboveclass', 'класс_вверху'},
	belowclass = {'belowclass', 'класс_внизу'},
	groupclass = {'groupclass', 'класс_групп'},
	listclass = {'listclass', 'класс_списков'},
	imageclass = {'imageclass', 'класс_изображения'},
	
	basestyle = {'basestyle', 'стиль', 'стиль_базовый'},
	bodystyle = {'style', 'bodystyle', 'стиль_тела'},
	titlestyle = {'titlestyle', 'стиль_основного_заголовка', 'стиль_заголовка'},
	titlegroupstyle = {'titlegroupstyle'},
	innerstyle = {'innerstyle'},
	abovestyle = {'abovestyle', 'стиль_вверху'},
	belowstyle = {'belowstyle', 'стиль_внизу'},
	imagestyle = {'imagestyle', 'стиль_изображения'},
	imageleftstyle = {'imageleftstyle', 'imagestyle2', 'стиль_изображения_слева'},
}

-- параметры {{навигационная таблица}} и {{подгруппы навигационной таблицы}}
local standardAliases = {
	groupstyle = {'groupstyle', 'стиль_заголовков', 'стиль_групп'},
	liststyle = {'liststyle', 'стиль_списков'},
	evenodd = {'evenodd', 'чётные_нечётные', 'четные_нечетные'},
	groupwidth = {'groupwidth', 'ширина_групп'},
	listpadding = {'listpadding', 'отступ_списков'},
}

-- параметры {{навигационная таблица}} и {{подгруппы навигационной таблицы}} с нумерацией
local standardElementAliases = {
	group = {'group%s', 'заголовок%s', 'группа%s'},
	list = {'list%s', 'список%s'},
	groupstyle = {'group%sstyle', 'стиль_заголовка%s', 'стиль_группы%s'},
	liststyle = {'list%sstyle', 'стиль_списка%s'},
	listpadding = {'list%spadding'}
}

-- параметры {{навигационная таблица с блоками}}
-- с нижнего подчеркивания начинаются параметры, конфликтующие с standardAliases 
local groupsParentAliases = {
	selected = {'selected', 'открытый_блок', 'развернуть'},
	secttitlestyle = {'secttitlestyle', 'стиль_заголовков'},
	_groupstyle = {'groupstyle', 'стиль_блоков'},
	_liststyle = {'liststyle', 'стиль_списков', 'contentstyle'},
	_listpadding = {'listpadding', 'отступ_списка', 'отступ_списков'}
}

-- параметры {{навигационная таблица с блоками}} с нумерацией
local groupsChildAliases = {
	groupname = {'abbr%s', 'имя_блока%s', 'аббр%s'},
	state = {'state%s'},
	title = {'group%s', 'блок%s', 'заголовок%s', 'группа%s', 'sect%s', 'section%s', 'секция%s'},
	list1 = {'list%s', 'список%s', 'content%s'},
	image = {'image%s', 'изображение%s'},
	imageleft = {'imageleft%s', 'изображение_слева%s'},

	secttitlestyle = {'sect%stitlestyle', 'стиль%sзаголовка', 'стиль_секции%s'},
	groupstyle = {'group%sstyle', 'стиль%sблока', 'стиль_группы%s', 'стиль_блока%s'},
	liststyle = {'list%sstyle', 'стиль%sсписка', 'стиль_списка%s', 'content%sstyle'},
	color = {'цвет%s'}
}

local function checkAliases(args, aliases, index)
	for _, alias in ipairs(aliases) do
		local arg
		if index then
			arg = args[string.format(alias, index)]
		else
			arg = args[alias]
		end
		
		if arg then
			return arg
		end
	end
	
	return nil
end

local function checkElAliases(args, name, index)
	return checkAliases(args, standardElementAliases[name], index)
end

local function concatStyles(t)
	local res
	for k, v in pairs(t) do
		if v then
			res = res and res .. ';' .. v or v
		end
	end
	return res
end

local function striped(wikitext, args)
	-- Return wikitext with markers replaced for odd/even striping.
	-- Child (subgroup) navboxes are flagged with a category that is removed
	-- by parent navboxes. The result is that the category shows all pages
	-- where a child navbox is not contained in a parent navbox.
	local orphanCat = '[[Категория:Навигационные шаблоны без родителя]]'
	if args.border == 'subgroup' and args.orphan ~= 'yes' then
		-- No change; striping occurs in outermost navbox.
		return wikitext .. orphanCat
	end
	local first, second = 'odd', 'even'
	if args.evenodd then
		if args.evenodd == 'swap' then
			first, second = second, first
		else
			first = args.evenodd
			second = first
		end
	end
	local changer
	if first == second then
		changer = first
	else
		local index = 0
		changer = function (code)
			if code == '0' then
				-- Current occurrence is for a group before a nested table.
				-- Set it to first as a valid although pointless class.
				-- The next occurrence will be the first row after a title
				-- in a subgroup and will also be first.
				index = 0
				return first
			end
			index = index + 1
			return index % 2 == 1 and first or second
		end
	end
	local regex = orphanCat:gsub('([%[%]])', '%%%1')
	return (wikitext:gsub(regex, ''):gsub(REGEX_MARKER, changer))  -- () omits gsub count
end

local function addNewline(s)
	if s:match('^[*:;#]') or s:match('^{|') then
		return '\n' .. s ..'\n'
	else
		return s
	end
end

local function renderNavBar(titleCell, args)

	if args.navbar ~= 'off' and args.navbar ~= 'plain' 
		and (args.name or not mw.getCurrentFrame():getParent():getTitle():gsub('/песочница$', '') == 'Шаблон:Навигационная таблица') then
		
		-- Check color contrast of the gear icon
		if not styleratio then
			styleratio = require('Module:Color contrast')._styleratio
		end
		local gearColor = ''
		local contrastStyle = args.titlestyle or args.basestyle
		local gearStyleBlack = (contrastStyle and mw.text.unstripNoWiki(contrastStyle) .. '; color:#666;' or '')
		local gearStyleWhite = (contrastStyle and mw.text.unstripNoWiki(contrastStyle) .. '; color:#fff;' or '')
		if styleratio{gearStyleBlack} < styleratio{gearStyleWhite} then
			gearColor = ' white'
		end
		local gear = string.format(
			'[[Файл:Wikipedia interwiki section gear icon%s.svg|14px|Просмотр этого шаблона|link=Шаблон:%s|alt=⛭]]',
			gearColor, args.name
		)
		
		--- Gear creation
		titleCell
			:tag('span')
				:addClass('navbox-gear')
				:css('float', 'left')
				:css('text-align', 'left')
				:css('width', '5em')
				:css('margin-right', '0.5em')
				:wikitext(gear)
	end

end

--
--   Title row
--
local function renderTitleRow(tbl, args)
	if not args.title then return end

	local titleRow = tbl:tag('tr')

	if args.titlegroup then
		titleRow
			:tag('th')
				:attr('scope', 'row')
				:addClass('navbox-group')
				:addClass(args.titlegroupclass)
				:cssText(args.basestyle)
				:cssText(args.groupstyle)
				:cssText(args.titlegroupstyle)
				:wikitext(args.titlegroup)
	end

	local titleCell = titleRow:tag('th'):attr('scope', 'col')

	if args.titlegroup then
		titleCell
			:css('border-left', '2px solid #fdfdfd')
			:css('width', '100%')
	end

	local titleColspan = 2
	if args.imageleft then titleColspan = titleColspan + 1 end
	if args.image then titleColspan = titleColspan + 1 end
	if args.titlegroup then titleColspan = titleColspan - 1 end

	titleCell
		:cssText(args.basestyle)
		:cssText(args.titlestyle)
		:addClass('navbox-title')
		:attr('colspan', titleColspan)

	renderNavBar(titleCell, args)

	titleCell
		:tag('div')
			:attr('id', mw.uri.anchorEncode(args.title))
			:addClass(args.titleclass)
			:css('font-size', '114%')
			:css('margin', '0 5em')
			:wikitext(addNewline(args.title))
end

--
--   Above/Below rows
--

local function getAboveBelowColspan(args)
	local ret = 2
	if args.imageleft then ret = ret + 1 end
	if args.image then ret = ret + 1 end
	return ret
end

local function renderAboveRow(tbl, args)
	if not args.above then return end

	tbl:tag('tr')
		:tag('td')
			:addClass('navbox-abovebelow')
			:addClass(args.aboveclass)
			:cssText(args.basestyle)
			:cssText(args.abovestyle)
			:attr('colspan', getAboveBelowColspan(args))
			:tag('div')
				:wikitext(addNewline(args.above))
end

local function renderBelowRow(tbl, args)
	if not args.below then return end

	tbl:tag('tr')
		:tag('td')
			:addClass('navbox-abovebelow')
			:addClass(args.belowclass)
			:cssText(args.basestyle)
			:cssText(args.belowstyle)
			:attr('colspan', getAboveBelowColspan(args))
			:tag('div')
				:wikitext(addNewline(args.below))
end

--
--   List rows
--

local function haveSubgroups(args)
	for i = 1, 23 do
		if checkElAliases(args, 'group', i) and checkElAliases(args, 'list', i) then
			return true
		end
	end
	return false
end

local function renderListRow(tbl, args, index, rowspan, rowArgs)
	local row = tbl:tag('tr')

	if index == 1 and args.imageleft then
		row
			:tag('td')
				:addClass('navbox-image')
				:addClass(args.imageclass)
				:css('width', '1px')
				:css('padding', '0px 7px 0px 0px')
				:cssText(args.imageleftstyle)
				:attr('rowspan', rowspan)
				:tag('div')
					:wikitext(addNewline(args.imageleft))
	end

	if rowArgs.group then
		local groupCell = row:tag('th')

		groupCell
			:attr('scope', 'row')
			:addClass('navbox-group')
			:addClass(args.groupclass)
			:cssText(args.basestyle)
			:css('width', args.groupwidth or '1px') -- If groupwidth not specified, minimize width

		groupCell
			:cssText(args.groupstyle)
			:cssText(rowArgs.groupstyle)
			:wikitext(rowArgs.group)
	end

	local listCell = row:tag('td')

	if rowArgs.group then
		listCell
			:css('text-align', 'left')
			:css('border-left-width', '2px')
			:css('border-left-style', 'solid')
	else
		if haveSubgroups(args) then
			listCell
				:attr('colspan', 2)
		end
	end

	if not args.groupwidth then
		listCell:css('width', '100%')
	end

	local listText = rowArgs.list
	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"') and RESTART_MARKER or 'odd'
	end
	listCell
		:css('padding', '0px')
		:cssText(args.liststyle)
		:cssText(rowArgs.liststyle)
		:addClass('navbox-list')
		:addClass('navbox-' .. oddEven)
		:addClass(args.listclass)
		:tag('div')
			:css('padding', rowArgs.listpadding or args.listpadding or '0em 0.25em')
			:wikitext(addNewline(listText))

	if index == 1 and args.image then
		row
			:tag('td')
				:addClass('navbox-image')
				:addClass(args.imageclass)
				:css('width', '1px')
				:css('padding', '0px 0px 0px 7px')
				:cssText(args.imagestyle)
				:attr('rowspan', rowspan)
				:tag('div')
					:wikitext(addNewline(args.image))
	end
end

--
--   Tracking categories
--
local function needsChangetoSubgroups(args)
	for i = 1, 23 do
		if (checkElAliases(args, 'group', i)) and not (checkElAliases(args, 'list', i)) then
			return true
		end
	end
	return false
end

local function needsHorizontalLists(args)
	if args.border == 'subgroup' or args.tracking == 'no' then
		return false
	end
	local listClasses = {
		['plainlist'] = true, ['hlist'] = true, ['hlist hnum'] = true,
		['hlist hwrap'] = true, ['hlist vcard'] = true, ['vcard hlist'] = true,
		['hlist vevent'] = true, ['hlist hlist-items-nowrap'] = true, ['hlist-items-nowrap'] = true,
	}
	return not (listClasses[args.listclass] or listClasses[args.bodyclass])
end

-- local function hasBackgroundColors()
--	return mw.ustring.match(titlestyle or '','background') or mw.ustring.match(groupstyle or '','background') or mw.ustring.match(basestyle or '','background')
-- end

local function isIllegible(args)
	if not styleratio then
		styleratio = require('Module:Color contrast')._styleratio
	end

	for key, style in pairs(args) do
		if tostring(key):match("style$") or tostring(key):match("^стиль") then
			if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then
				return true 
			end
		end
	end
	return false
end

local function getTrackingCategories(args)
	local cats = {}
	if needsChangetoSubgroups(args) then table.insert(cats, 'Навигационные шаблоны с ошибочным использованием заголовков') end
	if needsHorizontalLists(args) then table.insert(cats, 'Навигационные шаблоны без горизонтальных списков') end
	if isIllegible(args) then table.insert(cats, 'Потенциально нечитаемые навигационные шаблоны') end
	return cats
end

local function renderTrackingCategories(builder, args)
	local title = mw.title.getCurrentTitle()
	if title.namespace ~= 10 then return end -- not in template space
	local subpage = title.subpageText
	if subpage == 'doc' or subpage == 'песочница' or subpage == 'тесты' then return end

	for i, cat in ipairs(getTrackingCategories(args)) do
		builder:wikitext('[[Категория:' .. cat .. ']]')
	end
end

--
--   Main navbox tables
--
local function renderMainTable(args, listnums)
	local tbl = mw.html.create('table')
		:addClass('nowraplinks')
		:addClass(args.bodyclass)

	if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
		tbl
			:addClass('collapsible')
			:addClass(args.state or 'autocollapse')
	end

	tbl:css('border-spacing', 0)
	if args.border == 'subgroup' or args.border == 'none' then
		tbl
			:addClass('navbox-subgroup')
			:cssText(args.bodystyle)
	else -- regular navbox - bodystyle and style will be applied to the wrapper table
		tbl
			:addClass('navbox-inner')
			:css('background', 'transparent')
			:css('color', 'inherit')
	end
	tbl:cssText(args.innerstyle)

	renderTitleRow(tbl, args)
	renderAboveRow(tbl, args)
	for i, listnum in ipairs(listnums) do
		local rowArgs = {
			group = checkElAliases(args, 'group', listnum),
			list = checkElAliases(args, 'list', listnum),
			groupstyle = checkElAliases(args, 'groupstyle', listnum),
			liststyle = checkElAliases(args, 'liststyle', listnum),
			listpadding = checkElAliases(args, 'listpadding', listnum)
		}
		renderListRow(tbl, args, i, #listnums, rowArgs)
	end
	renderBelowRow(tbl, args)

	return tbl
end

-- Read the arguments in the order they'll be output in, to make references number in the right order.
local function readInTheRightOrder(args, groupAliases, listAliases)
	local _
	_ = checkAliases(args, commonAliases.title)
	_ = checkAliases(args, commonAliases.above)
	for i = 1, 23 do
		_ = checkAliases(args, groupAliases, i)
		_ = checkAliases(args, listAliases, i)
	end
	_ = checkAliases(args, commonAliases.below)
end

function p._navbox(args)
	if not yesno then
		yesno = require('Module:Yesno')
	end

	local listnums = {}
	for k, v in pairs(args) do
		local listnum = ('' .. k):match('^list(%d+)$') or ('' .. k):match('^список(%d+)$')
		if listnum then table.insert(listnums, tonumber(listnum)) end
	end
	
	table.sort(listnums)

	args.border = mw.text.trim(args.border or args[1] or '')
	if args.border == 'child' then
		args.border = 'subgroup'
	end
	
	for argname, aliasesList in pairs(commonAliases) do
		args[argname] = checkAliases(args, aliasesList)	
	end
	for argname, aliasesList in pairs(standardAliases) do
		args[argname] = checkAliases(args, aliasesList)	
	end

	args.navigation = yesno(args.navigation, '')
	
	-- render the main body of the navbox
	local tbl = renderMainTable(args, listnums)

	-- render the appropriate wrapper around the navbox, depending on the border param
	local res = mw.html.create()
	if args.border == 'none' then
		local nav = res:tag('div')
			:attr('role', 'navigation')
			:node(tbl)
		if args.title then
			nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
		else
			nav:attr('aria-label', 'Навигационный шаблон')
		end
		if args.name and args.name ~= '-' then
			nav:attr('data-name', args.name)
		end
		if args.navigation == true then
			nav:attr('data-navboxnavigation', '1')
		elseif args.navigation == false then
			nav:attr('data-navboxnavigation', '0')
		end
	elseif args.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
		-- padding being applied, and at the end add a <div> to balance out the parent's </div>
		res
			:wikitext('</div>') -- XXX: hack due to lack of unclosed support in mw.html.
			:node(tbl)
			:wikitext('<div>') -- XXX: hack due to lack of unclosed support in mw.html.
	else
		local nav = res:tag('div')
			:attr('role', 'navigation')
			:addClass('navbox')
			:cssText(args.bodystyle)
			:css('padding', '3px')
			:node(tbl)
		if args.title then
			nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title))
		else
			nav:attr('aria-label', 'Навигационный шаблон')
		end
		if args.name and args.name ~= '-' then
			nav:attr('data-name', args.name)
		end
		if args.navigation == true then
			nav:attr('data-navboxnavigation', '1')
		elseif args.navigation == false then
			nav:attr('data-navboxnavigation', '0')
		end
		
	end

	renderTrackingCategories(res, args)

	return striped(tostring(res), args)
end

function p.navbox(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	if not yesno then
		yesno = require('Module:Yesno')
	end
	args = getArgs(frame, {wrappers = {'Шаблон:Навигационная таблица', 'Шаблон:Подгруппы навигационной таблицы'}})
	if frame.args.border then
		-- This allows Template:Navbox_subgroup to use {{#invoke:Navbox|navbox|border=...}}.
		args.border = frame.args.border
	end
	
	readInTheRightOrder(args, standardElementAliases.group, standardElementAliases.list)

	return p._navbox(args)
end

function p.navboxWithCollapsibleGroups(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	local args = getArgs(frame, {wrappers = {'Шаблон:Навигационная таблица с блоками'}})
	
	readInTheRightOrder(args, groupsChildAliases.title, groupsChildAliases.list1)
	
	local parent = {}
	for argname, aliasesList in pairs(commonAliases) do
		parent[argname] = checkAliases(args, aliasesList)	
	end
	for argname, aliasesList in pairs(groupsParentAliases) do
		parent[argname] = checkAliases(args, aliasesList)	
	end
				
	for i = 1, 20 do
		local child = {}
		for argname, aliasesList in pairs(groupsChildAliases) do
			child[argname] = checkAliases(args, aliasesList, i)	
		end
		
		child.color = child.color and string.format('background:%s;', child.color) or ''
		child.border = 'child'
		child.navbar = 'plain'
	
		if parent.selected and parent.selected == child.groupname then
			child.state = 'uncollapsed'
		end
		
		child.state = child.state or 'collapsed'
		
		child.basestyle = concatStyles{parent.basestyle, parent.secttitlestyle, child.secttitlestyle}
    	child.titlestyle = concatStyles{parent._groupstyle, child.groupstyle, child.color}
    	child.liststyle  = concatStyles{parent._liststyle, child.liststyle}
    	child.lispadding = parent._listpadding
		
		if child.title then
			parent['list' .. i] = p._navbox(child)
		else
			parent['list' .. i] = child.list1
		end
	end
	
	return p._navbox(parent)
	
end

return p