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(&#039;strict&#039;)<br /> local cfg = mw.loadData(&#039;Module:Sidebar/configuration&#039;)<br /> <br /> local p = {}<br /> <br /> local getArgs = require(&#039;Module:Arguments&#039;).getArgs<br /> <br /> --[[<br /> Categorizes calling templates and modules with a &#039;style&#039; 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 &#039;&#039; end<br /> for _, pattern in ipairs (cfg.i18n.pattern.uncategorized_conversion_titles) do<br /> if title.text:match(pattern) then return &#039;&#039; end<br /> end<br /> <br /> for key, _ in pairs(args) do<br /> if mw.ustring.find(key, cfg.i18n.pattern.style_conversion) or key == &#039;width&#039; 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, &quot;^%s*(.-)%s*$&quot;, &quot;%1&quot;)<br /> if mw.ustring.find(s, &#039;^[#*:;]&#039;) or mw.ustring.find(s, &#039;^{|&#039;) then<br /> return &#039;\n&#039; .. 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, &#039;&#039;) ~=<br /> cfg.i18n.title_not_to_add_navbar<br /> )<br /> end<br /> <br /> local function has_list_class(args, htmlclass)<br /> local patterns = {<br /> &#039;^&#039; .. htmlclass .. &#039;$&#039;,<br /> &#039;%s&#039; .. htmlclass .. &#039;$&#039;,<br /> &#039;^&#039; .. htmlclass .. &#039;%s&#039;,<br /> &#039;%s&#039; .. htmlclass .. &#039;%s&#039;<br /> }<br /> <br /> for arg, value in pairs(args) do<br /> if type(arg) == &#039;string&#039; and mw.ustring.find(arg, &#039;class&#039;) then<br /> for _, pattern in ipairs(patterns) do<br /> if mw.ustring.find(args[arg] or &#039;&#039;, 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 = &#039;templatestyles&#039;, args = { src = templatestyles }<br /> }<br /> else<br /> return &#039;&#039;<br /> end<br /> end<br /> <br /> local plainlist_styles = add_list_templatestyles(&#039;plainlist&#039;, cfg.i18n.plainlist_templatestyles)<br /> local hlist_styles = add_list_templatestyles(&#039;hlist&#039;, 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 == &#039;&#039; then<br /> hlist_styles = frame:extensionTag{<br /> name = &#039;templatestyles&#039;, args = { src = cfg.i18n.hlist_templatestyles}<br /> }<br /> end<br /> <br /> -- hlist -&gt; 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 = &#039;(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)&#039;<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, &#039;&#039;)<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(&#039;table&#039;)<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(&#039;nomobile&#039;)<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(&#039;width&#039;, args.width or nil)<br /> :cssText(args.bodystyle or args.style)<br /> <br /> if args.outertitle then<br /> root<br /> :tag(&#039;caption&#039;)<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(&#039;tr&#039;):tag(&#039;td&#039;)<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(&#039;div&#039;)<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(&#039;tr&#039;)<br /> :tag(&#039;td&#039;)<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(&#039;tr&#039;)<br /> :tag(&#039;th&#039;)<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(&#039;tr&#039;):tag(&#039;td&#039;)<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(&#039;div&#039;)<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(&#039;tr&#039;)<br /> :tag(&#039;td&#039;)<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 = &#039;&#039; .. k<br /> local num = k:match(&#039;^heading(%d+)$&#039;) or k:match(&#039;^content(%d+)$&#039;)<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[&#039;heading&#039; .. num]<br /> if heading then<br /> root<br /> :tag(&#039;tr&#039;)<br /> :tag(&#039;th&#039;)<br /> :addClass(cfg.i18n.class.heading)<br /> :addClass(args.headingclass)<br /> :addClass(args[&#039;heading&#039; .. num .. &#039;class&#039;])<br /> :cssText(args.basestyle)<br /> :cssText(args.headingstyle)<br /> :cssText(args[&#039;heading&#039; .. num .. &#039;style&#039;])<br /> :newline()<br /> :wikitext(heading)<br /> end<br /> <br /> local content = args[&#039;content&#039; .. num]<br /> if content then<br /> root<br /> :tag(&#039;tr&#039;)<br /> :tag(&#039;td&#039;)<br /> :addClass(hasSubgroup(content) and cfg.i18n.class.content_with_subgroup<br /> or cfg.i18n.class.content)<br /> :addClass(args.contentclass)<br /> :addClass(args[&#039;content&#039; .. num .. &#039;class&#039;])<br /> :cssText(args.contentstyle)<br /> :cssText(args[&#039;content&#039; .. num .. &#039;style&#039;])<br /> :newline()<br /> :wikitext(content)<br /> :done()<br /> -- Without a linebreak after the &lt;/td&gt;, a nested list like<br /> -- &quot;* {{hlist| ...}}&quot; doesn&#039;t parse correctly.<br /> :newline()<br /> end<br /> end<br /> <br /> if args.below then<br /> root<br /> :tag(&#039;tr&#039;)<br /> :tag(&#039;td&#039;)<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(&#039;tr&#039;)<br /> :tag(&#039;td&#039;)<br /> :addClass(cfg.i18n.class.navbar)<br /> :cssText(args.navbarstyle)<br /> :wikitext(require(&#039;Module:Navbar&#039;)._navbar{<br /> args.name,<br /> plain = 1,<br /> fontstyle = args.navbarfontstyle<br /> })<br /> end<br /> <br /> local base_templatestyles = frame:extensionTag{<br /> name = &#039;templatestyles&#039;, args = { src = cfg.i18n.templatestyles }<br /> }<br /> <br /> local templatestyles = &#039;&#039;<br /> if args[&#039;templatestyles&#039;] and args[&#039;templatestyles&#039;] ~= &#039;&#039; then<br /> templatestyles = frame:extensionTag{<br /> name = &#039;templatestyles&#039;, args = { src = args[&#039;templatestyles&#039;] }<br /> }<br /> end<br /> <br /> local child_templatestyles = &#039;&#039;<br /> if args[&#039;child templatestyles&#039;] and args[&#039;child templatestyles&#039;] ~= &#039;&#039; then<br /> child_templatestyles = frame:extensionTag{<br /> name = &#039;templatestyles&#039;, args = { src = args[&#039;child templatestyles&#039;] }<br /> }<br /> end<br /> <br /> local grandchild_templatestyles = &#039;&#039;<br /> if args[&#039;grandchild templatestyles&#039;] and args[&#039;grandchild templatestyles&#039;] ~= &#039;&#039; then<br /> grandchild_templatestyles = frame:extensionTag{<br /> name = &#039;templatestyles&#039;, args = { src = args[&#039;grandchild templatestyles&#039;] }<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 &#039;&#039;),<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[&#039;list&#039; .. num .. &#039;title&#039;]<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(&#039;div&#039;)<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(&#039;div&#039;)<br /> :addClass(cfg.i18n.class.list_title)<br /> -- don&#039;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(&#039;color: var(--color-base)&#039;)<br /> :cssText(args[&#039;list&#039; .. num .. &#039;titlestyle&#039;])<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, &#039;&#039;) ==<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[&#039;centered list titles&#039;] and args[&#039;centered list titles&#039;] ~= &#039;&#039; then<br /> is_centered_list_titles = true<br /> end<br /> <br /> for k, v in pairs(args) do<br /> local num = string.match(k, &#039;^list(%d+)$&#039;)<br /> if num then<br /> local expand = args.expanded and<br /> (args.expanded == &#039;all&#039; or args.expanded == args[&#039;list&#039; .. num .. &#039;name&#039;])<br /> local row = mw.html.create(&#039;div&#039;)<br /> row<br /> :addClass(cfg.i18n.class.list)<br /> :addClass(&#039;mw-collapsible&#039;)<br /> :addClass((not expand) and &#039;mw-collapsed&#039; or nil)<br /> :addClass(args[&#039;list&#039; .. num .. &#039;class&#039;])<br /> :cssText(args.listframestyle)<br /> :cssText(args[&#039;list&#039; .. num .. &#039;framestyle&#039;])<br /> :node(list_title(args, is_centered_list_titles, num))<br /> :tag(&#039;div&#039;)<br /> :addClass(cfg.i18n.class.list_content)<br /> :addClass(&#039;mw-collapsible-content&#039;)<br /> -- don&#039;t /need/ a listnumstyleclass because you can do<br /> -- .templatename .listnumclass .sidebar-list<br /> :addClass(args.listclass)<br /> :cssText(args.liststyle)<br /> :cssText(args[&#039;list&#039; .. num .. &#039;style&#039;])<br /> :wikitext(trimAndAddAutomaticNewline(args[&#039;list&#039; .. num]))<br /> <br /> contentArgs[&#039;content&#039; .. 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