Module:Banner shell
Appearance
From Wikipedia, the free encyclopedia
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Warning This Lua module is used on approximately 11,600,000 pages, or roughly 18% of all pages .
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them.
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them.
Banner shell |
---|
Usage
This module implements Template:WikiProject banner shell and Template:Banner holder. Please refer to those templates' documentation.
The above documentation is transcluded from Module:Banner shell/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
require('strict') localp={} localsandbox-- = '/sandbox' -- BE SURE TO COMMENT OUT this definition when deploying to live localyesno=require('Module:Yesno') localshell=function(frame,header,content,collapsed,class) localstyles=frame:extensionTag('templatestyles','',{src='Module:Message box/tmbox.css'}) ..frame:extensionTag('templatestyles','',{src='Module:Banner shell'..(sandboxor'')..'/styles.css'}) localcontent_row ifcontentthen content_row=mw.html.create('tr') :tag('td') :attr('colspan','2') :addClass('banner-shell-inner') :addClass('outercollapse') :wikitext(content) :done() end localholder=mw.html.create('table') :attr('role','presentation') :addClass('tmbox') :addClass('tmbox-notice') :addClass('banner-shell') :addClass(class)-- allow additional class to be specified :addClass(contentand'mw-collapsible'ornil) :addClass(collapsedand'mw-collapsed'ornil) :node(header) :node(content_row) returnstyles..tostring(holder) end p.banner_holder=function(frame) localargs=require('Module:Arguments').getArgs(frame,{wrappers={'Template:Banner holder'}}) localimage='[[File:'..(args.imageor'NewFavicon icon.svg') ..'|'..(args.sizeor'24')..'px' ..'|link='..(args.image_linkor'') ..'|alt='..(args.altor'')..']]' localimage_cell=mw.html.create('td') :addClass('mbox-image') :wikitext(image) localtext_cell=mw.html.create('td') :addClass('mbox-text') :addClass('banner-shell-header') :tag('span') :addClass('nowrap') :css('float','left') :wikitext(string.rep(' ',10)) :done() :wikitext(args.textor'Other talk page banners') localheader=mw.html.create('tr') :node(image_cell) :node(text_cell) returnshell(frame,header,args[1],yesno(args.collapsed)) end localDuplicateBanners=function(text) localcapture='<span class="wpb%-project">([^<>]*)</span>' localbanners={} forprojectintext:gmatch(capture)do ifbanners[project]==truethen returnproject end banners[project]=true end end p.banner_shell=function(frame) localcfg=mw.loadData('Module:Banner shell/config'..(sandboxor'')) localargs=require('Module:Arguments').getArgs(frame,{wrappers={cfg.template}}) localtitle=args.demo_pageandmw.title.new(args.demo_page)ormw.title.getCurrentTitle() localpagetype=require('Module:Pagetype')._main{ page=title.prefixedText, dab=cfg.page_types.dab, sia='set index article', soft_redirect=cfg.page_types.soft_redirect, nonexistent=cfg.page_types.nonexistent, timedtext=cfg.page_types.timedtext, defaultns='extended' } locallang=mw.language.getContentLanguage() localclassmask=require('Module:WikiProject banner'..(sandboxor'')).class_mask localclass=classmask(args.classor'',title.talkPageTitle,false,pagetype) localdemo=notyesno(args.categoryortrue,true)orargs.demo_page localout={} localaddCategory=function(category,sort_key) ifnotdemoandtitle.isTalkPagethen localcategory_title=mw.title.new('Category:'..category) table.insert(out,'[['..category_title.prefixedText..(sort_keyand('|'..sort_key)or'')..']]') end end ifdemoandnotargs.demo_pagethen pagetype='article' end localblp=args.blpandargs.blp:lower() ifyesno(blp)orblp=='activepol'then table.insert(out,frame:expandTemplate{ title=cfg.blp_template.blp, args={activepol=blp=='activepol'and'yes'} }) elseifblp=='other'then table.insert(out,frame:expandTemplate{ title=cfg.blp_template.blpo} ) end localvital ifyesno(args.vital)then localpage=mw.ustring.upper(mw.ustring.sub(title.subjectPageTitle.text,1,1))-- get first letter of article name localcodepoint=mw.ustring.codepoint(page,1,1) ifcodepoint<65orcodepoint>90then--first letter is not between A-Z page='others' end localdata_page=mw.title.new('Wikipedia:Vital articles/data/'..page..'.json') ifdata_page.existsthen localindex=title.subjectPageTitle.text index=tostring(tonumber(index))==indexandtonumber(index)orindex--convert to number if page is numerical, otherwise loadJsonData does not work localdata=mw.loadJsonData(data_page.fullText)[index] ifdatathen locallevel=data.levelandtostring(data.level) iflevelanddata.topicthen locallink='Wikipedia:Vital articles/Level/'..level if(level=='4'orlevel=='5')then link=link..'/'..data.topic end ifdata.sublistthen link=link..'/'..data.sublist end ifdata.sectionthen link=link..'#'..data.section end ifnotmw.title.new(link).existsthen-- add tracking category if link does not exist addCategory(cfg.vital.attention,'L') end vital=cfg.vital.with_level:format(link,level) else vital=cfg.vital.without_level end for_,catinipairs(cfg.vital.categories)do ifcat:find('_CLASS')and(class=='NA'orclass=='')then addCategory(cfg.vital.attention,class=='NA'and'N'or'U') elseiflevel==nilthen addCategory(cfg.vital.attention,'V') elseifdata.topic==nilthen addCategory(cfg.vital.attention,'T') else localcategory=cat :gsub('_CLASS',class..'-Class') :gsub('_LEVEL',level) :gsub('_TOPIC',data.topic) addCategory(category) end end addCategory(cfg.vital.all) else addCategory(cfg.vital.not_listed) end end end localtext,icon_image,icon_str ifclass=='NA'then icon_image=cfg.icons.type[pagetype]orcfg.icons.default icon_str=pagetype=='page'and'Non-article page'orlang:ucfirst(pagetype) text={cfg.rating.not_required:format(vitalorpagetype)} elseifclass==''then icon_image=cfg.icons.unassessed icon_str='Unassessed article' text={cfg.rating.not_yet:format(vitalorpagetype)} addCategory('All unassessed articles') else icon_image=cfg.icons.quality[class]orcfg.icons.unassessed icon_str=class..'-Class '..pagetype text={cfg.rating.rated:format(vitalorpagetype,class)} frame:preprocess('{{#assessment:Project-independent assessment'..'|'..class..'}}') end localicon=string.format('[[File:%s|%s|35px|class=noviewer|alt=]]',icon_image,icon_str) table.insert(text,' '..cfg.rating.scale) ifargs[1]then table.insert(text,'<br>'..cfg.project.interest..' ') table.insert(text,yesno(args.collapsed)andcfg.project.collapsedorcfg.project.uncollapsed) localduplicate_cat=DuplicateBanners(args[1]) ifduplicate_catandtitle.isTalkPagethen addCategory(cfg.tracking.duplicate,duplicate_cat) end elseifnotyesno(args.vital)andclass~=''then-- if no projects and not vital and assessed then add class super category addCategory(class..'-Class '..(class=='NA'and'pages'or'articles')) end localheader=mw.html.create('tr') :tag('td') :addClass('assess') :wikitext(icon) :done() :tag('td') :addClass('banner-shell-header') :css('text-align','left') :css('font-weight','normal') :wikitext(table.concat(text)) :done() table.insert( out, shell(frame,header,args[1],yesno(args.collapsed),'wpbs') ) ifargs.listasthen table.insert(out,frame:preprocess('{{DEFAULTSORT:'..args.listas..'}}')) end ifnotdemothen localtracking=require('Module:Check for unknown parameters')._check({ unknown=cfg.tracking.unknown, preview=cfg.tracking.preview, '1','blp','category','class','collapsed','demo_page','listas','vital' },frame:getParent().args) table.insert(out,tracking) ifargs.categoryandyesno(args.category)~=falsethen-- category should not be "yes" addCategory(cfg.tracking.invalid,'category') end ifargs.collapsedandyesno(args.collapsed)~=truethen-- collapsed should not be "no" addCategory(cfg.tracking.invalid,'collapsed') end ifyesno(blp)==nilandblp~=nilandblp~='other'andblp~='activepol'then addCategory(cfg.tracking.invalid,'blp') end ifpagetype=='article'andargs.classandclass==''then-- find pages with invalid class parameter addCategory(cfg.tracking.invalid,'Zclass') end end returntable.concat(out) end returnp