--[=[This is a module to implement logic for header templates]=]require('strict')localp={}--p stands for packagelocalgetArgs=require('Module:Arguments').getArgslocalplain_sister=require('Module:Plain sister')._plain_sister-- return true if any value in list is not nil or empty in args-- (nil means not present; empty string is not nil)localfunctionhas_any_arg(args,list)fork,vinpairs(list)doifargs[v]~=nilthenreturntrueendendreturnfalseend--[=[Construct the main block]=]localfunctionconstruct_main_block(args,prefix)-- header and tracking categorieslocalmain_div=mw.html.create('div'):addClass('wst-header-mainblock'):addClass(prefix..'-mainblock')-- If an extra main class was provided, add it-- TODO: Is this used? Is it needed?ifargs.main_class~=nilandargs.main_class~=""thenmain_div:addClass(args.main_class)end-- "Previous" fieldlocalprev_div=main_div:tag('div'):addClass('wst-header-back'):addClass('searchaux'):addClass(prefix..'-back'):tag('div'):addClass('wst-header-back-arrow'):wikitext('←'):done():tag('div'):addClass('wst-header-back-link'):wikitext(args['previous']):done()ifargs['previous']==nilorargs['previous']==""thenprev_div:addClass('wst-header-nav-empty')end-- The central celllocalcenter_div=main_div:tag('div'):addClass('wst-header-central-cell'):addClass(prefix..'-central-cell')-- Special case to manage exceptional formatting in disambiguation-like-- pages; not otherwise documentedlocalpretitle=''ifargs.pretitlethenlocalbr='<br/>'ifnotargs.main_titleorargs.main_title==''thenbr=''endcenter_div:tag('span'):addClass('wst-header-pretitle'):wikitext(args.pretitle..br)endcenter_div:tag('span'):addClass('wst-header-title'):addClass(prefix..'-title'):wikitext(args.main_titleor'')-- "Next" fieldlocalnext_div=main_div:tag('div'):addClass('wst-header-forward'):addClass('searchaux'):addClass(prefix..'-forward'):tag('div'):addClass('wst-header-forward-link'):wikitext(args['next']):done():tag('div'):addClass('wst-header-forward-arrow'):wikitext('→'):done()ifargs['next']==nilorargs['next']==""thennext_div:addClass('wst-header-nav-empty')endreturntostring(main_div)end--[=[Construct the notes block]=]localfunctionconstruct_notes_block(args,prefix)localmain_div=mw.html.create('div'):addClass('wst-header-notes'):addClass('header_notes'):addClass('searchaux'):addClass(prefix..'-notes')-- If an extra main class was provided, add it-- TODO: Is this used? Is it needed?ifargs.notes_class~=nilandargs.notes_class~=""thenmain_div:addClass(args.notes_class)end-- Left-floated content has to come first, or it may float below the sisters.localnotes_left_content=''ifargs.notes_left_contentthenlocalnotes_left_content_div=mw.html.create('div'):addClass('wst-header-left'):addClass('header_notes_left_content'):addClass(prefix..'-left'):wikitext(args.notes_left_content)notes_left_content=tostring(notes_left_content_div)endlocalshortcut=''ifargs.shortcutthenshortcut=mw.getCurrentFrame():expandTemplate{title='shortcut',args={args.shortcut}}endlocalnotes_content=''ifargs.notesthenargs.notes=mw.getCurrentFrame():preprocess(args.notes)-- linebreaks are so notes get paragraph formattinglocalnotes_content_div=mw.html.create('div'):addClass('wst-header-content'):addClass('header_notes_content'):addClass('wst-header-notes-content'):addClass(prefix..'-notes-content'):wikitext('\n'..args.notes..'\n')notes_content=tostring(notes_content_div)endlocalsister=plain_sister(args)ifnotsisterandnotargs.notesandnotargs.notes_left_contentthenreturn''endreturntostring(main_div:wikitext(notes_left_content..(sisteror'')..shortcut..notes_content))end--[=[Construct header]=]functionp.construct_header(args)-- Make sure the main identifying class for the client template is setlocalprefix="wst-unknown"ifargs.template~=nilandargs.template~=""thenprefix="wst-"..args.templateendlocalheaderContainer=mw.html.create('div'):addClass("ws-header"):addClass("wst-header-structure"):addClass(prefix)-- header_class from client modules, class from individual usesifargs.header_classthenheaderContainer:addClass(args.header_class)endifargs.classthenheaderContainer:addClass(args.class)endheaderContainer:wikitext(table.concat({(args.pre_mainor''),construct_main_block(args,prefix),construct_notes_block(args,prefix),(args.post_notesor'')}))localstylesheet=mw.getCurrentFrame():extensionTag('templatestyles','',{src='Header structure/styles.css'})returnstylesheet..(args.pre_containeror'')..tostring(headerContainer)endfunctionp.header_structure(frame)returnp.construct_header(getArgs(frame))endreturnp