Module:Navbar
This Lua module is used on 2,150,000 pages. To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its /sandbox or /testcases subpages. The tested changes can then be added to this page in one single edit. Please consider discussing any changes on the talk page before implementing them. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This template's documentation is missing or does not accurately describe its functionality or the parameters in its code. Please help improve it. |
This is a Lua implementation of {{navbar}}. It is used in Module:Navbox.
local p = {}local cfg = mw.loadData('Module:Navbar/configuration')local function get_title_arg(is_collapsible, template)local title_arg = 1if is_collapsible then title_arg = 2 endif template then title_arg = 'template' endreturn title_argendlocal function choose_links(template, args)-- The show table indicates the default displayed items.-- view, talk, edit, hist, move, watch-- TODO: Move to configuration.local show = {true, true, true, false, false, false}if template thenshow[2] = falseshow[3] = falselocal index = {t = 2, d = 2, e = 3, h = 4, m = 5, w = 6,talk = 2, edit = 3, hist = 4, move = 5, watch = 6}-- TODO: Consider removing TableTools dependency.for _, v in ipairs(require ('Module:TableTools').compressSparseArray(args)) dolocal num = index[v]if num then show[num] = true endendendlocal remove_edit_link = args.noeditif remove_edit_link then show[3] = false endreturn showendlocal function add_link(link_description, ul, is_mini, font_style)local lif link_description.url thenl = {'[', '', ']'}elsel = {'[[', '|', ']]'}endul: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()endlocal 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 thenerror(cfg.invalid_title .. title_text)endlocal talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''-- TODO: Get link_descriptions and show into the configuration module.-- link_descriptions should be easier...local link_descriptions = {{ ['mini'] = 'v', ['full'] = 'view', ['html_title'] = 'View this template',['link'] = title.fullText, ['url'] = false },{ ['mini'] = 't', ['full'] = 'talk', ['html_title'] = 'Discuss this template',['link'] = talkpage, ['url'] = false },{ ['mini'] = 'e', ['full'] = 'edit', ['html_title'] = 'Edit this template',['link'] = title:fullUrl('action=edit'), ['url'] = true },{ ['mini'] = 'h', ['full'] = 'hist', ['html_title'] = 'History of this template',['link'] = title:fullUrl('action=history'), ['url'] = true },{ ['mini'] = 'm', ['full'] = 'move', ['html_title'] = 'Move this template',['link'] = mw.title.new('Special:Movepage'):fullUrl('target='..title.fullText), ['url'] = true },{ ['mini'] = 'w', ['full'] = 'watch', ['html_title'] = 'Watch this template', ['link'] = title:fullUrl('action=watch'), ['url'] = true }}local ul = mw.html.create('ul')if has_brackets thenul:addClass(cfg.classes.brackets):cssText(font_style)endfor i, _ in ipairs(displayed_links) doif displayed_links[i] then add_link(link_descriptions[i], ul, is_mini, font_style) endendreturn ul:done()endfunction p._navbar(args)-- TODO: We probably don't need both fontstyle and fontcolor...local font_style = args.fontstylelocal font_color = args.fontcolorlocal is_collapsible = args.collapsiblelocal is_mini = args.minilocal is_plain = args.plainlocal collapsible_class = nilif is_collapsible thencollapsible_class = cfg.classes.collapsibleif not is_plain then is_mini = 1 endif font_color thenfont_style = (font_style or '') .. '; color: ' .. font_color .. ';'endendlocal navbar_style = args.stylelocal div = mw.html.create():tag('div')div:addClass(cfg.classes.navbar):addClass(cfg.classes.plainlinks):addClass(cfg.classes.horizontal_list):addClass(collapsible_class) -- we made the determination earlier:cssText(navbar_style)if is_mini then div:addClass(cfg.classes.mini) endlocal box_text = (args.text or cfg.box_text) .. ' ' -- the concatenated space guarantees the box text is separatedif not (is_mini or is_plain) thendiv:tag('span'):addClass(cfg.classes.box_text):cssText(font_style):wikitext(box_text)endlocal template = args.templatelocal displayed_links = choose_links(template, args)local has_brackets = args.bracketslocal 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 thenlocal title_text_classif is_mini thentitle_text_class = cfg.classes.collapsible_title_minielsetitle_text_class = cfg.classes.collapsible_title_fullenddiv:done():tag('div'):addClass(title_text_class):cssText(font_style):wikitext(args[1])endlocal frame = mw.getCurrentFrame()-- hlist -> navbar is best-effort to preserve old Common.css ordering.return frame:extensionTag{name = 'templatestyles', args = { src = cfg.hlist_templatestyles }} .. frame:extensionTag{name = 'templatestyles', args = { src = cfg.templatestyles }} .. tostring(div:done())endfunction p.navbar(frame)return p._navbar(require('Module:Arguments').getArgs(frame))endreturn p
🔥 Top keywords: Pahila PannaRani Kamlapati railway stationChinakhaas:SearchWorld War IIfile:Manchester United FC crest.pngfile:Arsenal FC.pngTanha TasniaRajbangsi bhasaRussiaIndiaJwala mukhifile:Liverpool FC.pngPakistanKundrukhaas:RecentChangesWikipedia:Samaj PortalTanasahiAustraliaSubhas Chandra Bosefile:Tottenham Hotspur.pngAsiaGrahsadasya:EmausBot1974Indus Valley CivilizationMainaMangalgrahModule:NavboxNobel PrizeSaur mandalHanuman ChalisaVaisvikaranItihaassadasya ke baat:GirmityaIsai DharamGenghis KhanHimalayaBhagat Singh