Ugrás a tartalomhoz

„Modul:Navbar” változatai közötti eltérés

Innen: TrashWiki
Per edit request on talk
 
require('strict')
1. sor: 1. sor:
require('strict')
local p = {}
local p = {}
local cfg = mw.loadData('Module:Navbar/configuration')


local function get_title_arg(is_collapsible, template)
local i18n = {
local title_arg = 1
mini = {'m', 'v', 'sz'},
if is_collapsible then title_arg = 2 end
plain = {'megtekintés', 'vita', 'szerkesztés'},
if template then title_arg = 'template' end
normal = {'megnézi', 'vitatja', 'szerkeszti'}, -- a sablont
return title_arg
title = {'Mutasd ezt a sablont', 'A sablon vitalapja', 'A sablon szerkesztése'}
end
}
 
local getArgs


local function choose_links(template, args)
function p._navbar(args)
-- The show table indicates the default displayed items.
local titleText = args[1] or (':' .. mw.getCurrentFrame():getParent():getTitle())
-- view, talk, edit, hist, move, watch
local title = mw.title.new(mw.text.trim(titleText), 'Sablon');
-- TODO: Move to configuration.
if not title then
local show = {true, true, true, false, false, false}
error(string.format('Érvénytelen név: „%s”', titleText))
if template then
show[2] = false
show[3] = false
local 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)) do
local num = index[v]
if num then show[num] = true end
end
end
end


local remove_edit_link = args.noedit
local talkpage = title.talkPageTitle and title.talkPageTitle:fullUrl() or nil;
if remove_edit_link then show[3] = false end
local fontstyle = args['betűstílus'] or args.fontstyle
local style = args['stílus'] or args.style
return show
local text
if args.mini then
end
text = i18n.mini
 
elseif args.plain then
local function add_link(link_description, ul, is_mini, font_style)
text = i18n.plain
local l
if link_description.url then
l = {'[', '', ']'}
else
else
l = {'[[', '|', ']]'}
text = i18n.normal
end
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 div = mw.html.create():tag('div')
div
local title = mw.title.new(mw.text.trim(title_text), cfg.title_namespace)
:addClass('navbar')
if not title then
:addClass('noprint')
error(cfg.invalid_title .. title_text)
:addClass('hlist')
end
:addClass('plainlinks')
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
-- <ul> gets out if <span>, so we have to work it around
:css('display', args.nodiv and 'inline')
-- TODO: Get link_descriptions and show into the configuration module.
:cssText(fontstyle)
-- link_descriptions should be easier...
:css('font-size', 'xx-small')
local link_descriptions = {
:cssText(style)
{ ['mini'] = 'v', ['full'] = 'view', ['html_title'] = 'View this template',
 
['link'] = title.fullText, ['url'] = false },
if args.mini then div:addClass('mini') end
{ ['mini'] = 't', ['full'] = 'talk', ['html_title'] = 'Discuss this template',
['link'] = talkpage, ['url'] = false },
{ ['mini'] = 'e', ['full'] = 'edit', ['html_title'] = 'Edit this template',
['link'] = 'Special:EditPage/' .. title.fullText, ['url'] = false },
{ ['mini'] = 'h', ['full'] = 'hist', ['html_title'] = 'History of this template',
['link'] = 'Special:PageHistory/' .. title.fullText, ['url'] = false },
{ ['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')
div:wikitext(mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'hlist/styles.css'}))
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)
-- Internal link for Special:WhatLinksHere
-- TODO: We probably don't need both fontstyle and fontcolor...
local font_style = args.fontstyle
local font_color = args.fontcolor
local is_collapsible = args.collapsible
local is_mini = args.mini
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
local navbar_style = args.style
local div = mw.html.create():tag('div')
div
div
:addClass(cfg.classes.navbar)
:tag('span')
:addClass(cfg.classes.plainlinks)
:css('display', 'none')
:addClass(cfg.classes.horizontal_list)
:wikitext(string.format('[[%s]]', title.fullText))
:addClass(collapsible_class) -- we made the determination earlier
:cssText(navbar_style)


if is_mini then div:addClass(cfg.classes.mini) end
local ul = div:tag('ul');


