This Lua module is used on approximately 155,000+ pages.
To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its /sandbox or /testcases subpages.
The tested changes can then be added to this page in one single edit.
Please consider discussing any changes on the talk page before implementing them.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
---- This module implements {{Sidebar}}--require('Module:No globals')localcfg=mw.loadData('Module:Sidebar/configuration')localp={}localgetArgs=require('Module:Arguments').getArgs--[[Categorizes calling templates and modules with a 'style' parameter of any sortfor tracking to convert to TemplateStyles.TODO after a long cleanup: Catch sidebars in other namespaces than Template and Module.TODO would probably want to remove /log and /archive as CS1 does]]localfunctioncategorizeTemplatesWithInlineStyles(args)localtitle=mw.title.getCurrentTitle()iftitle.namespace~=10andtitle.namespace~=828thenreturn''endfor_,patterninipairs(cfg.i18n.pattern.uncategorized_conversion_titles)doiftitle.text:match(pattern)thenreturn''endendforkey,_inpairs(args)doifmw.ustring.find(key,cfg.i18n.pattern.style_conversion)orkey=='width'thenreturncfg.i18n.category.conversionendendend--[[For compatibility with the original {{sidebar with collapsible lists}}implementation, which passed some parameters through {{#if}} to trim theirwhitespace. This also triggered the automatic newline behavior.]]-- See ([[meta:Help:Newlines and spaces#Automatic newline]])localfunctiontrimAndAddAutomaticNewline(s)s=mw.ustring.gsub(s,"^%s*(.-)%s*$","%1")ifmw.ustring.find(s,'^[#*:;]')ormw.ustring.find(s,'^{|')thenreturn'\n'..selsereturnsendend--[[Finds whether a sidebar has a subgroup sidebar.]]localfunctionhasSubgroup(s)ifmw.ustring.find(s,cfg.i18n.pattern.subgroup)thenreturntrueelsereturnfalseendend--[[Main sidebar function. Takes the frame, args, and an optional collapsibleClass.The collapsibleClass is and should be used only for sidebars with collapsiblelists, as in p.collapsible.]]functionp.sidebar(frame,args,collapsibleClass)ifnotargsthenargs=getArgs(frame)endlocalroot=mw.html.create()localchild=args.childandmw.text.trim(args.child)==cfg.i18n.child_yesroot=root:tag('table')ifnotchildthenroot:addClass(cfg.i18n.class.sidebar)-- force collapsibleclass to be sidebar-collapse otherwise output nothing:addClass(collapsibleClass==cfg.i18n.class.collapseandcfg.i18n.class.collapseornil):addClass('nomobile'):addClass(args.float==cfg.i18n.float_noneandcfg.i18n.class.float_noneornil):addClass(args.float==cfg.i18n.float_leftandcfg.i18n.class.float_leftornil):addClass(args.wraplinks~=cfg.i18n.wrap_trueandcfg.i18n.class.wraplinksornil):addClass(args.bodyclassorargs.class):css('width',args.widthornil):cssText(args.bodystyleorargs.style)ifargs.outertitlethenroot:tag('caption'):addClass(cfg.i18n.class.outer_title):addClass(args.outertitleclass):cssText(args.outertitlestyle):wikitext(args.outertitle)endifargs.topimagethenlocalimageCell=root:tag('tr'):tag('td')imageCell:addClass(cfg.i18n.class.top_image):addClass(args.topimageclass):cssText(args.topimagestyle):wikitext(args.topimage)ifargs.topcaptionthenimageCell:tag('div'):addClass(cfg.i18n.class.top_caption):cssText(args.topcaptionstyle):wikitext(args.topcaption)endendifargs.pretitlethenroot:tag('tr'):tag('td'):addClass(args.topimageandcfg.i18n.class.pretitle_with_top_imageorcfg.i18n.class.pretitle):addClass(args.pretitleclass):cssText(args.basestyle):cssText(args.pretitlestyle):wikitext(args.pretitle)endelseroot:addClass(cfg.i18n.class.subgroup):addClass(args.bodyclassorargs.class):cssText(args.bodystyleorargs.style)endifargs.titlethenifchildthenroot:wikitext(args.title)elseroot:tag('tr'):tag('th'):addClass(args.pretitleandcfg.i18n.class.title_with_pretitleorcfg.i18n.class.title):addClass(args.titleclass):cssText(args.basestyle):cssText(args.titlestyle):wikitext(args.title)endendifargs.imagethenlocalimageCell=root:tag('tr'):tag('td')imageCell:addClass(cfg.i18n.class.image):addClass(args.imageclass):cssText(args.imagestyle):wikitext(args.image)ifargs.captionthenimageCell:tag('div'):addClass(cfg.i18n.class.caption):cssText(args.captionstyle):wikitext(args.caption)endendifargs.abovethenroot:tag('tr'):tag('td'):addClass(cfg.i18n.class.above):addClass(args.aboveclass):cssText(args.abovestyle):newline()-- newline required for bullet-points to work:wikitext(args.above)endlocalrowNums={}fork,vinpairs(args)dok=''..klocalnum=k:match('^heading(%d+)$')ork:match('^content(%d+)$')ifnumthentable.insert(rowNums,tonumber(num))endendtable.sort(rowNums)-- remove duplicates from the list (e.g. 3 will be duplicated if both heading3-- and content3 are specified)fori=#rowNums,1,-1doifrowNums[i]==rowNums[i-1]thentable.remove(rowNums,i)endendfori,numinipairs(rowNums)dolocalheading=args['heading'..num]ifheadingthenroot:tag('tr'):tag('th'):addClass(cfg.i18n.class.heading):addClass(args.headingclass):addClass(args['heading'..num..'class']):cssText(args.basestyle):cssText(args.headingstyle):cssText(args['heading'..num..'style']):newline():wikitext(heading)endlocalcontent=args['content'..num]ifcontentthenroot:tag('tr'):tag('td'):addClass(hasSubgroup(content)andcfg.i18n.class.content_with_subgrouporcfg.i18n.class.content):addClass(args.contentclass):addClass(args['content'..num..'class']):cssText(args.contentstyle):cssText(args['content'..num..'style']):newline():wikitext(content):done()-- Without a linebreak after the </td>, a nested list like-- "* {{hlist| ...}}" doesn't parse correctly.:newline()endendifargs.belowthenroot:tag('tr'):tag('td'):addClass(cfg.i18n.class.below):addClass(args.belowclass):cssText(args.belowstyle):newline():wikitext(args.below)endifnotchildthenifargs.navbar~=cfg.i18n.navbar_noneandargs.navbar~=cfg.i18n.navbar_offand(args.nameorframe:getParent():getTitle():gsub(cfg.i18n.pattern.sandbox,'')~=cfg.i18n.title_not_to_add_navbar)thenroot:tag('tr'):tag('td'):addClass(cfg.i18n.class.navbar):cssText(args.navbarstyle):wikitext(require('Module:Navbar')._navbar{args.name,mini=1,fontstyle=args.navbarfontstyle})endendlocalbase_templatestyles=frame:extensionTag{name='templatestyles',args={src=cfg.i18n.templatestyles}}localtemplatestyles=''ifargs['templatestyles']andargs['templatestyles']~=''thentemplatestyles=frame:extensionTag{name='templatestyles',args={src=args['templatestyles']}}endlocalchild_templatestyles=''ifargs['child templatestyles']andargs['child templatestyles']~=''thenchild_templatestyles=frame:extensionTag{name='templatestyles',args={src=args['child templatestyles']}}endlocalgrandchild_templatestyles=''ifargs['grandchild templatestyles']andargs['grandchild templatestyles']~=''thengrandchild_templatestyles=frame:extensionTag{name='templatestyles',args={src=args['grandchild templatestyles']}}endreturntable.concat({base_templatestyles,templatestyles,child_templatestyles,grandchild_templatestyles,tostring(root),(childandcfg.i18n.category.childor''),categorizeTemplatesWithInlineStyles(args)})endlocalfunctionlist_title(args,is_centered_list_titles,num)localtitle_text=trimAndAddAutomaticNewline(args['list'..num..'title']orcfg.i18n.default_list_title)localtitleifis_centered_list_titlesthen-- collapsible can be finicky, so provide some CSS/HTML to supporttitle=mw.html.create('div'):addClass(cfg.i18n.class.list_title_centered):wikitext(title_text)elsetitle=mw.html.create():wikitext(title_text)endlocaltitle_container=mw.html.create('div'):addClass(cfg.i18n.class.list_title)-- don't /need/ a listnumtitleclass because you can do-- .templateclass .listnumclass .sidebar-list-title:addClass(args.listtitleclass):cssText(args.basestyle):cssText(args.listtitlestyle):cssText(args['list'..num..'titlestyle']):node(title):done()returntitle_containerend--[[Main entry point for sidebar with collapsible lists.Does the work of creating the collapsible lists themselves and including theminto the args.]]functionp.collapsible(frame)localargs=getArgs(frame)ifnotargs.nameandframe:getParent():getTitle():gsub(cfg.i18n.pattern.collapse_sandbox,'')==cfg.i18n.collapse_title_not_to_add_navbarthenargs.navbar=cfg.i18n.navbar_noneendlocalcontentArgs={}localis_centered_list_titlesifargs['centered list titles']andargs['centered list titles']~=''thenis_centered_list_titles=trueelseis_centered_list_titles=falseendfork,vinpairs(args)dolocalnum=string.match(k,'^list(%d+)$')ifnumthenlocalexpand=args.expandedand(args.expanded=='all'orargs.expanded==args['list'..num..'name'])localrow=mw.html.create('div')row:addClass(cfg.i18n.class.list):addClass('mw-collapsible'):addClass((notexpand)and'mw-collapsed'ornil):addClass(args['list'..num..'class']):cssText(args.listframestyle):cssText(args['list'..num..'framestyle']):node(list_title(args,is_centered_list_titles,num)):tag('div'):addClass(cfg.i18n.class.list_content):addClass('mw-collapsible-content')-- don't /need/ a listnumstyleclass because you can do-- .templatename .listnumclass .sidebar-list:addClass(args.listclass):cssText(args.liststyle):cssText(args['list'..num..'style']):wikitext(trimAndAddAutomaticNewline(args['list'..num]))contentArgs['content'..num]=tostring(row)endendfork,vinpairs(contentArgs)doargs[k]=vendreturnp.sidebar(frame,args,cfg.i18n.class.collapse)endreturnp