stringtranslate.com

Module:Banner shell

local p = {}local yesno = require('Module:Yesno')local shell = function(frame, header, content, collapsed, class)local styles = frame:extensionTag('templatestyles', '', {src = 'Module:Message box/tmbox.css'}).. frame:extensionTag('templatestyles', '', {src = 'Module:Banner shell/styles.css'})local content_rowif content thencontent_row = mw.html.create('tr'):tag('td'):attr('colspan', '2'):addClass('banner-shell-inner'):addClass('outercollapse'):wikitext(content):done()endlocal holder = mw.html.create('table'):attr('role', 'presentation'):addClass('tmbox'):addClass('tmbox-notice'):addClass('banner-shell'):addClass(class) -- allow additional class to be specified:addClass(content and 'mw-collapsible' or nil):addClass(collapsed and 'mw-collapsed' or nil):node(header):node(content_row)return styles .. tostring(holder)endp.banner_holder = function(frame)local args = require('Module:Arguments').getArgs(frame, {wrappers = {'Template:Banner holder'}})local image = '[[File:' .. (args.image or 'NewFavicon icon.svg').. '|' .. (args.size or '24') .. 'px'.. '|link=' .. (args.image_link or '').. '|alt=' .. (args.alt or '') .. ']]'local image_cell = mw.html.create('td'):addClass('mbox-image'):wikitext(image)local text_cell = mw.html.create('td'):addClass('mbox-text'):addClass('banner-shell-header'):tag('span'):addClass('collapseButton'):addClass('nowrap'):css('float', 'left'):wikitext(string.rep('&nbsp;', 10)):done():wikitext(args.text or 'Other talk page banners')local header = mw.html.create('tr'):node(image_cell):node(text_cell)return shell(frame, header, args[1], yesno(args.collapsed))endlocal DuplicateBanners = function(text)local capture = '<span class="wpb%-project">([%w%s]*)</span>'local banners = {}for project in text:gmatch(capture) doif banners[project] == true thenreturn projectendbanners[project] = trueendendp.banner_shell = function(frame)local args = require('Module:Arguments').getArgs(frame, {wrappers = {'Template:WikiProject banner shell'}})local title = args.demo_page and mw.title.new(args.demo_page) or mw.title.getCurrentTitle()local pagetype = require('Module:Pagetype')._main{page = title.prefixedText,[1] = args.class,dab = 'disambiguation page',soft_redirect = 'soft redirect',nonexistent = 'non-existent page',defaultns = 'extended'}local classmask = require('Module:WikiProject banner').class_masklocal class = pagetype=='article' and args.class or ''class = classmask(class, title.talkPageTitle, false, pagetype)local demo = not yesno(args.category or true, true) or args.demo_pagelocal out = {}local addCategory = function(category, sort_key)if not demo and title.isTalkPage thenlocal category_title = mw.title.new('Category:' .. category)table.insert(out, '[[' .. category_title.prefixedText .. (sort_key and ('|' .. sort_key) or '') .. ']]')endendif demo and not args.demo_page thenpagetype = 'article'endif yesno(args.blp) or yesno(args.living) thentable.insert(out, frame:expandTemplate{title = 'BLP'})elseif yesno(args.blpo) thentable.insert(out, frame:expandTemplate{title = 'BLP others'})endif yesno(args.activepol) thentable.insert(out, frame:expandTemplate{title = 'Active politician'})endif class=='' and args[1] then -- check if class parameters are defined by any project bannerlocal articleclass = require('Module:WikiProject banner').readarticleclass({ignore_blank = true, only_subtemplates = true},title.talkPageTitle.prefixedText)if articleclass~='' then -- class parameters are defined by one or more project bannersclass = nil -- no global assessmentlocal raw_args = require('Module:Arguments').getArgs(frame, {wrappers = {'Template:WikiProject banner shell'},removeBlanks = false})endendlocal class2 = class and class~='' and (class .. '-Class') or 'Unassessed'local vitallocal icon_class = 'council'if yesno(args.vital) thenlocal page = mw.ustring.upper(mw.ustring.sub(title.subjectPageTitle.text, 1, 1)) -- get first letter of article namelocal codepoint = mw.ustring.codepoint(page, 1, 1)if codepoint<65 or codepoint>90 then --first letter is not between A-Zpage = 'others'endlocal data_page = mw.title.new('Wikipedia:Vital articles/data/' .. page .. '.json')if data_page.exists thenlocal index = title.subjectPageTitle.textindex = tostring(tonumber(index))==index and tonumber(index) or index --convert to number if page is numerical, otherwise loadJsonData does not worklocal data = mw.loadJsonData(data_page.fullText)[index]if data thenlocal level = data.level and tostring(data.level)if level and data.topic thenlocal link = 'Wikipedia:Vital articles/Level/' .. levelif (level=='4' or level=='5') thenlink = link .. '/' .. data.topicendif data.sublist thenlink = link .. '/' .. data.sublistendif data.section thenlink = link .. '#' .. data.sectionendif not mw.title.new(link).exists then -- add tracking category if link does not existaddCategory('Wikipedia vital articles needing attention', 'L')endvital = 'This [[File:Círculos Concéntricos.svg|16px|link=|alt=]]&nbsp;<b>[[' .. link .. '|level-' .. level .. ' vital article]]</b> 'elsevital = 'This vital article 'endlocal vitalCat = function(cat, valid) -- valid is table of 3 booleans for class/level/topic, if true then category will not be populated unless validlocal show_cat = trueif (valid.class and (class=='NA' or class==nil or class==''))or (valid.level and level==nil)or (valid.topic and data.topic==nil) thenshow_cat = falseendif show_cat thenlocal category = cat:gsub('_CLASS', class2):gsub('_LEVEL', level or 'unknown'):gsub('_TOPIC', data.topic or 'an unknown topic')addCategory(category)endendvitalCat('_CLASS vital articles', {})vitalCat('Wikipedia level-_LEVEL vital articles', {})vitalCat('Wikipedia vital articles in _TOPIC', {})vitalCat('_CLASS level-_LEVEL vital articles', {class=true, level=true})vitalCat('Wikipedia level-_LEVEL vital articles in _TOPIC', {level=true, topic=true})vitalCat('_CLASS vital articles in _TOPIC', {class=true, topic=true})elseaddCategory('Articles not listed in the vital article list')endendendlocal pagetype_display = pagetype=='article' and 'article'or pagetype=='page' and 'page'or pagetype=='non-existent page' and 'page'or ('<b>' .. pagetype .. '</b>')-- use bold if page type is not articlelocal text = vital or 'This ' .. pagetype_display .. ' 'if class or not args[1] thenlocal icons = { -- map output of pagetype function to input of class icon function['project page'] = 'project',['user page'] = 'user',['interface page'] = 'interface',['help page'] = 'help',['module'] = 'module',['disambiguation page'] = 'disambig',['soft redirect'] = 'redirect',['non-existent page'] = 'vacant',['page'] = 'na'}icon_class = class=='NA' and (icons[pagetype] or pagetype) or classif class=='' thentext = text .. 'has not yet been rated'elseif class=='NA' thentext = text .. 'does not require a rating'elsetext = text .. 'is rated <span style="font-weight:bold;">' .. class .. '-class</span>'endtext = text .. ' on Wikipedia\'s [[Wikipedia:Content assessment|content assessment]] scale.'if args[1] thentext = text .. '<br>It'elseif not yesno(args.vital) thenaddCategory(class2 .. ' articles')endendif args[1] thentext = text .. ' is of interest to ' .. (yesno(args.collapsed)and 'multiple [[Wikipedia:WikiProject|WikiProjects]].'or ('the following [[Wikipedia:WikiProject|WikiProjects]]:'))endlocal icon = require('Module:Class')._icon{icon_class, size='35px'}local header = 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(text):done()table.insert(out,shell(frame, header, args[1], yesno(args.collapsed), 'wpbs'))if args[1] thenlocal duplicate_cat = DuplicateBanners(args[1])if duplicate_cat and title.isTalkPage thenaddCategory('Pages using WikiProject banner shell with duplicate banner templates', duplicate_cat)endendif args.listas thentable.insert(out, frame:preprocess('{{DEFAULTSORT:' .. args.listas .. '}}'))endif not demo thenlocal tracking = require('Module:Check for unknown parameters')._check({['unknown']='[[Category:Pages using WikiProject banner shell with unknown parameters|_VALUE_ ]]',['preview']='Page using [[Template:WikiProject banner shell]] with unknown parameter "_VALUE_"','1', 'activepol', 'blp', 'blpo', 'category', 'class', 'collapsed', 'demo_page', 'listas', 'living', 'vital'}, frame:getParent().args)table.insert(out, tracking)for _, param in ipairs{'activepol', 'blp', 'blpo', 'category', 'collapsed', 'living'} doif yesno(args[param], 'invalid')=='invalid' thenaddCategory('Pages using WikiProject banner shell with invalid parameters', param)endendif pagetype=='article' and args.class and class=='' then -- find pages with invalid class parameteraddCategory('Pages using WikiProject banner shell with invalid parameters', 'Zclass')endendreturn table.concat(out)endreturn p