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

Материал из in.wiki
Перейти к навигации Перейти к поиску
м (откат правок 37.75.200.122 (обс) к версии Vlsergey)
м (1 версия импортирована: Импорт из Википедии)
 
(не показано 77 промежуточных версий 16 участников)
Строка 1: Строка 1:
 
--
 
--
-- This module will implement {{Navbox}}
+
-- Реализует {{навигационная таблица}}, {{подгруппы навигационной таблицы}} и {{навигационная таблица с блоками}}.
 +
-- Основной объём кода заимствован из английского Module:Navbox.
 
--
 
--
+
 
 
local p = {}
 
local p = {}
 
local HtmlBuilder = require('Module:HtmlBuilder')
 
local Navbar = require('Module:Navbar')
 
  
local args
+
local navbar = require('Module:Navbar')._ruwikiNavbar
local frame
+
local getArgs -- lazily initialized
local tableRowAdded = false
+
local yesno -- lazily initialized
local border
+
local styleratio
local listnums = {}
+
 
+
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
function trim(s)
+
local RESTART_MARKER = '\127_ODDEVEN0_\127'
    return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
+
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'},
 +
listclass = {'list%sclass', 'класс%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'},
 +
listclass = {'list%sclass', 'класс%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
 
end
  
function addTableRow(tbl)
+
local function addNewline(s)
    -- If any other rows have already been added, then we add a 2px gutter row.
+
if s:match('^[*:;#]') or s:match('^{|') then
    if tableRowAdded then
+
return '\n' .. s ..'\n'
        tbl
+
else
            .tag('tr')
+
return s
                .css('height', '2px')
+
end
                .tag('td')
 
    end
 
   
 
    tableRowAdded = true
 
   
 
    return tbl.tag('tr')
 
 
end
 
end
  
 +
local function renderNavBar(titleCell, args)
 +
local currentFrame = mw.getCurrentFrame()
 +
if args.navbar ~= 'off' and args.navbar ~= 'plain'
 +
and (args.name or not currentFrame:getParent():getTitle():gsub('/песочница$', '') == 'Шаблон:Навигационная таблица') then
 +
 +
--- Gear creation
 +
titleCell
 +
:tag('span')
 +
:addClass('navbox-gear')
 +
:css('float', 'left')
 +
:css('text-align', 'left')
 +
:css('width', '5em')
 +
:css('margin-right', '0.5em')
 +
:wikitext(navbar{
 +
args.name,
 +
['fontstyle'] = args.titlestyle or args.basestyle
 +
})
 +
end
 +
 +
end
  
 
--
 
--
 
--  Title row
 
--  Title row
 
--
 
--
function renderTitleRow(tbl)
+
local function renderTitleRow(tbl, args)
    if not args.title then return end
+
if not args.title then return end
+
 
    local titleRow = addTableRow(tbl)
+
local titleRow = tbl:tag('tr')
   
+
 
    if args.titlegroup then
+
if args.titlegroup then
        titleRow
+
titleRow
            .tag('th')
+
:tag('th')
                .attr('scope', 'row')
+
:attr('scope', 'row')
                .addClass('navbox-group')
+
:addClass('navbox-group')
                .addClass(args.titlegroupclass)
+
:addClass(args.titlegroupclass)
                .cssText(args.basestyle)
+
:cssText(args.basestyle)
                .cssText(args.groupstyle)
+
:cssText(args.groupstyle)
                .cssText(args.titlegroupstyle)
+
:cssText(args.titlegroupstyle)
                .wikitext(args.titlegroup)
+
:wikitext(args.titlegroup)
    end
+
end
   
+
 
    local titleCell = titleRow.tag('th').attr('scope', 'col')
+
local titleCell = titleRow:tag('th'):attr('scope', 'colgroup')
           
+
 
    if args.titlegroup then
+
if args.titlegroup then
        titleCell
+
titleCell
            .css('border-left', '2px solid #fdfdfd')
+
:css('border-left', '2px solid #fdfdfd')
            .css('width', '100%')
+
:css('width', '100%')
    end
+
end
   
+
 
    local titleColspan = 2
+
local titleColspan = 2
    if args.imageleft then titleColspan = titleColspan + 1 end
+
if args.imageleft then titleColspan = titleColspan + 1 end
    if args.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
 
        .cssText(args.basestyle)
 
        .cssText(args.titlestyle)
 
        .addClass('navbox-title')
 
        .attr('colspan', titleColspan)
 
 
    renderNavBar(titleCell)
 
 
    titleCell
 
        .tag('div')
 
            .addClass(args.titleclass)
 
            .css('font-size', '110%')
 
            .newline()
 
            .wikitext(args.title)
 
end
 
  
function renderNavBar(titleCell)
+
titleCell
    -- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left
+
:cssText(args.basestyle)
    -- or right to keep the title centered.
+
:cssText(args.titlestyle)
    local spacerSide = nil
+
:addClass('navbox-title')
 +
:attr('colspan', titleColspan)
  
    if args.navbar == 'off' then
+
renderNavBar(titleCell, args)
        -- No navbar, and client wants no spacer, i.e. wants the title to be shifted to the left. If there's
 
        -- also no show/hide link, then we need a spacer on the right to achieve the left shift.
 
        if args.state == 'plain' then spacerSide = 'right' end
 
    elseif args.navbar == 'plain' or args.navbar == 'off' or (not args.name and (border == 'subgroup' or border == 'child' or border == 'none')) then
 
        -- No navbar. Need a spacer on the left to balance out the width of the show/hide link.
 
        if args.state ~= 'plain' then spacerSide = 'left' end
 
    else
 
        -- Will render navbar (or error message). If there's no show/hide link, need a spacer on the right
 
        -- to balance out the width of the navbar.
 
        if args.state == 'plain' then spacerSide = 'right' end
 
  
        titleCell.wikitext(Navbar.navbar({
+
titleCell
            args.name,
+
:tag('div')
            mini = 1,
+
:attr('id', mw.uri.anchorEncode(args.title))
            fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') ..  ';background:none transparent;border:none;'
+
:addClass(args.titleclass)
        }))
+
:css('font-size', '114%')
    end
+
:css('margin', '0 5em')
   
+
:wikitext(addNewline(args.title))
    -- Render the spacer div.
 
    if spacerSide then
 
        titleCell
 
            .tag('span')
 
                .css('float', spacerSide)
 
                .css('width', '6em')
 
                .wikitext(' ')
 
    end
 
 
end
 
end
 
  
 
--
 
--
 
--  Above/Below rows
 
--  Above/Below rows
 
--
 
--
function renderAboveRow(tbl)
+
 
    if not args.above then return end
+
local function getAboveBelowColspan(args)
+
local ret = 2
    addTableRow(tbl)
+
if args.imageleft then ret = ret + 1 end
        .tag('td')
+
if args.image then ret = ret + 1 end
            .addClass('navbox-abovebelow')
+
return ret
            .addClass(args.aboveclass)
 
            .cssText(args.basestyle)
 
            .cssText(args.abovestyle)
 
            .attr('colspan', getAboveBelowColspan())
 
            .tag('div')
 
                .newline()
 
                .wikitext(args.above)
 
 
end
 
end
  
function renderBelowRow(tbl)
+
local function renderAboveRow(tbl, args)
    if not args.below then return end
+
if not args.above then return end
   
+
 
    addTableRow(tbl)
+
tbl:tag('tr')
        .tag('td')
+
:tag('td')
            .addClass('navbox-abovebelow')
+
:addClass('navbox-abovebelow')
            .addClass(args.belowclass)
+
:addClass(args.aboveclass)
            .cssText(args.basestyle)
+
:cssText(args.basestyle)
            .cssText(args.belowstyle)
+
:cssText(args.abovestyle)
            .attr('colspan', getAboveBelowColspan())
+
:attr('colspan', getAboveBelowColspan(args))
            .tag('div')
+
:tag('div')
                .newline()
+
:wikitext(addNewline(args.above))
                .wikitext(args.below)
 
 
end
 
end
  
function getAboveBelowColspan()
+
local function renderBelowRow(tbl, args)
    local ret = 2
+
if not args.below then return end
    if args.imageleft then ret = ret + 1 end
+
 
    if args.image then ret = ret + 1 end
+
tbl:tag('tr')
    return ret
+
: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
 
end
+
 
 
 
--
 
--
 
--  List rows
 
--  List rows
 
--
 
--
function renderListRow(tbl, listnum)
 
    local row = addTableRow(tbl)
 
   
 
    if listnum == 1 and args.imageleft then
 
        row
 
            .tag('td')
 
                .addClass('navbox-image')
 
                .addClass(args.imageclass)
 
                .css('width', '0%')
 
                .css('padding', '0px 2px 0px 0px')
 
                .cssText(args.imageleftstyle)
 
                .attr('rowspan', 2 * #listnums - 1)
 
                .tag('div')
 
                    .newline()
 
                    .wikitext(args.imageleft)
 
    end
 
 
    if args['group' .. listnum] then
 
        local groupCell = row.tag('th')
 
       
 
        groupCell
 
              .attr('scope', 'row')
 
              .addClass('navbox-group')
 
              .addClass(args.groupclass)
 
              .cssText(args.basestyle)
 
             
 
        if args.groupwidth then
 
            groupCell.css('width', args.groupwidth)
 
        end
 
         
 
        groupCell
 
            .cssText(args.groupstyle)
 
            .cssText(args['group' .. listnum .. 'style'])
 
            .wikitext(args['group' .. listnum])
 
    end
 
   
 
    local listCell = row.tag('td')
 
  
    if args['group' .. listnum] then
+
local function haveSubgroups(args)
        listCell
+
for i = 1, 23 do
            .css('text-align', 'left')
+
if checkElAliases(args, 'group', i) and checkElAliases(args, 'list', i) then
            .css('border-left-width', '2px')
+
return true
            .css('border-left-style', 'solid')
+
end
    else
+
end
        listCell.attr('colspan', 2)
+
return false
    end
+
end
   
+
 
    if not args.groupwidth then  
+
local function renderListRow(tbl, args, index, rowspan, rowArgs)
        listCell.css('width', '100%')
+
local row = tbl:tag('tr')
    end
+
 
   
+
if index == 1 and args.imageleft then
    local isOdd = (listnum % 2) == 1
+
row
    local rowstyle = args.evenstyle
+
:tag('td')
    if isOdd then rowstyle = args.oddstyle end
+
:addClass('navbox-image')
+
:addClass(args.imageclass)
    local evenOdd
+
:css('width', '1px')
    if args.evenodd == 'swap' then
+
:css('padding', '0px 7px 0px 0px')
        if isOdd then evenOdd = 'even' else evenOdd = 'odd' end
+
:cssText(args.imageleftstyle)
    else
+
:attr('rowspan', rowspan)
        if isOdd then evenOdd = args.evenodd or 'odd' else evenOdd = args.evenodd or 'even' end
+
:tag('div')
    end
+
:wikitext(addNewline(args.imageleft))
   
+
end
    listCell
+
 
        .css('padding', '0px')
+
if rowArgs.group then
        .cssText(args.liststyle)
+
local groupCell = row:tag('th')
        .cssText(rowstyle)
+
 
        .cssText(args['list' .. listnum .. 'style'])
+
groupCell
        .addClass('navbox-list')
+
:attr('scope', 'row')
        .addClass('navbox-' .. evenOdd)
+
:addClass('navbox-group')
        .addClass(args.listclass)
+
:addClass(args.groupclass)
        .tag('div')
+
:cssText(args.basestyle)
            .css('padding', (listnum == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
+
:css('width', args.groupwidth or '1px') -- If groupwidth not specified, minimize width
            .newline()
+
 
            .wikitext(args['list' .. listnum])
+
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)
 +
:addClass(rowArgs.listclass)
 +
:tag('div')
 +
:css('padding', rowArgs.listpadding or args.listpadding or '0em 0.25em')
 +
:wikitext(addNewline(listText))
  
    if listnum == 1 and args.image then
+
if index == 1 and args.image then
        row
+
row
            .tag('td')
+
:tag('td')
                .addClass('navbox-image')
+
:addClass('navbox-image')
                .addClass(args.imageclass)
+
:addClass(args.imageclass)
                .css('width', '0%')
+
:css('width', '1px')
                .css('padding', '0px 0px 0px 2px')
+
:css('padding', '0px 0px 0px 7px')
                .cssText(args.imagestyle)
+
:cssText(args.imagestyle)
                .attr('rowspan', 2 * #listnums - 1)
+
:attr('rowspan', rowspan)
                .tag('div')
+
:tag('div')
                    .newline()
+
:wikitext(addNewline(args.image))
                    .wikitext(args.image)
+
end
    end
 
 
end
 
end
 
  
 
--
 
--
 
--  Tracking categories
 
--  Tracking categories
 
--
 
--
function renderTrackingCategories(builder)
+
local function needsChangetoSubgroups(args)
    local frame = mw.getCurrentFrame()
+
for i = 1, 23 do
   
+
if (checkElAliases(args, 'group', i)) and not (checkElAliases(args, 'list', i)) then
    if not frame then return end
+
return true
   
+
end
    local s = frame:preprocess('{{#ifeq:{{NAMESPACE}}|{{ns:10}}|1|0}}{{SUBPAGENAME}}')
+
end
    if mw.ustring.sub(s, 1, 1) == '0' then return end -- not in template space
+
return false
    local subpage = mw.ustring.lower(mw.ustring.sub(s, 2))
 
    if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
 
   
 
    for i, cat in ipairs(getTrackingCategories()) do
 
        builder.wikitext('[[Category:' .. cat .. ']]')
 
    end
 
 
end
 
end
  
function getTrackingCategories()
+
local function needsHorizontalLists(args)
    local cats = {}
+
if args.border == 'subgroup' or args.tracking == 'no' then
    if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end
+
return false
    if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
+
end
    return cats
+
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
 
end
  
function needsHorizontalLists()
+
-- local function hasBackgroundColors()
    if border == 'child' or border == 'subgroup' or args.tracking == 'no' then return false end
+
-- return mw.ustring.match(titlestyle or '','background') or mw.ustring.match(groupstyle or '','background') or mw.ustring.match(basestyle or '','background')
   
+
-- end
    local listClasses = {'plainlist', 'hlist', 'hlist hnum', 'hlist hwrap', 'hlist vcard', 'vcard hlist', 'hlist vevent'}
 
    for i, cls in ipairs(listClasses) do
 
        if args.listclass == cls or args.bodyclass == cls then
 
            return false
 
        end
 
    end
 
  
    return true
+
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
 
end
  
function hasBackgroundColors()
+
local function getTrackingCategories(args)
    return args.titlestyle or args.groupstyle
+
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
 
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
 
--  Main navbox tables
 
--
 
--
function renderMainTable()
+
local function renderMainTable(args, listnums)
    local tbl = HtmlBuilder.create('table')
+
local tbl = mw.html.create('table')
        .attr('cellspacing', 0)
+
:addClass('nowraplinks')
        .addClass('nowraplinks')
+
:addClass(args.bodyclass)
        .addClass(args.bodyclass)
+
 
           
+
if args.title 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')
+
:addClass(args.state or 'autocollapse')
            .addClass(args.state or 'autocollapse')
+
end
    end
+
 
+
tbl:css('border-spacing', 0)
    tbl.css('border-spacing', 0)
+
if args.border == 'subgroup' or args.border == 'none' then
    if border == 'subgroup' or border == 'child' or border == 'none' then
+
tbl
        tbl
+
:addClass('navbox-subgroup')
            .addClass('navbox-subgroup')
+
:cssText(args.bodystyle)
            .cssText(args.bodystyle)
+
else -- regular navbox - bodystyle and style will be applied to the wrapper table
            .cssText(args.style)
+
tbl
    else -- regular navobx - bodystyle and style will be applied to the wrapper table
+
:addClass('navbox-inner')
        tbl
+
:css('background', 'transparent')
            .addClass('navbox-inner')
+
:css('color', 'inherit')
            .css('background', 'transparent')
+
end
            .css('color', 'inherit')
+
tbl:cssText(args.innerstyle)
    end
+
 
    tbl.cssText(args.innerstyle)
+
renderTitleRow(tbl, args)
+
renderAboveRow(tbl, args)
    renderTitleRow(tbl)
+
for i, listnum in ipairs(listnums) do
    renderAboveRow(tbl)
+
local rowArgs = {
    for i, listnum in ipairs(listnums) do
+
group = checkElAliases(args, 'group', listnum),
        renderListRow(tbl, listnum)  
+
list = checkElAliases(args, 'list', listnum),
    end
+
groupstyle = checkElAliases(args, 'groupstyle', listnum),
    renderBelowRow(tbl)
+
listclass = checkElAliases(args, 'listclass', listnum),
   
+
liststyle = checkElAliases(args, 'liststyle', listnum),
    return tbl
+
listpadding = checkElAliases(args, 'listpadding', listnum)
 +
}
 +
renderListRow(tbl, args, i, #listnums, rowArgs)
 +
end
 +
renderBelowRow(tbl, args)
 +
 
 +
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 _
    for k, v in pairs(args) do
+
_ = checkAliases(args, commonAliases.title)
        local listnum = ('' .. k):match('^list(%d+)$')
+
_ = checkAliases(args, commonAliases.above)
        if listnum then table.insert(listnums, tonumber(listnum)) end
+
for i = 1, 23 do
    end
+
_ = checkAliases(args, groupAliases, i)
    table.sort(listnums)
+
_ = checkAliases(args, listAliases, i)
+
end
    border = trim(args.border or args[1] or '')
+
_ = 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)
 +
: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
  
    -- render the main body of the navbox
+
renderTrackingCategories(res, args)
    local tbl = renderMainTable()
 
  
    -- render the appropriate wrapper around the navbox, depending on the border param
+
return striped(tostring(res), args)
    local res = HtmlBuilder.create()
 
    if border == 'none' then
 
        res.node(tbl)
 
    elseif border == 'subgroup' or border == 'child' 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
 
            .tag('/div', {unclosed = true})
 
                .done()
 
            .node(tbl)
 
            .tag('div', {unclosed = true})
 
    else
 
        res
 
            .tag('table')
 
                .attr('cellspacing', 0)
 
                .addClass(args.navboxclass or 'navbox')
 
                .css('border-spacing', 0)
 
                .cssText(args.bodystyle)
 
                .cssText(args.style)
 
                .tag('tr')
 
                    .tag('td')
 
                        .css('padding', '2px')
 
                        .node(tbl)
 
    end
 
 
    renderTrackingCategories(res)
 
 
    return tostring(res)
 
 
end
 
end
+
 
 
function p.navbox(frame)
 
function p.navbox(frame)
    -- ParserFunctions considers the empty string to be false, so to preserve the previous
+
if not getArgs then
    -- behavior of {{navbox}}, change any empty arguments to nil, so Lua will consider
+
getArgs = require('Module:Arguments').getArgs
    -- them false too.
+
end
    local args = {}
+
if not yesno then
    local parent_args = frame:getParent().args;
+
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)
  
    -- Out of order parsing bug.
+
return p._navbox(args)
    local temp;
 
    temp = parent_args.title;
 
    temp = parent_args.above;
 
    for i = 1, 20 do
 
        temp = parent_args["group" .. tostring(i)];
 
        temp = parent_args["list" .. tostring(i)];
 
    end   
 
    temp = parent_args.below;
 
   
 
    for k, v in pairs(parent_args) do
 
        if v ~= '' then
 
            args[k] = v
 
        end
 
    end
 
    return p._navbox(args)
 
 
end
 
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
 
return p

Текущая версия от 23:20, 31 марта 2024

Ошибка Lua в Модуль:Sidebar на строке 123: bad argument #1 to 'gfind' (string expected, got nil).

This module implements the {{Navbox}} template. Please see the template page for usage instructions.

Tracking/maintenance categories


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

local p = {}

local navbar = require('Module:Navbar')._ruwikiNavbar
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'},
	listclass = {'list%sclass', 'класс%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'},
	listclass = {'list%sclass', 'класс%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)
	local currentFrame = mw.getCurrentFrame()
	if args.navbar ~= 'off' and args.navbar ~= 'plain' 
		and (args.name or not currentFrame:getParent():getTitle():gsub('/песочница$', '') == 'Шаблон:Навигационная таблица') then
		
		--- Gear creation
		titleCell
			:tag('span')
				:addClass('navbox-gear')
				:css('float', 'left')
				:css('text-align', 'left')
				:css('width', '5em')
				:css('margin-right', '0.5em')
				:wikitext(navbar{
					args.name,
					['fontstyle'] = args.titlestyle or args.basestyle
				})
	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', 'colgroup')

	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)
		:addClass(rowArgs.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),
			listclass = checkElAliases(args, 'listclass', 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)
			: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