Module:WikiProject banner/auxiliary/sandbox
Appearance
From Wikipedia, the free encyclopedia
Beta This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected.
[画像:Protected] 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.
Warning This Lua module is used on approximately 3,970,000 pages, or roughly 6% 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.
WikiProject banners |
---|
Module |
Template:WPBannerMeta |
Config |
Styles |
Auxiliary |
templatepage |
Category (errors) |
This module depends on the following other modules:
This module contains extra functions not frequently used by Module:WikiProject banner to support the following features:
- B-class checklist
- To-do list
- Assessment category intersection
- Image-needed note
- Collaboration note
- A-class review note
- Peer review note
The above documentation is transcluded from Module:WikiProject banner/auxiliary/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
require('strict') local p = {} local sandbox = '/sandbox' -- BE SURE TO COMMENT OUT this definition when deploying to live local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or '')) local yesno = require('Module:Yesno') local lang = mw.getLanguage(cfg.language) p.b_checklist = function(args, raw_args, class, demo, assessment_link) --------------------------- -- B-class checklist ------ --------------------------- local show_checklist = false local parameters_used = args.b1 or args.b2 or args.b3 or args.b4 or args.b5 or args.b6 if (class=='B' or class=='C' or class=='BL' or class=='CL')-- always displayed on C or B or ((class=='Start' or class=='List') and yesno(args.B_DISPLAY_ON_START))-- show on Start/List if option selected or ((class=='Start' or class=='Stub') and parameters_used) then-- show on Start or Stub if any parameters used show_checklist = true end if show_checklist then local scale = args.QUALITY_CRITERIA=='custom' and assessment_link and assessment_link..'#'..lang:ucfirst(cfg.quality.name) or cfg.b_checklist.default_scale local text = cfg.b_checklist.text:format( parameters_used and cfg.b_checklist.checked or cfg.b_checklist.not_checked, scale ) local syntax = {} local criteria = mw.html.create('ol') for i = 1, 6 do local b = raw_args['b'..i] if b and b~='unused' then -- crtierion in use b = cfg.b_checklist.mask[b:lower()] or cfg.b_checklist.mask.default local image = '[[File:' .. cfg.b_checklist.icon[b] .. '.svg|16x16px|link=|alt=]]' local failed_cat = args['B'..i..'_CAT'] local category = '' if b~='y' and b~='x' and failed_cat and not demo then -- criterion failed category = '[[Category:' .. failed_cat .. ']]' end if (b=='u' or b=='i') and args.B_MAIN_CAT and not demo then -- unevaluated or invalid parameter category = category .. '[[Category:' .. args.B_MAIN_CAT .. ']]' end local _status = mw.html.create('span') :css('font-style', 'italic') :wikitext(cfg.b_checklist.status[b]) local criterion = mw.html.create('li') :wikitext(image .. ' ' .. cfg.b_checklist.criteria[i] .. ': ') :node(_status) :wikitext(category) criteria:node(criterion) local new_syntax = mw.html.create('li') :addClass('nowrap') :wikitext(cfg.b_checklist.syntax.prompt:format( tostring(i), cfg.b_checklist.criteria[i] .. string.rep( ' ', cfg.b_checklist.syntax.max_width-#cfg.b_checklist.criteria[i] ) )) table.insert(syntax, tostring(new_syntax)) end end local prompt if not parameters_used then local list = mw.html.create('ul)') :css('font-size', '88%') :css('margin', '0px') :css('font-family', 'monospace, sans-serif') :css('padding', '1em') :css('border', '1px dashed #2f6fab') :css('background-color', '#f9f9f9') :css('line-height', '1.1em') :css('list-style', 'none') :node(table.concat(syntax)) prompt = mw.html.create('span') :wikitext(cfg.b_checklist.syntax.text:format(tostring(mw.title.getCurrentTitle():fullUrl({action = 'edit'})))) :node(list) :wikitext(cfg.b_checklist.syntax.assess) end local image = mw.html.create('td') :addClass('assess-b') :css('padding-bottom', '5px') :wikitext(cfg.b_checklist.image) local checklist_table = mw.html.create('table') :addClass('plainlinks mw-collapsible mw-collapsed') :tag('tr') :tag('th') :addClass('wpb-collapsed-head mbox-text') :attr('colspan', '3') :css('font-weight', 'normal') :wikitext(text) :done() :tag('td') :css('min-width', '3em') :done() -- empty cell for show/hide toggle :done() :tag('tr') :tag('td') :css('font-size', '90%') :node(criteria) :done() :tag('td') :css('font-size', '88%') :node(prompt) :done() :tag('td') :addClass('empty-cell') :done() :done() local checklist = mw.html.create('tr') :node(image) :tag('td') :addClass('wpb-collapsed-notes') :node(checklist_table) return checklist end end p.todo_list = function(args, frame) --------------------------- -- To-do list ------------- --------------------------- local list if args.TODO_LINK then local link = function(action) local url = mw.uri.fullUrl(args.TODO_LINK, {action = action}) return mw.html.create('li'):wikitext('[' .. tostring(url) .. ' ' .. cfg.todo_list[action] .. ']') end local links = yesno(args.TODO_EDITLINKS or true, 'true') and frame:expandTemplate{title = 'Flatlist', args = { class = 'plainlinks', style = 'text-align:center;font-size:90%;', [1] = tostring(mw.html.create('ul') :node(link('edit')) :node(link('history')) :node(link('watch')) :node(link('purge')) ) }} or '' list = links .. '\n' .. frame:expandTemplate{title = args.TODO_LINK} else list = ('\n' .. args.TODO_TEXT) or '' end local title = mw.html.create('div') :css('padding', '0.2em 2px 0.2em 0') --TODO add to styles.css :css('font-weight', 'bold') :wikitext((args.TODO_TITLE or cfg.todo_list.default_title) .. ':') local content = mw.html.create('div') :addClass('mw-collapsible-content') :css('padding', '5px') :css('background-color', 'var(--background-color-base, #fff)') :css('color', 'inherit') :css('border', '1px solid #c0c090') :css('margin-top', '5px') :wikitext(list) local todo_list = mw.html.create('tr') :tag('td') :attr('colspan', '3') :css('padding', '0') :tag('div') :addClass('mw-collapsible mw-collapsed') :node(title) :node(content) :allDone() return todo_list end p.todo_list_ = function(frame) return p.todo_list(frame.args, frame) end p.quality_importance_insection = function(args, class, importance, importance_name, assessment_cat, article, tf_prefix) --------------------------- -- Category intersection -- --------------------------- local prefix = tf_prefix or '' if class=='NA' and (yesno(args[prefix..'QII_SUPPRESS_NA']) or yesno(args[prefix..'QII_SUPPRESS_NA_CLASS'])) then return nil end if importance=='NA' and (yesno(args[prefix..'QII_SUPPRESS_NA']) or yesno(args[prefix..'QII_SUPPRESS_NA_IMPORTANCE'])) then return nil end local form = args[prefix..'QII_FORMAT']:gsub('C', '_C_'):gsub('I', '_I_'):gsub('T', '_T_') if not class or not importance or not form then return nil end local new_class if class=='' then new_class = 'Unassessed' .. (args[prefix..'QII_UNASSESSED_APPENDIX'] or '') else new_class = class .. '-Class' end local check_cat = function (typ) local cat_name = form:gsub('_C_', new_class):gsub('_I_', importance .. '-' .. importance_name):gsub('_T_', assessment_cat .. ' ' .. typ) local cat = mw.title.new('Category:' .. cat_name) return cat.exists and #cat:getContent()>0 and cat_name end local cat if not article then cat = check_cat('pages') end if not cat then cat = check_cat('articles') end return cat end p.image_needed = function(args) --------------------------- -- Image needed ----------- --------------------------- local type = cfg.image_needed.default_type if args['image-type'] then local add_article = function(word) local article = cfg.image_needed.article.consonant if cfg.image_needed.vowels[word:sub(1, 1)] then article = cfg.image_needed.article.vowel end return article .. ' <b>' .. word .. '</b>' end type = add_article(args['image-type']) end local details = '' if args['image-details'] then details = ' ' .. cfg.image_needed.details:format(args['image-details']) end local location = '' if args['image-location'] then local location_cat = mw.title.new('Category:Wikipedians in ' .. args['image-location']) if location_cat.exists then location = ' ' .. cfg.image_needed.help:format('[[:' .. location_cat.fullText .. '|' .. location_cat.text .. ']]') end end local category_exists = function(category) local title = mw.title.new('Category:' .. category) if title.exists then return category end end return { text = cfg.image_needed.text:format(type, details, location), image_name = args.IM_IMAGE or cfg.image_needed.default_image, category = args['image-location'] and category_exists( cfg.image_needed.location:format( args['image-type'] or 'photograph', args['image-location'] ) ) or args.IM_LOCATION_CATEGORY, category2 = args['image-topic'] and category_exists( cfg.image_needed.topic:format( args['image-type'] or 'photograph', args['image-topic'] ) ) or args.IM_TOPIC_CATEGORY } end p.collaboration = function(args, title) --------------------------- -- Collaboration ---------- --------------------------- local image = args.COLL_IMAGE or cfg.collaboration.default_image local link = '[[' .. (args.COLL_LINK or '') .. '|' .. (args.COLL_TEXT or cfg.collaboration.default_text) .. ']]' local note_args = {candidate = {}, current = {}, past = {}} if yesno(args['collaboration-candidate'], true) then local subpage_link = (args.COLL_LINK or '') .. '#' .. title.subjectPageTitle.text note_args.candidate = { text = cfg.collaboration.candidate:format(subpage_link, link), image_name = image, size = cfg.collaboration.size, category = args.COLL_CANDIDATE_CAT } end if yesno(args['collaboration-current'], true) then note_args.current = { text = cfg.collaboration.current:format(link), image_name = image, size = cfg.collaboration.size, category = args.COLL_CURRENT_CAT } end if yesno(args['collaboration-past'], true) then note_args.past = { text = cfg.collaboration.past:format(link), image_name = image, size = cfg.collaboration.size, category = args.COLL_PAST_CAT } end return note_args end p.a_class = function(args, lang) --------------------------- -- A-class review --------- --------------------------- local status = cfg.a_class.mask[lang:lc(args['a class'])] if status==nil then return {} end local link_exists = args.ACR_SUBPAGE_LINK and mw.title.new(args.ACR_SUBPAGE_LINK).exists or false local link = mw.html.create('span'):css('font-weight', 'bold') local label = cfg.a_class.status[status] if args.ACR_SUBPAGE_LINK and status=='current' and not link_exists and args.ACR_PRELOAD then -- use custom preload template when creating discussion page local url = mw.uri.fullUrl(args.ACR_SUBPAGE_LINK, { action = 'edit', preload = args.ACR_PRELOAD, summary = cfg.a_class.create_summary }) link:wikitext('[' .. tostring(url) .. ' ' .. label .. ']') else link:wikitext('[[' .. (args.ACR_SUBPAGE_LINK or '') .. '|' .. label .. ']]') end return { text = cfg.a_class.text:format( tostring(link), args.ACR_REVIEW_LINK or '' ), image_name = args.ACR_IMAGE or cfg.a_class.icon[status], size = args.ACR_SIZE or '18x18px', background = cfg.a_class.background, category = args[cfg.a_class.category[status]], category2 = not link_exists and args.ACR_INVALID_CAT } end p.peer_review = function(args, title) --------------------------- -- Peer review ------------ --------------------------- local image = args.PR_IMAGE or cfg.peer_review.default_image local size = args.PR_SIZE or cfg.peer_review.size local link = args.PR_LINK or '' local pr_title = args['peer review title'] and mw.title.new(args['peer review title']) or title local subpage_link = link .. '/' .. pr_title.subjectPageTitle.text local invalid_cat = not mw.title.new(subpage_link).exists and args.PR_INVALID_CAT local note_args = {current = {}, past = {}} if yesno(args['peer review'], true) then note_args.current = { text = cfg.peer_review.current:format(subpage_link, link), image_name = image, size = size, category = args.PR_CAT, category2 = invalid_cat } end if yesno(args['old peer review'], true) then note_args.past = { text = cfg.peer_review.past:format(link, subpage_link), image_name = image, size = size, category = args.PR_OLD_CAT, category2 = invalid_cat } end return note_args end return p