Editing Module:Sidebar

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
require('strict')
--
-- This module implements {{Sidebar}}
--
require('Module:No globals')
local cfg = mw.loadData('Module:Sidebar/configuration')
local cfg = mw.loadData('Module:Sidebar/configuration')


Line 51: Line 54:
return false
return false
end
end
end
local function has_navbar(navbar_mode, sidebar_name)
return navbar_mode ~= cfg.i18n.navbar_none and
navbar_mode ~= cfg.i18n.navbar_off and
(
sidebar_name or
mw.getCurrentFrame():getParent():getTitle():gsub(cfg.i18n.pattern.sandbox, '') ~=
cfg.i18n.title_not_to_add_navbar
)
end
local function has_list_class(args, htmlclass)
local patterns = {
'^' .. htmlclass .. '$',
'%s' .. htmlclass .. '$',
'^' .. htmlclass .. '%s',
'%s' .. htmlclass .. '%s'
}
for arg, value in pairs(args) do
if type(arg) == 'string' and mw.ustring.find(arg, 'class') then
for _, pattern in ipairs(patterns) do
if mw.ustring.find(args[arg] or '', pattern) then
return true
end
end
end
end
return false
end
-- there are a lot of list classes in the wild, so we add their TemplateStyles
local function add_list_styles(args)
local frame = mw.getCurrentFrame()
local function add_list_templatestyles(htmlclass, templatestyles)
if has_list_class(args, htmlclass) then
return frame:extensionTag{
name = 'templatestyles', args = { src = templatestyles }
}
else
return ''
end
end
local plainlist_styles = add_list_templatestyles('plainlist', cfg.i18n.plainlist_templatestyles)
local hlist_styles = add_list_templatestyles('hlist', cfg.i18n.hlist_templatestyles)
-- a second workaround for [[phab:T303378]]
-- when that issue is fixed, we can actually use has_navbar not to emit the
-- tag here if we want
if has_navbar(args.navbar, args.name) and hlist_styles == '' then
hlist_styles = frame:extensionTag{
name = 'templatestyles', args = { src = cfg.i18n.hlist_templatestyles}
}
end
-- hlist -> plainlist is best-effort to preserve old Common.css ordering. [hlist_note]
return hlist_styles .. plainlist_styles
end
-- work around [[phab:T303378]]
-- for each arg: find all the templatestyles strip markers, insert them into a
-- table. then remove all templatestyles markers from the arg
local function move_hiding_templatestyles(args)
local gfind = string.gfind
local gsub = string.gsub
local templatestyles_markers = {}
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)'
for k, arg in pairs(args) do
for marker in gfind(arg, strip_marker_pattern) do
table.insert(templatestyles_markers, marker)
end
args[k] = gsub(arg, strip_marker_pattern, '')
end
return templatestyles_markers
end
end


Line 138: Line 65:
args = getArgs(frame)
args = getArgs(frame)
end
end
local hiding_templatestyles = table.concat(move_hiding_templatestyles(args))
local root = mw.html.create()
local root = mw.html.create()
local child = args.child and mw.text.trim(args.child) == cfg.i18n.child_yes
local child = args.child and mw.text.trim(args.child) == cfg.i18n.child_yes
Line 309: Line 235:
end
end


if not child and has_navbar(args.navbar, args.name) then
if not child then
root
if args.navbar ~= cfg.i18n.navbar_none and args.navbar ~= cfg.i18n.navbar_off and
:tag('tr')
(args.name or frame:getParent():getTitle():gsub(cfg.i18n.pattern.sandbox, '') ~=
:tag('td')
cfg.i18n.title_not_to_add_navbar) then
:addClass(cfg.i18n.class.navbar)
root
:cssText(args.navbarstyle)
:tag('tr')
:wikitext(require('Module:Navbar')._navbar{
:tag('td')
args.name,
:addClass(cfg.i18n.class.navbar)
mini = 1,
:cssText(args.navbarstyle)
fontstyle = args.navbarfontstyle
:wikitext(require('Module:Navbar')._navbar{
})
args.name,
mini = 1,
fontstyle = args.navbarfontstyle
})
end
end
end
Line 348: Line 278:


return table.concat({
return table.concat({
add_list_styles(args), -- see [hlist_note] above about ordering
base_templatestyles,
base_templatestyles,
templatestyles,
templatestyles,
child_templatestyles,
child_templatestyles,
grandchild_templatestyles,
grandchild_templatestyles,
hiding_templatestyles,
tostring(root),
tostring(root),
(child and cfg.i18n.category.child or ''),
(child and cfg.i18n.category.child or ''),
Line 405: Line 333:
local contentArgs = {}
local contentArgs = {}
local is_centered_list_titles = false
local is_centered_list_titles
if args['centered list titles'] and args['centered list titles'] ~= '' then
if args['centered list titles'] and args['centered list titles'] ~= '' then
is_centered_list_titles = true
is_centered_list_titles = true
else
is_centered_list_titles = false
end
end


Please note that all contributions to Timeline of History may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Timeline of History:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Template used on this page: