Módulo:Navbar
Aspeto
![]() | Este módulo pode ter sua documentação deficiente. Por favor, documente-o ou melhore suas explicações caso o saiba usar ou tenha conhecimentos para tal. |
![]() | Este módulo Lua é usado em aproximadamente 782 000 páginas, ou aproximadamente 13% de todas páginas. Para evitar grandes transtornos e carga do servidor, quaisquer mudanças devem ser testadas nas subpáginas /Testes ou /Exemplos para testes do módulo, ou em sua própria subpágina de testes de módulos. As mudanças testadas podem ser adicionadas a esta página em uma única edição. Considere discutir as mudanças na página de discussão antes de implementá-las. |
![]() | Este módulo está na categoria sujeitos a proteção de página. Ele é um módulo de alta visibilidade em uso por um grande número de páginas, ou é transcluído muito frequentemente. Por causa do vandalismo ou erros que podem afectar muitas páginas, e mesmo edições triviais podem causar cargas substanciais nos servidores, ele está protegido de editar. |
![]() | Este módulo depende dos seguintes outros módulos: |
![]() | Este módulo utiliza TemplateStyles: |
Esta é uma implementação Lua de {{Navbar}}. É usada em Módulo:Navbox.
local p = {}
local cfg = mw.loadData('Módulo:Navbar/configuração')
local function get_title_arg(is_collapsible, template)
local title_arg = 1
if is_collapsible then title_arg = 2 end
if template then title_arg = 'template' end
return title_arg
end
local function choose_links(template, args)
-- A tabela de exibição indica os itens padrão exibidos.
-- visualizar, discutir, editar, histórico, mover, vigiar
-- TODO: Mover para configuração.
local show = {true, true, true, false, false, false}
if template then
show[2] = false
show[3] = false
local index = {t = 2, d = 2, e = 3, h = 4, m = 5, w = 6, vi = 6,
talk = 2, discutir = 2, ['discussão'] = 2, edit = 3, editar = 3, hist = 4, ['histórico'] = 4, move = 5, mover = 5, watch = 6, vigiar = 6}
-- TODO: Considere remover a dependência de TableTools.
for _, v in ipairs(require ('Módulo:TableTools').compressSparseArray(args)) do
local num = index[v]
if num then show[num] = true end
end
end
if (args['nãoeditar'] or args['semeditar']) and not args.noedit then args.noedit = (args['nãoeditar'] or args['semeditar']) end
local remove_edit_link = args.noedit
if remove_edit_link then show[3] = false end
return show
end
local function add_link(link_description, ul, is_mini, font_style)
local l
if link_description.url then
l = {'[', '', ']'}
else
l = {'[[', '|', ']]'}
end
ul:tag('li')
:addClass('nv-' .. link_description.full)
:wikitext(l[1] .. link_description.link .. l[2])
:tag(is_mini and 'abbr' or 'span')
:attr('title', link_description.html_title)
:cssText(font_style)
:wikitext(is_mini and link_description.mini or link_description.full)
:done()
:wikitext(l[3])
:done()
end
local function make_list(title_text, has_brackets, displayed_links, is_mini, font_style)
local title = mw.title.new(mw.text.trim(title_text), cfg.title_namespace)
if not title then
error(cfg.invalid_title .. title_text)
end
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
-- TODO: Obtém link_descriptions e mostra no módulo de configuração.
-- link_descriptions deve ser mais fácil...
local link_descriptions = {
{ ['mini'] = 'v', ['full'] = 'ver', ['html_title'] = 'Ver esta predefinição',
['link'] = title.fullText, ['url'] = false },
{ ['mini'] = 'd', ['full'] = 'discutir', ['html_title'] = 'Discutir esta predefinição',
['link'] = talkpage, ['url'] = false },
{ ['mini'] = 'e', ['full'] = 'editar', ['html_title'] = 'Editar esta predefinição',
['link'] = 'Special:EditPage/' .. title.fullText, ['url'] = false },
{ ['mini'] = 'h', ['full'] = 'histórico', ['html_title'] = 'Histórico desta predefinição',
['link'] = 'Special:PageHistory/' .. title.fullText, ['url'] = false },
{ ['mini'] = 'm', ['full'] = 'mover', ['html_title'] = 'Mover esta predefinição',
['link'] = mw.title.new('Special:Movepage'):fullUrl('target='..title.fullText), ['url'] = true },
{ ['mini'] = 'vi', ['full'] = 'vigiar', ['html_title'] = 'Vigiar esta predefinição',
['link'] = title:fullUrl('action=watch'), ['url'] = true }
}
local ul = mw.html.create('ul')
if has_brackets then
ul:addClass(cfg.classes.brackets)
:cssText(font_style)
end
for i, _ in ipairs(displayed_links) do
if displayed_links[i] then add_link(link_descriptions[i], ul, is_mini, font_style) end
end
return ul:done()
end
function p._navbar(args)
-- TODO: Nós provavelmente não precisamos de ambos, fontstyle e fontcolor...
if args['fonteestilo'] and not args.fontstyle then args.fontstyle = args['fonteestilo'] end
local font_style = args.fontstyle
if args['fontecor'] and not args.fontcolor then args.fontcolor = args['fontecor'] end
local font_color = args.fontcolor
if args['flexível'] and not args.collapsible then args.collapsible = args['flexível'] end
local is_collapsible = args.collapsible
local is_mini = args.mini
if args.simples and not args.plain then args.plain = args.simples end
local is_plain = args.plain
local collapsible_class = nil
if is_collapsible then
collapsible_class = cfg.classes.collapsible
if not is_plain then is_mini = 1 end
if font_color then
font_style = (font_style or '') .. '; color: ' .. font_color .. ';'
end
end
if args.estilo and not args.style then args.style = args.estilo end
local navbar_style = args.style
local div = mw.html.create():tag('div')
div
:addClass(cfg.classes.navbar)
:addClass(cfg.classes.plainlinks)
:addClass(cfg.classes.horizontal_list)
:addClass(collapsible_class) -- nós fizemos a determinação antes
:cssText(navbar_style)
if is_mini then div:addClass(cfg.classes.mini) end
if args.texto and not args.text then args.text = args.texto end
local box_text = (args.text or cfg.box_text) .. ' '
-- o espaço concatenado garante que o texto da caixa seja separado
if not (is_mini or is_plain) then
div
:tag('span')
:addClass(cfg.classes.box_text)
:cssText(font_style)
:wikitext(box_text)
end
if args['predefinição'] and not args.template then args.template = args['predefinição'] end
local template = args.template
local displayed_links = choose_links(template, args)
if (args['parênteses retos'] or args['colchetes']) and not args.brackets then args.brackets = (args['parênteses retos'] or args['colchetes']) end
local has_brackets = args.brackets
local title_arg = get_title_arg(is_collapsible, template)
local title_text = args[title_arg]or (':' .. mw.getCurrentFrame():getParent():getTitle())
local list = make_list(title_text, has_brackets, displayed_links, is_mini, font_style)
div:node(list)
if is_collapsible then
local title_text_class
if is_mini then
title_text_class = cfg.classes.collapsible_title_mini
else
title_text_class = cfg.classes.collapsible_title_full
end
div:done()
:tag('div')
:addClass(title_text_class)
:cssText(font_style)
:wikitext(args[1])
end
local frame = mw.getCurrentFrame()
-- hlist -> navbar é o melhor esforço para preservar a antiga ordenação do Common.css.
return frame:extensionTag{
name = 'templatestyles', args = { src = cfg.hlist_templatestyles }
} .. frame:extensionTag{
name = 'templatestyles', args = { src = cfg.templatestyles }
} .. tostring(div:done())
end
function p.navbar(frame)
return p._navbar(require('Módulo:Arguments').getArgs(frame))
end
return p