Module:Navbar/sandbox: Difference between revisions

Content deleted Content added
some more refactors
m Removed protection from "Module:Navbar/sandbox"
 
(40 intermediate revisions by 8 users not shown)
Line 9:
end
 
local function choose_links(template, remove_edit_linkargs)
-- The show table indicates the default displayed items.
-- view, talk, edit, hist, move, watch
Line 25:
end
end
 
local remove_edit_link = args.noedit
if remove_edit_link then show[3] = false end
Line 31 ⟶ 33:
end
 
local function addItemadd_link(link_description, ul, is_mini, font_style)
local l
if link_description.url then
Line 48 ⟶ 50:
: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(titleTexttitle_text), cfg.title_namespace)
if not title then
error(cfg.invalid_title .. titleTexttitle_text)
end
local 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'] = mw.title.new('Special:Movepage'):fullUrl('target=EditPage/' .. title.fullText), ['url'] = truefalse },
{ ['mini'] = 'h', ['full'] = 'hist', ['html_title'] = 'History of this template',
['link'] = title'Special:fullUrl(PageHistory/'action=edit') .. title.fullText, ['url'] = truefalse },
{ ['mini'] = 'm', ['full'] = 'move', ['html_title'] = 'Move this template',
['link'] = mw.title.new('Special:Movepage'):fullUrl('actiontarget=history'..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 then
ul:addClass(cfg.classes.brackets)
:cssText(font_style)
end
for i, _ in ipairs(displayed_links) do
if displayed_links[i] then addItemadd_link(link_descriptions[i], ul, is_mini, font_style) end
end
return ul:done()
end
 
Line 90 ⟶ 130:
local template = args.template
local titleArgdisplayed_links = get_title_argchoose_links(is_collapsibletemplate, templateargs)
local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
local title = mw.title.new(mw.text.trim(titleText), cfg.title_namespace)
if not title then
error(cfg.invalid_title .. titleText)
end
local 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 has_brackets = args.brackets
local ultitle_arg = mw.html.createget_title_arg('ul'is_collapsible, template)
local titleTexttitle_text = args[titleArgtitle_arg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
if has_brackets then
local links = ''
ul:addClass(cfg.classes.brackets)
if args.vte_links_override then
:cssText(font_style)
links = args.vte_links_override
end
div:wikitext(links)
 
else
local remove_edit_link = args.noedit
links = make_list(title_text, has_brackets, displayed_links, is_mini, font_style)
local displayed_links = choose_links(template, remove_edit_link)
div:node(ullinks)
end
for i, _ in ipairs(displayed_links) do
if displayed_links[i] then addItem(link_descriptions[i], ul, is_mini, font_style) end
end
ul:done()
div:node(ul)
 
if is_collapsible then
Line 144 ⟶ 156:
:wikitext(args[1])
end
 
local frame = mw.getCurrentFrame()
-- TODO: Support some limited parameters worth of templatestyles so that
-- hlist -> navbar is best-effort to preserve old Common.css ordering.
-- these styles can be easily overridden if desired.
return mw.getCurrentFrame()frame:extensionTag{
name = 'templatestyles', args = { src = cfg.hlist_templatestyles }
} .. frame:extensionTag{
name = 'templatestyles', args = { src = cfg.templatestyles }
} .. tostring(div:done())