https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ASidebar%2Fsandbox2
Module:Sidebar/sandbox2 - Revision history
2025-05-31T23:43:12Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.3
https://en.wikipedia.org/w/index.php?title=Module:Sidebar/sandbox2&diff=1276185774&oldid=prev
Vestrian24Bio: navbar style
2025-02-17T11:06:55Z
<p>navbar style</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:06, 17 February 2025</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 318:</td>
<td colspan="2" class="diff-lineno">Line 318:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> args.name,</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> args.name,</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> plain = 1,</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> plain = 1,</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> style = "float:center",</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> fontstyle = args.navbarfontstyle</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> fontstyle = args.navbarfontstyle</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> })</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> })</div></td>
</tr>
</table>
Vestrian24Bio
https://en.wikipedia.org/w/index.php?title=Module:Sidebar/sandbox2&diff=1276185225&oldid=prev
Vestrian24Bio: new
2025-02-17T11:00:21Z
<p>new</p>
<p><b>New page</b></p><div>require('strict')<br />
local cfg = mw.loadData('Module:Sidebar/configuration')<br />
<br />
local p = {}<br />
<br />
local getArgs = require('Module:Arguments').getArgs<br />
<br />
--[[<br />
Categorizes calling templates and modules with a 'style' parameter of any sort<br />
for tracking to convert to TemplateStyles.<br />
<br />
TODO after a long cleanup: Catch sidebars in other namespaces than Template and Module.<br />
TODO would probably want to remove /log and /archive as CS1 does<br />
]]<br />
local function categorizeTemplatesWithInlineStyles(args)<br />
local title = mw.title.getCurrentTitle()<br />
if title.namespace ~= 10 and title.namespace ~= 828 then return '' end<br />
for _, pattern in ipairs (cfg.i18n.pattern.uncategorized_conversion_titles) do<br />
if title.text:match(pattern) then return '' end<br />
end<br />
<br />
for key, _ in pairs(args) do<br />
if mw.ustring.find(key, cfg.i18n.pattern.style_conversion) or key == 'width' then<br />
return cfg.i18n.category.conversion<br />
end<br />
end<br />
end<br />
<br />
--[[<br />
For compatibility with the original {{sidebar with collapsible lists}}<br />
implementation, which passed some parameters through {{#if}} to trim their<br />
whitespace. This also triggered the automatic newline behavior.<br />
]]<br />
-- See ([[meta:Help:Newlines and spaces#Automatic newline]])<br />
local function trimAndAddAutomaticNewline(s)<br />
s = mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1")<br />
if mw.ustring.find(s, '^[#*:;]') or mw.ustring.find(s, '^{|') then<br />
return '\n' .. s<br />
else<br />
return s<br />
end<br />
end<br />
<br />
--[[<br />
Finds whether a sidebar has a subgroup sidebar.<br />
]]<br />
local function hasSubgroup(s)<br />
if mw.ustring.find(s, cfg.i18n.pattern.subgroup) then<br />
return true<br />
else<br />
return false<br />
end<br />
end<br />
<br />
local function has_navbar(navbar_mode, sidebar_name)<br />
return navbar_mode ~= cfg.i18n.navbar_none and<br />
navbar_mode ~= cfg.i18n.navbar_off and<br />
(<br />
sidebar_name or<br />
mw.getCurrentFrame():getParent():getTitle():gsub(cfg.i18n.pattern.sandbox, '') ~=<br />
cfg.i18n.title_not_to_add_navbar<br />
)<br />
end<br />
<br />
local function has_list_class(args, htmlclass)<br />
local patterns = {<br />
'^' .. htmlclass .. '$',<br />
'%s' .. htmlclass .. '$',<br />
'^' .. htmlclass .. '%s',<br />
'%s' .. htmlclass .. '%s'<br />
}<br />
<br />
for arg, value in pairs(args) do<br />
if type(arg) == 'string' and mw.ustring.find(arg, 'class') then<br />
for _, pattern in ipairs(patterns) do<br />
if mw.ustring.find(args[arg] or '', pattern) then<br />
return true<br />
end<br />
end<br />
end<br />
end<br />
return false<br />
end<br />
<br />
-- there are a lot of list classes in the wild, so we add their TemplateStyles<br />
local function add_list_styles(args)<br />
local frame = mw.getCurrentFrame()<br />
local function add_list_templatestyles(htmlclass, templatestyles)<br />
if has_list_class(args, htmlclass) then<br />
return frame:extensionTag{<br />
name = 'templatestyles', args = { src = templatestyles }<br />
}<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
local plainlist_styles = add_list_templatestyles('plainlist', cfg.i18n.plainlist_templatestyles)<br />
local hlist_styles = add_list_templatestyles('hlist', cfg.i18n.hlist_templatestyles)<br />
<br />
-- a second workaround for [[phab:T303378]]<br />
-- when that issue is fixed, we can actually use has_navbar not to emit the<br />
-- tag here if we want<br />
if has_navbar(args.navbar, args.name) and hlist_styles == '' then<br />
hlist_styles = frame:extensionTag{<br />
name = 'templatestyles', args = { src = cfg.i18n.hlist_templatestyles}<br />
}<br />
end<br />
<br />
-- hlist -> plainlist is best-effort to preserve old Common.css ordering. [hlist_note]<br />
return hlist_styles .. plainlist_styles<br />
end<br />
<br />
-- work around [[phab:T303378]]<br />
-- for each arg: find all the templatestyles strip markers, insert them into a<br />
-- table. then remove all templatestyles markers from the arg<br />
local function move_hiding_templatestyles(args)<br />
local gfind = string.gfind<br />
local gsub = string.gsub<br />
local templatestyles_markers = {}<br />
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)'<br />
for k, arg in pairs(args) do<br />
for marker in gfind(arg, strip_marker_pattern) do<br />
table.insert(templatestyles_markers, marker)<br />
end<br />
args[k] = gsub(arg, strip_marker_pattern, '')<br />
end<br />
return templatestyles_markers<br />
end<br />
<br />
--[[<br />
Main sidebar function. Takes the frame, args, and an optional collapsibleClass.<br />
The collapsibleClass is and should be used only for sidebars with collapsible<br />
lists, as in p.collapsible.<br />
]]<br />
function p.sidebar(frame, args, collapsibleClass)<br />
if not args then<br />
args = getArgs(frame)<br />
end<br />
local hiding_templatestyles = table.concat(move_hiding_templatestyles(args))<br />
local root = mw.html.create()<br />
local child = args.child and mw.text.trim(args.child) == cfg.i18n.child_yes<br />
<br />
root = root:tag('table')<br />
if not child then<br />
root <br />
:addClass(cfg.i18n.class.sidebar)<br />
-- force collapsibleclass to be sidebar-collapse otherwise output nothing<br />
:addClass(collapsibleClass == cfg.i18n.class.collapse and cfg.i18n.class.collapse or nil)<br />
:addClass('nomobile')<br />
:addClass(args.float == cfg.i18n.float_none and cfg.i18n.class.float_none or nil)<br />
:addClass(args.float == cfg.i18n.float_left and cfg.i18n.class.float_left or nil)<br />
:addClass(args.wraplinks ~= cfg.i18n.wrap_true and cfg.i18n.class.wraplinks or nil)<br />
:addClass(args.bodyclass or args.class)<br />
:css('width', args.width or nil)<br />
:cssText(args.bodystyle or args.style)<br />
<br />
if args.outertitle then<br />
root<br />
:tag('caption')<br />
:addClass(cfg.i18n.class.outer_title)<br />
:addClass(args.outertitleclass)<br />
:cssText(args.outertitlestyle)<br />
:wikitext(args.outertitle)<br />
end<br />
<br />
if args.topimage then<br />
local imageCell = root:tag('tr'):tag('td')<br />
<br />
imageCell<br />
:addClass(cfg.i18n.class.top_image)<br />
:addClass(args.topimageclass)<br />
:cssText(args.topimagestyle)<br />
:wikitext(args.topimage)<br />
<br />
if args.topcaption then<br />
imageCell<br />
:tag('div')<br />
:addClass(cfg.i18n.class.top_caption)<br />
:cssText(args.topcaptionstyle)<br />
:wikitext(args.topcaption)<br />
end<br />
end<br />
<br />
if args.pretitle then<br />
root<br />
:tag('tr')<br />
:tag('td')<br />
:addClass(args.topimage and cfg.i18n.class.pretitle_with_top_image<br />
or cfg.i18n.class.pretitle)<br />
:addClass(args.pretitleclass)<br />
:cssText(args.basestyle)<br />
:cssText(args.pretitlestyle)<br />
:wikitext(args.pretitle)<br />
end<br />
else<br />
root<br />
:addClass(cfg.i18n.class.subgroup)<br />
:addClass(args.bodyclass or args.class)<br />
:cssText(args.bodystyle or args.style)<br />
end<br />
<br />
if args.title then<br />
if child then<br />
root<br />
:wikitext(args.title)<br />
else<br />
root<br />
:tag('tr')<br />
:tag('th')<br />
:addClass(args.pretitle and cfg.i18n.class.title_with_pretitle<br />
or cfg.i18n.class.title)<br />
:addClass(args.titleclass)<br />
:cssText(args.basestyle)<br />
:cssText(args.titlestyle)<br />
:wikitext(args.title)<br />
end<br />
end<br />
<br />
if args.image then<br />
local imageCell = root:tag('tr'):tag('td')<br />
<br />
imageCell<br />
:addClass(cfg.i18n.class.image)<br />
:addClass(args.imageclass)<br />
:cssText(args.imagestyle)<br />
:wikitext(args.image)<br />
<br />
if args.caption then<br />
imageCell<br />
:tag('div')<br />
:addClass(cfg.i18n.class.caption)<br />
:cssText(args.captionstyle)<br />
:wikitext(args.caption)<br />
end<br />
end<br />
<br />
if args.above then<br />
root<br />
:tag('tr')<br />
:tag('td')<br />
:addClass(cfg.i18n.class.above)<br />
:addClass(args.aboveclass)<br />
:cssText(args.abovestyle)<br />
:newline() -- newline required for bullet-points to work<br />
:wikitext(args.above)<br />
end<br />
<br />
local rowNums = {}<br />
for k, v in pairs(args) do<br />
k = '' .. k<br />
local num = k:match('^heading(%d+)$') or k:match('^content(%d+)$')<br />
if num then table.insert(rowNums, tonumber(num)) end<br />
end<br />
table.sort(rowNums)<br />
-- remove duplicates from the list (e.g. 3 will be duplicated if both heading3<br />
-- and content3 are specified)<br />
for i = #rowNums, 1, -1 do<br />
if rowNums[i] == rowNums[i - 1] then<br />
table.remove(rowNums, i)<br />
end<br />
end<br />
<br />
for i, num in ipairs(rowNums) do<br />
local heading = args['heading' .. num]<br />
if heading then<br />
root<br />
:tag('tr')<br />
:tag('th')<br />
:addClass(cfg.i18n.class.heading)<br />
:addClass(args.headingclass)<br />
:addClass(args['heading' .. num .. 'class'])<br />
:cssText(args.basestyle)<br />
:cssText(args.headingstyle)<br />
:cssText(args['heading' .. num .. 'style'])<br />
:newline()<br />
:wikitext(heading)<br />
end<br />
<br />
local content = args['content' .. num]<br />
if content then<br />
root<br />
:tag('tr')<br />
:tag('td')<br />
:addClass(hasSubgroup(content) and cfg.i18n.class.content_with_subgroup<br />
or cfg.i18n.class.content)<br />
:addClass(args.contentclass)<br />
:addClass(args['content' .. num .. 'class'])<br />
:cssText(args.contentstyle)<br />
:cssText(args['content' .. num .. 'style'])<br />
:newline()<br />
:wikitext(content)<br />
:done()<br />
-- Without a linebreak after the </td>, a nested list like<br />
-- "* {{hlist| ...}}" doesn't parse correctly.<br />
:newline()<br />
end<br />
end<br />
<br />
if args.below then<br />
root<br />
:tag('tr')<br />
:tag('td')<br />
:addClass(cfg.i18n.class.below)<br />
:addClass(args.belowclass)<br />
:cssText(args.belowstyle)<br />
:newline()<br />
:wikitext(args.below)<br />
end<br />
<br />
if not child and has_navbar(args.navbar, args.name) then<br />
root<br />
:tag('tr')<br />
:tag('td')<br />
:addClass(cfg.i18n.class.navbar)<br />
:cssText(args.navbarstyle)<br />
:wikitext(require('Module:Navbar')._navbar{<br />
args.name,<br />
plain = 1,<br />
fontstyle = args.navbarfontstyle<br />
})<br />
end<br />
<br />
local base_templatestyles = frame:extensionTag{<br />
name = 'templatestyles', args = { src = cfg.i18n.templatestyles }<br />
}<br />
<br />
local templatestyles = ''<br />
if args['templatestyles'] and args['templatestyles'] ~= '' then<br />
templatestyles = frame:extensionTag{<br />
name = 'templatestyles', args = { src = args['templatestyles'] }<br />
}<br />
end<br />
<br />
local child_templatestyles = ''<br />
if args['child templatestyles'] and args['child templatestyles'] ~= '' then<br />
child_templatestyles = frame:extensionTag{<br />
name = 'templatestyles', args = { src = args['child templatestyles'] }<br />
}<br />
end<br />
<br />
local grandchild_templatestyles = ''<br />
if args['grandchild templatestyles'] and args['grandchild templatestyles'] ~= '' then<br />
grandchild_templatestyles = frame:extensionTag{<br />
name = 'templatestyles', args = { src = args['grandchild templatestyles'] }<br />
}<br />
end<br />
<br />
return table.concat({<br />
add_list_styles(args), -- see [hlist_note] above about ordering<br />
base_templatestyles,<br />
templatestyles,<br />
child_templatestyles,<br />
grandchild_templatestyles,<br />
hiding_templatestyles,<br />
tostring(root),<br />
(child and cfg.i18n.category.child or ''),<br />
categorizeTemplatesWithInlineStyles(args)<br />
})<br />
end<br />
<br />
local function list_title(args, is_centered_list_titles, num)<br />
<br />
local title_text = trimAndAddAutomaticNewline(args['list' .. num .. 'title']<br />
or cfg.i18n.default_list_title)<br />
<br />
local title<br />
if is_centered_list_titles then<br />
-- collapsible can be finicky, so provide some CSS/HTML to support<br />
title = mw.html.create('div')<br />
:addClass(cfg.i18n.class.list_title_centered)<br />
:wikitext(title_text)<br />
else<br />
title = mw.html.create()<br />
:wikitext(title_text)<br />
end<br />
<br />
local title_container = mw.html.create('div')<br />
:addClass(cfg.i18n.class.list_title)<br />
-- don't /need/ a listnumtitleclass because you can do<br />
-- .templateclass .listnumclass .sidebar-list-title<br />
:addClass(args.listtitleclass)<br />
:cssText(args.basestyle)<br />
:cssText(args.listtitlestyle)<br />
:cssText('color: var(--color-base)')<br />
:cssText(args['list' .. num .. 'titlestyle'])<br />
:node(title)<br />
:done()<br />
<br />
return title_container<br />
end<br />
<br />
--[[<br />
Main entry point for sidebar with collapsible lists.<br />
Does the work of creating the collapsible lists themselves and including them<br />
into the args.<br />
]]<br />
function p.collapsible(frame)<br />
local args = getArgs(frame)<br />
if not args.name and<br />
frame:getParent():getTitle():gsub(cfg.i18n.pattern.collapse_sandbox, '') ==<br />
cfg.i18n.collapse_title_not_to_add_navbar then<br />
args.navbar = cfg.i18n.navbar_none<br />
end<br />
<br />
local contentArgs = {}<br />
<br />
local is_centered_list_titles = false<br />
if args['centered list titles'] and args['centered list titles'] ~= '' then<br />
is_centered_list_titles = true<br />
end<br />
<br />
for k, v in pairs(args) do<br />
local num = string.match(k, '^list(%d+)$')<br />
if num then<br />
local expand = args.expanded and<br />
(args.expanded == 'all' or args.expanded == args['list' .. num .. 'name'])<br />
local row = mw.html.create('div')<br />
row<br />
:addClass(cfg.i18n.class.list)<br />
:addClass('mw-collapsible')<br />
:addClass((not expand) and 'mw-collapsed' or nil)<br />
:addClass(args['list' .. num .. 'class'])<br />
:cssText(args.listframestyle)<br />
:cssText(args['list' .. num .. 'framestyle'])<br />
:node(list_title(args, is_centered_list_titles, num))<br />
:tag('div')<br />
:addClass(cfg.i18n.class.list_content)<br />
:addClass('mw-collapsible-content')<br />
-- don't /need/ a listnumstyleclass because you can do<br />
-- .templatename .listnumclass .sidebar-list<br />
:addClass(args.listclass)<br />
:cssText(args.liststyle)<br />
:cssText(args['list' .. num .. 'style'])<br />
:wikitext(trimAndAddAutomaticNewline(args['list' .. num]))<br />
<br />
contentArgs['content' .. num] = tostring(row)<br />
end<br />
end<br />
<br />
for k, v in pairs(contentArgs) do<br />
args[k] = v<br />
end<br />
<br />
return p.sidebar(frame, args, cfg.i18n.class.collapse)<br />
end<br />
<br />
return p</div>
Vestrian24Bio