Module:Navbar
Jump to navigation
Jump to search
require('strict')
local p = {}
local navbarText = {
view = 'pogled',
talk = 'besěda',
edit = 'izměniti',
history = 'historija',
purge = 'očistiti',
}
local function addLink(title, link)
local isv_cyrl = require('Module:Alphabet')._global_cyrl
local page = title.fullText
if link == 'talk' then
page = 'Special:NewSection/' .. title.talkPageTitle.fullText
elseif link == 'edit' then
page = 'Special:EditPage/' .. title.fullText
elseif link == 'history' then
page = 'Special:PageHistory/' .. title.fullText
elseif link == 'purge' then
page = 'Special:Purge/' .. title.basePageTitle.fullText
end
return string.format('[[%s|%s]]', page, isv_cyrl(navbarText[link]) or '???')
end
function p._navbar(args)
local title = args[1]
local navbar = mw.html.create('span')
:addClass('mw-editsection-like plainlinks')
:addClass(args.class)
local navbarTitle = mw.title.new(title)
if not navbarTitle then
return
end
local linkCount = 0
for _, val in ipairs(args) do
if navbarText[val] then
if linkCount == 0 then
navbar:wikitext('<span class="mw-editsection-bracket">[</span>')
end
if linkCount > 0 then
navbar:wikitext(' | ')
end
navbar:wikitext(addLink(navbarTitle, val))
linkCount = linkCount + 1
end
end
if linkCount > 0 then
navbar:wikitext('<span class="mw-editsection-bracket">]</span>')
return tostring(navbar)
end
return error('No links generated with these parameters for ' .. navbarTitle.fullText)
end
function p.navbar(frame)
return p._navbar(require('Module:Arguments').getArgs(frame))
end
return p