stringtranslate.com

Module:WikiProject banner

require('strict')local p = {}local sandbox-- = '/sandbox'local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or ''))local args_module = require('Module:Arguments')local mbox = require('Module:Message box').mainlocal yesno = require('Module:Yesno')local frame = mw.getCurrentFrame()local lang = mw.getLanguage(cfg.language)local current_title = mw.title.getCurrentTitle()local parameter_format = function(parameter, value)return frame:expandTemplate{title='para', args={parameter, value or ''}}endlocal wikilink = function(link, display)if link thenreturn display and '[['..link..'|'..display..']]' or '[['..link..']]'elsereturn display or ''endendlocal image = function(image_name, size, alt, position)return image_name and '[[File:'.. image_name.. (size and '|' .. size or '').. (position and '|' .. position or '').. (alt and '|alt=' .. alt or '').. ']]'endlocal if_exists = function(target, fallback) -- function to add wikilink if target existslocal title = mw.title.new(target)if title and title.exists thenreturn wikilink(target)elsereturn fallback or targetendendlocal isarticle = function(class)local article = truefor _,v in ipairs(cfg.quality.non_article_classes) doif class==v then -- class matches one of the non-article classesarticle = falsebreakendendreturn articleend----------------------------- Importance mask -----------------------------------local importance_mask = function(raw_importance, class, scale, banner_name)local importanceif scale=='inline' then -- pass importance without changeimportance = raw_importanceelseif scale=='subpage' thenlocal custom_mask = banner_name:subPageTitle('importance')if custom_mask.exists and #custom_mask:getContent()>1 then -- pass to custom importance maskimportance = mw.text.trim(frame:expandTemplate{title = custom_mask.prefixedText,args = {importance=raw_importance or '¬', class=class}})endelseimportance = frame:expandTemplate{title = 'Template:Importance mask',args = {raw_importance or '¬', class=class}}endif importance=='¬' thenimportance = nilendreturn importanceend----------------------------- Quality class mask --------------------------------p.readarticleclass = function(options, page) -- used by _main and also Module:Banner shellpage = page or current_title.prefixedTextlocal get_parameter_value = require('Module:Template parameter value').getValuelocal success, result = get_parameter_value(page, cfg.WPBS_redirects, 'class', options)return success and result-- returns FALSE if banner shell template does not exist on page-- returns BLANK if class parameter is not defined or is defined blank-- otherwise returns class parameterendp.class_mask = function(class, title, FQS, pagetype)local resolveFQSgrade = function(class)return FQS and lang:ucfirst(class) or 'NA'endlocal outtitle = title or mw.title.getCurrentTitle()local ns = title.namespaceclass = class:match('^%s*(.-)%s*$'):lower()if pagetype=='redirect' or pagetype=='soft redirect' thenout = resolveFQSgrade('redirect')elseif pagetype=='disambiguation page' or class=='dab' or class=='disambig' or class=='disambiguation' or class=='disamb' thenout = resolveFQSgrade('disambig')elseif pagetype=='article' thenif class=='start' or class=='stub' then -- Ucfirstout = lang:ucfirst(class)elseif class=='b' or class=='c' or class=='fa' or class=='fl' or class=='a' or class=='ga' then -- Upper-caseout = class:upper()elseif class=='list' or class=='sia' or class=='si' or class=='sl' then-- Listout = 'List'elseout = '' -- unassessedendelseif ns==7 or ns==711 then -- File talkif class=='fm' and FQS thenout = 'FM'elseout = resolveFQSgrade('file')endelseif ns==15 then -- Category talkout = resolveFQSgrade('category')elseif ns==101 then -- Portal talkout = resolveFQSgrade('portal')elseif ns==11 or ns==829 then -- Template talkout = resolveFQSgrade('template')elseif ns==5 then -- Wikipedia talkout = resolveFQSgrade('project')elseif ns==119 then -- Draft talkout = resolveFQSgrade('draft')elseout = 'NA'endreturn outendlocal page_assessment = function(project, class, importance) -- add PageAssessments parser functionlocal assessment = table.concat({project, class or '', importance or ''},'|')frame:preprocess('{{#assessment:' .. assessment .. '}}')endlocal bubble = function(text, colour, conflict)local out = mw.html.create('span'):addClass('wpb-header-bubbles'):css('color', '#202122'):css('background', colour):css('border', conflict and cfg.quality.conflict.border or (cfg.quality.border..' '..colour)):wikitext(text)return tostring(out)endp._main = function(args, raw_args, demo, banner_name, inactive)----------------------------- Initialise parameters -----------------------------local project = args.PROJECT or 'PROJECT'local project_name = args.PROJECT_NAME or 'WikiProject ' .. projectlocal project_link = mw.title.new(args.PROJECT_LINK or 'Wikipedia:' .. project_name)local pagetype = demo and not args.demo_page and 'article' or require('Module:Pagetype' .. (sandbox or ''))._main({page = args.demo_page,dab = 'disambiguation page'})local rows, nested_ratings, task_forces, notes, categories, taskforce_categories = {}, {}, {}, {}, {}, {}local add_category = function(category, key)if category and category~='none' thentable.insert(categories, {category = category, key = key})endendlocal parse_text = function(text)return text and text:gsub('_PAGETYPE_', pagetype)endfor arg_name, arg_value in pairs(args) dolocal tf_match = mw.ustring.match(arg_name,'^tf (%d+)$')local note_match = mw.ustring.match(arg_name,'^note (%d+)$')if tf_match and yesno(arg_value, true) thentable.insert(task_forces, tf_match)elseif note_match and yesno(arg_value, true) thentable.insert(notes, note_match)elselocal tf, cat = mw.ustring.match(arg_name,'^tf (%d+) cat (%d+)$')if tf and yesno(arg_value, true) thenif not taskforce_categories[tf] then -- initialise tabletaskforce_categories[tf] = {}endtable.insert(taskforce_categories[tf], cat)endendendtable.sort(task_forces, function (x, y) return tonumber(x) < tonumber(y) end)table.sort(notes, function (x, y) return tonumber(x) < tonumber(y) end)local warning = ''----------------------------- Location warning ----------------------------------local show_namespace_warning = not (current_title.isTalkPage or demo)if show_namespace_warning thenlocal text = cfg.namespace_warning.text:format(pagetype,current_title.talkPageTitle.fullText,parameter_format('category', 'no'))local sortkey = current_title.namespace==10 and cfg.namespace_warning.sortkey_on_template_page or cfg.namespace_warning.sortkeyif current_title.namespace==10 then -- on the Template namespacetext = text .. ' ' .. cfg.namespace_warning.on_template_page:format(parameter_format('BANNER_NAME'),current_title.prefixedText)endwarning = mbox('ombox', {image = '[[File:' .. cfg.namespace_warning.image .. '|40px]]',type = cfg.namespace_warning.type_,text = text})if not current_title.subjectPageTitle:inNamespace(2) thenadd_category(cfg.namespace_warning.categories, sortkey)endend----------------------------- Substitution warning ------------------------------if args.substcheck=='SUBST' thenlocal text = cfg.subst_warning.text:format(project_name,'<code>&#123;&#123;'..banner_name.prefixedText..'&#125;&#125;</code>')warning = warning .. mbox('ombox', {image = '[[File:' .. cfg.subst_warning.image .. '|40px]]',type = cfg.subst_warning.type_,text = text,}) .. cfg.subst_warning.categoriesend----------------------------- Primary image/text --------------------------------local assessment_cat = args.ASSESSMENT_CAT or project .. ' articles'local primary_image = function(image_name, size)local cell = mw.html.create('td')if image_name and image_name~='' thencell:addClass('mbox-image wpb-image'):wikitext(image(image_name, size, cfg.image.alt))elsecell:addClass('mbox-empty-cell')endreturn cellendlocal portal = args.PORTALlocal portal_box = portal and frame:expandTemplate{title='Portal', args={portal}} or ''local main_text = portal_box .. (parse_text(args.MAIN_TEXT) or cfg.main_text:format(pagetype,project_link.prefixedText,project_name,args.MAIN_ARTICLE and if_exists(args.MAIN_ARTICLE) or if_exists(project, project .. ' articles'),project_link.talkPageTitle.prefixedText))local image_left_size = args.IMAGE_LEFT_SIZE or cfg.image.default_sizelocal metadata = function(class, data)return mw.html.create('span'):addClass(class):wikitext(data)endlocal text_cell = mw.html.create('td'):addClass('mbox-text'):wikitext(main_text):tag('span'):addClass('metadata wpb-metadata'):node(metadata('wpb-project', project)):node(metadata('wpb-project_link', project_link.prefixedText)):node(metadata('wpb-banner_name', banner_name.prefixedText)):node(metadata('wpb-assessment_cat', assessment_cat)):done()local primary_row = mw.html.create('tr'):node(primary_image(args.IMAGE_LEFT, image_left_size)):node(text_cell):node(primary_image(args.IMAGE_RIGHT, args.IMAGE_RIGHT_SIZE or cfg.image.default_size))table.insert(rows, primary_row)----------------------------- Quality assessment --------------------------------local assessment_link = args.ASSESSMENT_LINKif not assessment_link thenlocal fallback = mw.title.new(project_link.prefixedText .. '/Assessment')assessment_link = fallback.exists and fallback.prefixedTextelseif assessment_link=='no' thenassessment_link = nilendlocal check_exists = function(class, assessment_cat) -- check if category exists and is not blankif not isarticle(class) thenlocal cat = mw.title.new('Category:' .. class .. '-Class' .. ' ' .. assessment_cat)return (cat.exists and #cat:getContent()>0) and class or 'NA' -- automatically use NA for non-article pages if category does not existelsereturn classendendlocal class = raw_args.classif class then -- banner gives quality ratingslocal title = args.demo_page and mw.title.new(args.demo_page) or current_titlelocal article_class = p.readarticleclass({ignore_subtemplates=true}, title.prefixedText)if not article_class thenif pagetype=='article' thenadd_category(cfg.category.no_banner_shell_articles)elseadd_category(cfg.category.no_banner_shell)endendarticle_class = article_class and p.class_mask(article_class, title, false, pagetype)local show_quality, conflict = true, falseif args.QUALITY_CRITERIA=='custom' then -- project has opted out of standard assessment scale and uses a custom masklocal custom_mask = banner_name:subPageTitle('class')if custom_mask.exists and #custom_mask:getContent()>1 thenraw_args.demo_page = args.demo_page -- send demo_page to custom maskclass = mw.text.trim(frame:expandTemplate{title = custom_mask.prefixedText,args = raw_args})if class=='' and article_class and article_class~='' then -- if unassessed and article class exists, check if it can be inheritedlocal new_arg_table = {}for arg, val in pairs(raw_args) do -- construct new argument table to send to custom masknew_arg_table[arg] = valendnew_arg_table.class = article_class -- replace class with inherited classlocal article_class_normalised = mw.text.trim(frame:expandTemplate{title = custom_mask.prefixedText,args = new_arg_table})if article_class_normalised and article_class_normalised~='' thenclass = article_class_normalised -- inherit class from article_class normalised by custom maskelsearticle_class = nil -- effectively no article_class for this bannerendendendelseclass = p.class_mask(class, title, true, pagetype)endif article_class then -- banner shell existsif article_class=='' then -- no article class definedif class=='' then -- local class also does not exist, check whether any other class parameters are defined inside the shelllocal classparam = p.readarticleclass({ignore_blank=true, only_subtemplates=true}, title.prefixedText)if classparam=='' then -- no class parameters defined, display as globally unassessedshow_quality = false -- hide quality class in project bannerendelseadd_category(cfg.category.no_quality_rating)endelseif class=='' or class==article_class then -- local class matches article class or is blankshow_quality = false -- hide quality class in project bannerclass = article_classif raw_args.class~='' and args.QUALITY_CRITERIA~='custom' thenadd_category(cfg.category.redundant_class)endelseif (article_class=='NA') and not isarticle(class) then -- article class and local class are both non-article classesshow_quality = falseelse -- article class exists and differs from local classif args.QUALITY_CRITERIA~='custom' thenconflict = trueadd_category(cfg.quality.conflict.category)endendendif not isarticle(class) thenlocal cat = mw.title.new(cfg.quality.assessment_category:format(class, assessment_cat))if not (cat.exists and #cat:getContent()>0) then --check if category exists and is not blankclass = 'NA' -- automatically use NA for non-article pages if category does not existendendlocal category = (class=='' and 'Unassessed' or class..'-Class') .. ' ' .. assessment_catif show_quality then -- quality rating shown in bannerlocal ratingif pagetype=='article' thenrating = class=='' and cfg.quality.not_yet or cfg.quality.rated:format(class)elserating = cfg.quality.not_requiredendlocal scale = args.QUALITY_CRITERIA=='custom'and assessment_linkand cfg.quality.project_scale:format(wikilink(assessment_link..'#'..lang:ucfirst(cfg.quality.name), cfg.quality.name))or cfg.quality.default_scalelocal quality_rating = conflict and cfg.quality.conflict.text or cfg.quality.rating:format(pagetype, rating, scale)local colour = cfg.quality.colour[class] or cfg.quality.colour.defaultlocal class_row = mw.html.create('tr'):tag('td'):addClass('assess'):addClass('assess-' .. class):css('background', colour):css('color', 'inherit'):wikitext(wikilink(':Category:' .. category, class=='' and '???' or class)):css('border', conflict and cfg.quality.conflict.border or (cfg.quality.border..' '..colour)):done():tag('td'):addClass('mbox-text'):attr('colspan', '2'):wikitext(quality_rating):done()table.insert(rows, class_row)table.insert(nested_ratings,1,bubble(class=='' and 'Unassessed' or (class..'‑class'), colour, conflict))endadd_category(category)endif args.HOOK_ASSESS thentable.insert(rows, args.HOOK_ASSESS)endif raw_args.b1 or raw_args.b2 or raw_args.b3 or raw_args.b4 or raw_args.b5 or raw_args.b6 thenlocal b_checklist = require(cfg.auxiliary_module .. (sandbox or '')).b_checklist(args, raw_args, class, demo, assessment_link)table.insert(rows, b_checklist)end----------------------------- Importance assessment -----------------------------local importance = importance_mask(raw_args.importance or raw_args.priority, class, args.IMPORTANCE_SCALE, banner_name)local importance_name = args.IMPN or (raw_args.priority and 'priority' or cfg.importance.default_name)if importance then -- banner gives importance ratingslocal category = importance .. '-' .. importance_name .. ' ' .. assessment_catif importance~='NA' then -- display importance ratinglocal rating = importance=='Unknown' and cfg.importance.not_yet or cfg.importance.rated:format(importance, importance_name)local scale_name = cfg.importance.scale:format(importance_name)local scale = assessment_linkand cfg.importance.project_scale:format(assessment_link..'#'..lang:ucfirst(scale_name), scale_name)or cfg.importance.default_scalelocal importance_rating = cfg.importance.rating:format(pagetype, rating, scale)local colour = cfg.importance.colour[importance] or cfg.importance.colour.defaultlocal importance_row = mw.html.create('tr'):tag('td'):addClass('assess'):addClass('import'):addClass('import-' .. importance):css('color', '#202122'):css('background', colour):wikitext(wikilink(':Category:' .. category, importance=='Unknown' and '???' or importance)):done():tag('td'):addClass('mbox-text'):attr('colspan', '2'):wikitext(importance_rating):done()table.insert(rows, importance_row)if importance~='Unknown' then -- importance is not NA or Unknowntable.insert(nested_ratings,bubble(importance..'‑'..importance_name, colour))endendadd_category(category)endpage_assessment(project, class, importance)if args.HOOK_IMPORTANCE thentable.insert(rows, args.HOOK_IMPORTANCE)endif args.QII_FORMAT thenadd_category(require(cfg.auxiliary_module .. (sandbox or '')).quality_importance_insection(args, class, importance, importance_name))end----------------------------- Collapsing sections -------------------------------local collapse_section = function(collapse, new_rows, header)if collapse thenlocal header_row = mw.html.create('tr'):tag('th'):attr('colspan','3'):addClass('wpb-collapsed-head'):wikitext(header):done()local blank_row = mw.html.create('tr'):tag('td'):addClass('mbox-image wpb-gutter'):css('min-width',image_left_size):tag('span'):addClass('wpb-iefix'):wikitext('/&nbsp;'):done() --TO FIX IE:done():tag('td'):done():tag('td'):done()local collapsed_rows = mw.html.create('table'):addClass('mw-collapsible mw-collapsed'):node(header_row):node(blank_row)for _, row in ipairs(new_rows) docollapsed_rows:node(row)endlocal collapsed_section = mw.html.create('tr'):tag('td'):attr('colspan','3'):addClass('wpb-collapsed-notes'):node(collapsed_rows):done()table.insert(rows, collapsed_section)elsefor _, row in ipairs(new_rows) dotable.insert(rows, row)endendend----------------------------- Task forces ---------------------------------------local nested_tf, taskforce_output = {}, {}local tf_default_size = args.TF_SIZE or cfg.task_force.default_sizefor _, k in ipairs(task_forces) dolocal tf_prefix = 'TF_' .. k .. '_'local tf_assessment_cat = args[tf_prefix..'ASSESSMENT_CAT'] or (args[tf_prefix..'NAME'] or '')..' articles'local tf_importanceif raw_args['tf '..k..' importance'] thentf_importance = importance_mask(raw_args['tf '..k..' importance'], class, args.IMPORTANCE_SCALE, banner_name)if tf_importance=='Unknown' and yesno(args.INHERIT_IMPORTANCE) thentf_importance = importanceendendif args[tf_prefix .. 'TEXT']~='none' thenlocal portal = args[tf_prefix..'PORTAL'] and frame:expandTemplate{title='Portal', args={args[tf_prefix .. 'PORTAL'], height='15', margin='0'}} or ''local text = ''local tf_text = args[tf_prefix..'TEXT'] or args.TF_TEXTif tf_text thentext = portal .. tf_text:gsub('_NAME_', args[tf_prefix .. 'NAME'] or ''):gsub('_LINK_', args[tf_prefix .. 'LINK'] or ''):gsub('_IMPORTANCE_', tf_importance or ''):gsub('_PAGETYPE_', pagetype)elselocal tf_importance_text = tf_importanceand tf_importance~='NA'and tf_importance~='Unknown'and ' ' .. cfg.task_force.importance:format(wikilink(':Category:' .. tf_importance .. '-' .. importance_name .. ' ' .. tf_assessment_cat, tf_importance .. '-' .. importance_name)) or ''text = portal .. cfg.task_force.text:format(pagetype,wikilink(args[tf_prefix .. 'LINK'], args[tf_prefix .. 'NAME']),tf_importance_text)endlocal tf_size = args[tf_prefix .. 'SIZE'] or tf_default_sizelocal tf_image = ''if args[tf_prefix .. 'IMAGE'] thentf_image = image(args[tf_prefix .. 'IMAGE'], tf_size, cfg.task_force.icon_alt, 'center')endlocal taskforce = mw.html.create('tr'):tag('td'):wikitext(tf_image):done():tag('td'):addClass('mbox-text'):attr('colspan','2'):wikitext(text):done()table.insert(taskforce_output, taskforce)endif args[tf_prefix..'HOOK'] thentable.insert(taskforce_output, args[tf_prefix..'HOOK'])endif yesno(args[tf_prefix..'QUALITY']) and class thenlocal tf_class = check_exists(class, tf_assessment_cat)add_category((tf_class=='' and 'Unassessed' or tf_class..'-Class') .. ' ' .. tf_assessment_cat)endif tf_importance thenadd_category(tf_importance .. '-' .. importance_name .. ' ' .. tf_assessment_cat)endif args[tf_prefix..'QII_FORMAT'] thenadd_category(require(cfg.auxiliary_module .. (sandbox or '')).quality_importance_insection(args, class, tf_importance, importance_name, tf_prefix))endif args[tf_prefix..'NAME'] thenpage_assessment(project..'/'..args[tf_prefix..'NAME'], class, tf_importance)endif args[tf_prefix..'MAIN_CAT'] thenadd_category(args[tf_prefix..'MAIN_CAT'])endif args[tf_prefix..'NESTED'] thentable.insert(nested_tf, wikilink(args[tf_prefix..'LINK'], args[tf_prefix..'NESTED']))endfor _, c in ipairs(taskforce_categories[k] or {}) do-- add additional taskforce categoriesadd_category(args[tf_prefix..'CAT_'..c])endendif args.HOOK_TF thentable.insert(taskforce_output, args.HOOK_TF)endlocal threshold = tonumber(args.TF_COLLAPSE) or (args.TF_HEADER and cfg.task_force.lower_threshold) or cfg.task_force.upper_thresholdcollapse_section(#taskforce_output > threshold,taskforce_output,args.TF_HEADER or cfg.task_force.header)----------------------------- Notes ---------------------------------------------local note_output = {}local note_default_size = args.NOTE_SIZE or args.NOTE_1_SIZE or cfg.note.default_sizelocal render_note = function(note_args)--text, image_name, size, category, sort_prefixlocal sort = note_args.sort_prefix and note_args.sort_prefix .. current_title.textadd_category(note_args.category, sort)add_category(note_args.category2, sort)if note_args.text thenlocal note_image = image(note_args.image_name, note_args.size or note_default_size, cfg.note.icon_alt, 'center')local new_note = mw.html.create('tr'):tag('td'):css('background', note_args.background):wikitext(note_image):done():tag('td'):addClass('mbox-text'):attr('colspan', '2'):wikitext(note_args.text):done()table.insert(note_output, new_note)if note_image thenlocal icon = mw.html.create('span'):addClass('wpb-header-bubbles'):wikitext('[[File:' .. note_args.image_name .. '|' .. cfg.note.header_icon .. '|' .. note_args.text .. '|link=|alt=]]')table.insert(nested_ratings, tostring(icon))endendendlocal auto = falselocal auto_arg = args.auto and args.auto:lower()if (auto_arg=='yes' or auto_arg=='stub') and class=='Stub' thenauto = 'stub'elseif (auto_arg=='inherit' or auto_arg=='length') and class and class~='' thenauto = auto_argendif auto thenlocal auto_cat = args.AUTO_ASSESS_CAT or cfg.auto.default_cat:format(project)local auto_text = cfg.auto.assessed:format(pagetype,cfg.auto[auto], -- method of automatic assessmentparameter_format('auto'))local sort_prefixif auto=='stub' thensort_prefix = 'S'elseif auto=='length' thensort_prefix = 'L'elseif auto=='inherit' thenlocal sort_codes = cfg.auto.sort_codessort_prefix = sort_codes[class] or cfg.auto.default_sort_codeendrender_note{text = auto_text,image_name = cfg.auto.icon,category = auto_cat,sort_prefix = sort_prefix}endif yesno(args.attention, true) thenlocal attention_cat = args.ATTENTION_CAT or cfg.attention.default_cat:format(project)render_note{text = cfg.attention.text:format(pagetype),image_name = cfg.attention.icon,category = attention_cat}endif yesno(args.infobox, true) thenlocal infobox_cat = args.INFOBOX_CAT or cfg.infobox.default_cat:format(project)render_note{text = cfg.infobox.text:format(pagetype),image_name = cfg.infobox.icon,category = infobox_cat}endfor _, k in ipairs(notes) dolocal note_prefix = 'NOTE_' .. k .. '_'render_note{text = parse_text(args[note_prefix..'TEXT']),image_name = args[note_prefix..'IMAGE'],size = args[note_prefix..'SIZE'],category = args[note_prefix..'CAT']}endif yesno(args['image-needed'], true) thenlocal image_needed_args = require(cfg.auxiliary_module .. (sandbox or '')).image_needed(args, pagetype)render_note(image_needed_args)endif yesno(args['collaboration-candidate'], true) or yesno(args['collaboration-current'], true) or yesno(args['collaboration-past'], true) thenlocal collaboration_args = require(cfg.auxiliary_module .. (sandbox or '')).collaboration(args, pagetype, current_title)render_note(collaboration_args.candidate)render_note(collaboration_args.current)render_note(collaboration_args.past)endif yesno(args['a class'], true) thenlocal a_class_args = require(cfg.auxiliary_module .. (sandbox or '')).a_class(args, lang)render_note(a_class_args)endif yesno(args['peer review'], true) or yesno(args['old peer review'], true) thenlocal peer_review_args = require(cfg.auxiliary_module .. (sandbox or '')).peer_review(args, current_title)render_note(peer_review_args.current)render_note(peer_review_args.past)endlocal note_count = #note_outputif args.HOOK_NOTE thentable.insert(note_output, args.HOOK_NOTE)local hook_collapsed = 0if args.HOOK_COLLAPSED thenlocal success, result = pcall(mw.ext.ParserFunctions.expr, args.HOOK_COLLAPSED)hook_collapsed = success and tonumber(result) or 0if args.HOOK_COLLAPSED=='auto' thenhook_collapsed = 1endendnote_count = note_count + hook_collapsedendcollapse_section(note_count > (tonumber(args.COLLAPSED) or cfg.note.threshold),note_output,args.COLLAPSED_HEAD or cfg.note.header)----------------------------- Bottom text ---------------------------------------if args.HOOK_BOTTOM thentable.insert(rows, args.HOOK_BOTTOM)endif args.TODO_LINK or args.TODO_TEXT thenlocal todolist = require(cfg.auxiliary_module .. (sandbox or '')).todo_list(args, frame)table.insert(rows, todolist)endif args.BOTTOM_TEXT thenlocal bottom_text = mw.html.create('tr'):tag('td'):attr('colspan','3'):wikitext(parse_text(args.BOTTOM_TEXT)):done()table.insert(rows, bottom_text)endif args.MAIN_CAT thenadd_category(args.MAIN_CAT)end----------------------------- Nested display ------------------------------------if args.HOOK_NESTED thenlocal hook_nested = args.HOOK_NESTED:gsub('^&#32;/ ', '') -- remove initial slash, will be added latertable.insert(nested_tf, hook_nested)endlocal nested_tf_str = ''if #nested_tf>0 thennested_tf_str = tostring(mw.html.create('span'):css('font-weight', 'normal') --TODO: move to TemplateStyles.:wikitext(': ' .. table.concat(nested_tf, ' / ')))endlocal nested_ratings_str = #nested_ratings>0 and table.concat(nested_ratings, ' ') or ''if args.HOOK_NESTED_ASSESS thennested_ratings_str = nested_ratings_str .. tostring(mw.html.create('span'):addClass('wpb-header-bubbles'):wikitext(args.HOOK_NESTED_ASSESS))endlocal header_row = mw.html.create('tr'):addClass('wpb-header'):tag('td'):addClass('wpb-header-icon'):attr('width', '50px') --TODO: move to TemplateStyles.:css('text-align', 'center') --TODO: move to TemplateStyles.:wikitext(image(args.IMAGE_LEFT, cfg.image.header_size, cfg.image.alt)):done():tag('td'):addClass('wpb-header-combined'):wikitext(wikilink(project_link.prefixedText, project) .. nested_tf_str .. ' ' .. nested_ratings_str):done()----------------------------- Prepare categories --------------------------------local categories_formatted = ''if args.demo_page then -- for testing purposeslocal category_list = mw.html.create('ul')for _, cat in ipairs(categories) dolocal item = mw.html.create('li'):wikitext(wikilink(':Category:' .. cat.category, cat.category))category_list:node(item)endlocal category_box = mw.html.create('div'):css('background-color', '#F5F5F5'):css('border-width', '1px'):css('color', '#202122') --TODO: move to TemplateStyles.:css('width', '500px') --TODO: move to TemplateStyles.:wikitext('Categories:'):node(category_list)categories_formatted = tostring(category_box)elseif not demo thenlocal categories_linked = {}for _, cat in ipairs(categories) dolocal cat_link = wikilink('Category:' .. cat.category, cat.key)table.insert(categories_linked, cat_link)endcategories_formatted = table.concat(categories_linked)end----------------------------- Make banner ---------------------------------------local banner_rows = mw.html.create('table')for _, row in ipairs(rows) dobanner_rows:node(row)endlocal banner = mw.html.create('table'):addClass('tmbox tmbox-notice mw-collapsible innercollapse wpb'):addClass(inactive and cfg.status.inactive_class or nil):css('table-layout', 'fixed') --TODO: move to TemplateStyles.:node(header_row):tag('tr'):tag('td'):addClass('mbox-text wpb-main'):attr('colspan','2'):node(banner_rows):allDone()if args.listas thenframe:preprocess('{{DEFAULTSORT:' .. args.listas .. '}}')endlocal tstyle = frame:extensionTag ('templatestyles', '', {src='Module:Message box/tmbox.css'}) ..frame:extensionTag ('templatestyles', '', {src = 'Module:WikiProject banner' .. (sandbox or '') .. '/styles.css'})return warning .. tstyle .. tostring(banner) .. categories_formatted, note_count, #taskforce_output, assessment_linkendlocal parameter_check = function(frame, banner_name, project_name)----------------------------- Unknown parameters --------------------------------local parent_args = args_module.getArgs(frame, {parentOnly = true})local parameters = {}for parameter in banner_name:getContent():gmatch('{{{([^|}]+)') dotable.insert(parameters, parameter)endparameters.preview = cfg.unknown_parameters.preview:format(wikilink(banner_name.fullText))local unknown_category = cfg.unknown_parameters.tracking:format(project_name)if not mw.title.new(unknown_category).exists thenunknown_category = cfg.unknown_parameters.defaultendparameters.unknown = unknown_category and '[[' .. unknown_category .. '|_VALUE_]]' or ''return require('Module:Check for unknown parameters')._check(parameters, parent_args)endlocal initialise = function(args, raw_args, inactive_status)args.demo_page = args_module.getArgs(frame, {parentOnly = true}).demo_pagelocal project_name = args.PROJECT_NAME or 'WikiProject ' .. (args.PROJECT or 'PROJECT')local banner_name = mw.title.new(args.BANNER_NAME or 'Template:WikiProject ' .. (args.PROJECT or 'PROJECT'))local demo = not yesno(args.category or true, true) or args.demo_pagelocal on_template_page = not demo and current_title.rootPageTitle==banner_name.rootPageTitlelocal unknown_parameters = banner_name.exists and not demo and parameter_check(frame, banner_name, project_name) or ''if on_template_page thenlocal templatepage = require('Module:WikiProject banner/templatepage' .. (sandbox or '')).templatepagereturn templatepage(args, raw_args, inactive_status)elsereturn unknown_parameters.. p._main(args, raw_args, demo or inactive_status, banner_name, inactive_status and true or false), nil -- nil to disregard subsequent returned valuesendendp.main = function(frame)local args = args_module.getArgs(frame, {frameOnly = true})local raw_args = args_module.getArgs(frame, {frameOnly = true, removeBlanks = false})return initialise(args, raw_args)end----------------------------- Inactive projects ---------------------------------p.inactive = function(frame)local args = args_module.getArgs(frame, {frameOnly = true})local project_name = args.PROJECT_NAME or 'WikiProject ' .. (args.PROJECT or 'PROJECT')local project_link = mw.title.new(args.PROJECT_LINK or 'Wikipedia:' .. project_name)local _status = cfg.status[args.PROJECT_STATUS] or cfg.status.default_inactivelocal main_text = cfg.inactive.text:format('_PAGETYPE_',project_link.prefixedText,project_name,_status)return initialise({PROJECT = args.PROJECT,BANNER_NAME = args.BANNER_NAME,IMAGE_LEFT = cfg.inactive.image,IMAGE_LEFT_SIZE = cfg.inactive.image_size,MAIN_TEXT = main_text,HOOK_NESTED_ASSESS = ' ' .. cfg.inactive.nested:format(_status),substcheck = args.substcheck,category = args.category},{class = frame.args.class,substcheck = '' -- to prevent warning on templatepage},_status)endreturn p