local box_text = (args.text or cfg.box_text) .. ' '
ul
-- the concatenated space guarantees the box text is separated
:css('display', 'inline')
if not (is_mini or is_plain) then
:tag('li')
:addClass('nv-view')
:wikitext('[' .. title:fullUrl() .. ' ')
:tag('span')
:attr('title', i18n.title[1])
:cssText(fontstyle)
:wikitext(text[1])
:done()
:wikitext(']')
:done()
:wikitext(' ')
:tag('li')
:addClass('nv-talk')
:wikitext(talkpage and '[' .. talkpage .. ' ')
:tag('span')
:attr('title', i18n.title[2])
:cssText(fontstyle)
:wikitext(text[2])
:done()
:wikitext(talkpage and ']')
:done()
:wikitext(' ')
:tag('li')
:addClass('nv-edit')
:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
:tag('span')
:attr('title', i18n.title[3])
:cssText(fontstyle)
:wikitext(text[3])
:done()
:wikitext(']');
 
if not (args.mini or args.plain) then
div
div
:tag('span')
:tag('span')
:addClass(cfg.classes.box_text)
:css('word-spacing', 0)
:cssText(font_style)
:cssText(fontstyle)
:wikitext(box_text)
:wikitext(' a sablont');
end
end
local template = args.template
local displayed_links = choose_links(template, args)
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
return tostring(div:done())
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 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())
end
end


function p.navbar(frame)
function p.navbar(frame)
return p._navbar(require('Module:Arguments').getArgs(frame))
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
return p._navbar(getArgs(frame))
end
end


return p
return p

A lap 2023. november 29., 17:27-kori változata

This is a Lua implementation of {{Navbar}}. It is used in Module:Navbox.


require('strict')
local p = {}

local i18n = {
	mini	= {'m', 'v', 'sz'},
	plain	= {'megtekintés', 'vita', 'szerkesztés'},
	normal	= {'megnézi', 'vitatja', 'szerkeszti'}, -- a sablont
	title	= {'Mutasd ezt a sablont', 'A sablon vitalapja', 'A sablon szerkesztése'}
}

local getArgs

function p._navbar(args)
	local titleText = args[1] or (':' .. mw.getCurrentFrame():getParent():getTitle())
	local title = mw.title.new(mw.text.trim(titleText), 'Sablon');
	if not title then
		error(string.format('Érvénytelen név: „%s”', titleText))
	end

	local talkpage = title.talkPageTitle and title.talkPageTitle:fullUrl() or nil;
	local fontstyle = args['betűstílus'] or args.fontstyle
	local style = args['stílus'] or args.style
	local text
	if args.mini then
		text = i18n.mini
	elseif args.plain then
		text = i18n.plain
	else
		text = i18n.normal
	end

	local div = mw.html.create():tag('div')
	div
		:addClass('navbar')
		:addClass('noprint')
		:addClass('hlist')
		:addClass('plainlinks')
		-- <ul> gets out if <span>, so we have to work it around
		:css('display', args.nodiv and 'inline')
		:cssText(fontstyle)
		:css('font-size', 'xx-small')
		:cssText(style)

	if args.mini then div:addClass('mini') end

	div:wikitext(mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'hlist/styles.css'}))

	-- Internal link for Special:WhatLinksHere
	div
		:tag('span')
		:css('display', 'none')
		:wikitext(string.format('[[%s]]', title.fullText))

	local ul = div:tag('ul');

	ul
		:css('display', 'inline')
		:tag('li')
			:addClass('nv-view')
			:wikitext('[' .. title:fullUrl() .. ' ')
			:tag('span')
				:attr('title', i18n.title[1])
				:cssText(fontstyle)
				:wikitext(text[1])
				:done()
			:wikitext(']')
			:done()
		:wikitext(' ')
		:tag('li')
			:addClass('nv-talk')
			:wikitext(talkpage and '[' .. talkpage .. ' ')
			:tag('span')
				:attr('title', i18n.title[2])
				:cssText(fontstyle)
				:wikitext(text[2])
				:done()
			:wikitext(talkpage and ']')
			:done()
		:wikitext(' ')
		:tag('li')
			:addClass('nv-edit')
			:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
			:tag('span')
				:attr('title', i18n.title[3])
				:cssText(fontstyle)
				:wikitext(text[3])
				:done()
			:wikitext(']');

	if not (args.mini or args.plain) then
		div
			:tag('span')
				:css('word-spacing', 0)
				:cssText(fontstyle)
				:wikitext(' a sablont');
	end

	return tostring(div:done())
end

function p.navbar(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	return p._navbar(getArgs(frame))
end

return p