Jump to content

Module:WikiProject banner and Module:WikiProject banner/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
m Text replacement - "BattleTechWiki" to "BattleIntelligence"
 
m Text replacement - "BattleTechWiki" to "BattleIntelligence"
 
Line 1: Line 1:
require('strict')
require('strict')
local p = {}
local p = {}
local sandbox-- = '/sandbox'
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 cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or ''))
local auxiliary = cfg.auxiliary_module .. (sandbox or '')
local auxiliary = cfg.auxiliary_module .. (sandbox or '')
Line 57: Line 57:
end
end


local importance_mask = function(raw_importance, scale, banner_name, pagetype)
local importance_mask = function(raw_importance, scale, banner_name, pagetype, class)
---------------------------
---------------------------
-- Importance mask --------
-- Importance mask --------
Line 71: Line 71:
args = {
args = {
importance = raw_importance or '¬',
importance = raw_importance or '¬',
class = class,
pagetype = pagetype
pagetype = pagetype
}
}
Line 77: Line 78:
elseif raw_importance then-- standard importance scale
elseif raw_importance then-- standard importance scale
importance = cfg.importance.na
importance = cfg.importance.na
if pagetype=='article' or pagetype=='redirect' or pagetype=='draft' then
if pagetype=='article' or pagetype=='set index article' or pagetype=='redirect' or pagetype=='draft' then
local mask = cfg.importance.mask
local mask = cfg.importance.mask
if mask[raw_importance:lower()] then -- valid importance specified
if mask[raw_importance:lower()] then -- valid importance specified
importance = mask[raw_importance:lower()]
importance = mask[raw_importance:lower()]
elseif pagetype=='article' then -- unspecified or invalid importance, use "Unknown" for articles
elseif pagetype=='article' or pagetype=='set index article' then -- unspecified or invalid importance, use "Unknown" for articles
importance = cfg.importance.unknown
importance = cfg.importance.unknown
end
end
Line 113: Line 114:
elseif pagetype=='disambiguation page' then
elseif pagetype=='disambiguation page' then
out = resolveFQSgrade('disambig')
out = resolveFQSgrade('disambig')
elseif pagetype=='set index article' then
out = 'List'
elseif pagetype=='article' then
elseif pagetype=='article' then
if class=='start' or class=='stub' then -- Ucfirst
if class=='start' or class=='stub' then -- Ucfirst
Line 159: Line 162:
local pagetype = demo_page==true and 'article' or require('Module:Pagetype')._main({
local pagetype = demo_page==true and 'article' or require('Module:Pagetype')._main({
page = demo_page,
page = demo_page,
dab = 'disambiguation page'
dab = 'disambiguation page',
sia = 'set index article'
})
})
local rows, nested_ratings, task_forces, notes, categories, taskforce_categories = {}, {}, {}, {}, {}, {}
local rows, nested_ratings, task_forces, notes, categories, taskforce_categories = {}, {}, {}, {}, {}, {}
Line 167: Line 171:
end
end
end
end
local parse_text = function(text)
local parse_pt = function(text) -- function to replace _PAGETYPE_ with the actual page type
return text and text:gsub('_PAGETYPE_', pagetype)
local ptype = pagetype=='set index article' and 'article' or pagetype -- display "article" instead of "set index article"
return text and text:gsub('_PAGETYPE_', ptype)
end
end
for arg_name, arg_value in pairs(args) do
for arg_name, arg_value in pairs(args) do
Line 196: Line 201:
if show_namespace_warning then
if show_namespace_warning then
local text = cfg.namespace_warning.text:format(
local text = cfg.namespace_warning.text:format(
pagetype,
current_title.talkPageTitle.fullText,
current_title.talkPageTitle.fullText,
parameter_format('category', 'no')
parameter_format('category', 'no')
Line 210: Line 214:
image = '[[File:' .. cfg.namespace_warning.image .. '|40px]]',
image = '[[File:' .. cfg.namespace_warning.image .. '|40px]]',
type = cfg.namespace_warning.type_,
type = cfg.namespace_warning.type_,
text = text
text = parse_pt(text)
})
})
if not current_title.subjectPageTitle:inNamespace(2) then
if not current_title.subjectPageTitle:inNamespace(2) then
Line 246: Line 250:
local portal = args.PORTAL
local portal = args.PORTAL
local portal_box = portal and frame:expandTemplate{title='Portal', args={portal}} or ''
local 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(
local main_text = portal_box .. parse_pt(args.MAIN_TEXT or cfg.main_text:format(
pagetype,
project_link.prefixedText,
project_link.prefixedText,
project_name,
project_name,
Line 300: Line 303:
end
end
else -- no banner shell on page
else -- no banner shell on page
if pagetype=='article' then
if pagetype=='article' or pagetype=='set index article' then
add_category(cfg.banner_shell.category.no_banner_shell_articles)
add_category(cfg.banner_shell.category.no_banner_shell_articles)
elseif title.namespace==3 then --User talk namespace
elseif title.namespace==3 then --User talk namespace
Line 308: Line 311:
end
end
end
end
else
elseif title.namespace~=2 then --User namespace
add_category(cfg.banner_shell.category.no_banner_shell)
add_category(cfg.banner_shell.category.no_banner_shell)
end
end
Line 392: Line 395:
class = 'NA' -- automatically use NA for non-article pages if category does not exist
class = 'NA' -- automatically use NA for non-article pages if category does not exist
end
end
--if raw_args.class~='' and args.QUALITY_CRITERIA~='custom' then
-- add_category(cfg.banner_shell.category.redundant_class)
--end
end
end
local category = (class=='' and 'Unassessed' or class..'-Class') .. ' ' .. assessment_cat
local category = (class=='' and 'Unassessed' or class..'-Class') .. ' ' .. assessment_cat
if show_quality then -- quality rating shown in banner
if show_quality then -- quality rating shown in banner
local rating
local rating
if pagetype=='article' then
if pagetype=='article' or pagetype=='set index article' then
rating = class=='' and cfg.quality.not_yet or cfg.quality.rated:format(class)
rating = class=='' and cfg.quality.not_yet or cfg.quality.rated:format(class)
else
else
Line 406: Line 412:
or cfg.quality.default_scale
or cfg.quality.default_scale
local quality_rating = conflict
local quality_rating = conflict
and cfg.banner_shell.conflict.text:format(pagetype)
and cfg.banner_shell.conflict.text
or cfg.quality.rating:format(pagetype, rating, scale)
or cfg.quality.rating:format(rating, scale)
local cssClass = 'class-' .. (class=='' and 'unassessed' or class:lower())
local cssClass = 'class-' .. (class=='' and 'unassessed' or class:lower())
local class_row =  mw.html.create('tr')
local class_row =  mw.html.create('tr')
Line 419: Line 425:
:addClass('mbox-text')
:addClass('mbox-text')
:attr('colspan', '2')
:attr('colspan', '2')
:wikitext(quality_rating)
:wikitext(parse_pt(quality_rating))
:done()
:done()
table.insert(rows, class_row)
table.insert(rows, class_row)
Line 440: Line 446:
-- Importance assessment --
-- Importance assessment --
---------------------------
---------------------------
local importance = importance_mask(raw_args.importance or raw_args.priority, args.IMPORTANCE_SCALE, banner_name, pagetype)
local importance = importance_mask(raw_args.importance or raw_args.priority, args.IMPORTANCE_SCALE, banner_name, pagetype, class)
local importance_name = args.IMPN or (raw_args.priority and 'priority' or cfg.importance.default_name)
local importance_name = args.IMPN or (raw_args.priority and 'priority' or cfg.importance.default_name)
if importance then -- banner gives importance ratings
if importance then -- banner gives importance ratings
Line 450: Line 456:
and cfg.importance.project_scale:format(assessment_link..'#'..lang:ucfirst(scale_name), scale_name)
and cfg.importance.project_scale:format(assessment_link..'#'..lang:ucfirst(scale_name), scale_name)
or cfg.importance.default_scale
or cfg.importance.default_scale
local importance_rating = cfg.importance.rating:format(pagetype, rating, scale)
local importance_rating = parse_pt(cfg.importance.rating:format(rating, scale))
local cssClass = 'import-' .. importance:lower()
local cssClass = 'import-' .. importance:lower()
local importance_row =  mw.html.create('tr')
local importance_row =  mw.html.create('tr')
Line 532: Line 538:
local tf_importance
local tf_importance
if raw_args['tf '..k..' importance'] then
if raw_args['tf '..k..' importance'] then
tf_importance = importance_mask(raw_args['tf '..k..' importance'], args.IMPORTANCE_SCALE, banner_name, pagetype)
tf_importance = importance_mask(raw_args['tf '..k..' importance'], args.IMPORTANCE_SCALE, banner_name, pagetype, class)
if tf_importance=='Unknown' and yesno(args.INHERIT_IMPORTANCE) then
if tf_importance=='Unknown' and yesno(args.INHERIT_IMPORTANCE) then
tf_importance = importance
tf_importance = importance
Line 549: Line 555:
:gsub('_LINK_', args[tf_prefix .. 'LINK'] or '')
:gsub('_LINK_', args[tf_prefix .. 'LINK'] or '')
:gsub('_IMPORTANCE_', tf_importance or '')
:gsub('_IMPORTANCE_', tf_importance or '')
:gsub('_PAGETYPE_', pagetype)
else
else
local tf_importance_text = tf_importance
local tf_importance_text = tf_importance
Line 558: Line 563:
) or ''
) or ''
text = portal .. cfg.task_force.text:format(
text = portal .. cfg.task_force.text:format(
pagetype,
wikilink(args[tf_prefix .. 'LINK'], args[tf_prefix .. 'NAME']),
wikilink(args[tf_prefix .. 'LINK'], args[tf_prefix .. 'NAME']),
tf_importance_text
tf_importance_text
Line 575: Line 579:
:addClass('mbox-text')
:addClass('mbox-text')
:attr('colspan','2')
:attr('colspan','2')
:wikitext(text)
:wikitext(parse_pt(text))
:done()
:done()
table.insert(taskforce_output, taskforce)
table.insert(taskforce_output, taskforce)
Line 624: Line 628:
add_category(note_args.category2, sort)
add_category(note_args.category2, sort)
if note_args.text then
if note_args.text then
local note_image = image(note_args.image_name, note_args.size or note_default_size, cfg.note.icon_alt, 'center')
local 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')
local new_note = mw.html.create('tr')
:tag('td')
:tag('td')
Line 633: Line 642:
:addClass('mbox-text')
:addClass('mbox-text')
:attr('colspan', '2')
:attr('colspan', '2')
:wikitext(note_args.text)
:wikitext(parse_pt(note_args.text))
:done()
:done()
table.insert(note_output, new_note)
table.insert(note_output, new_note)
Line 639: Line 648:
local icon = mw.html.create('span')
local icon = mw.html.create('span')
:addClass('wpb-header-bubbles')
:addClass('wpb-header-bubbles')
:wikitext('[[File:' .. note_args.image_name .. '|' .. cfg.note.header_icon .. '|' .. note_args.text .. '|link=|alt=]]')
:wikitext('[[File:' .. note_args.image_name .. '|' .. cfg.note.header_icon .. '|' .. parse_pt(note_args.text) .. '|link=|alt=]]')
table.insert(nested_ratings, tostring(icon))
table.insert(nested_ratings, tostring(icon))
end
end
Line 654: Line 663:
local auto_cat = args.AUTO_ASSESS_CAT or cfg.auto.default_cat:format(project)
local auto_cat = args.AUTO_ASSESS_CAT or cfg.auto.default_cat:format(project)
local auto_text = cfg.auto.assessed:format(
local auto_text = cfg.auto.assessed:format(
pagetype,
cfg.auto[auto], -- method of automatic assessment
cfg.auto[auto], -- method of automatic assessment
parameter_format('auto')
parameter_format('auto')
Line 677: Line 685:
local attention_cat = args.ATTENTION_CAT or cfg.attention.default_cat:format(project)
local attention_cat = args.ATTENTION_CAT or cfg.attention.default_cat:format(project)
render_note{
render_note{
text = cfg.attention.text:format(pagetype),
text = cfg.attention.text,
image_name = cfg.attention.icon,
image_name = cfg.attention.icon,
category = attention_cat
category = attention_cat
Line 685: Line 693:
local infobox_cat = args.INFOBOX_CAT or cfg.infobox.default_cat:format(project)
local infobox_cat = args.INFOBOX_CAT or cfg.infobox.default_cat:format(project)
render_note{
render_note{
text = cfg.infobox.text:format(pagetype),
text = cfg.infobox.text,
image_name = cfg.infobox.icon,
image_name = cfg.infobox.icon,
category = infobox_cat
category = infobox_cat
Line 693: Line 701:
local note_prefix = 'NOTE_' .. k .. '_'
local note_prefix = 'NOTE_' .. k .. '_'
render_note{
render_note{
text = parse_text(args[note_prefix..'TEXT']),
text = parse_pt(args[note_prefix..'TEXT']),
image_name = args[note_prefix..'IMAGE'],
image_name = args[note_prefix..'IMAGE'],
size = args[note_prefix..'SIZE'],
size = args[note_prefix..'SIZE'],
Line 700: Line 708:
end
end
if yesno(args['image-needed'], true) then
if yesno(args['image-needed'], true) then
local image_needed_args = require(auxiliary).image_needed(args, pagetype)
local image_needed_args = require(auxiliary).image_needed(args)
render_note(image_needed_args)
render_note(image_needed_args)
end
end
if yesno(args['collaboration-candidate'], true) or yesno(args['collaboration-current'], true) or yesno(args['collaboration-past'], true) then
if yesno(args['collaboration-candidate'], true) or yesno(args['collaboration-current'], true) or yesno(args['collaboration-past'], true) then
local collaboration_args = require(auxiliary).collaboration(args, pagetype, current_title)
local collaboration_args = require(auxiliary).collaboration(args, current_title)
render_note(collaboration_args.candidate)
render_note(collaboration_args.candidate)
render_note(collaboration_args.current)
render_note(collaboration_args.current)
Line 751: Line 759:
:tag('td')
:tag('td')
:attr('colspan','3')
:attr('colspan','3')
:wikitext(parse_text(args.BOTTOM_TEXT))
:wikitext(parse_pt(args.BOTTOM_TEXT))
:done()
:done()
table.insert(rows, bottom_text)
table.insert(rows, bottom_text)
Line 802: Line 810:
)
)
if success and shell_listas_value~='' then
if success and shell_listas_value~='' then
if args.listas==shell_listas_value then-- same value in both (with spacing trimming)
if args.listas==shell_listas_value then -- same value in both (with spacing trimming)
add_category('WikiProject banners with redundant listas value')
add_category(cfg.banner_shell.category.redundant_listas)
end
end
else-- listas is blank or not defined in banner shell
else -- listas is blank or not defined in banner shell
add_category('WikiProject banners with listas value which needs moving to banner shell')
add_category(cfg.banner_shell.category.move_listas)
end
end
end
end
Line 843: Line 851:
local banner = mw.html.create('table')
local banner = mw.html.create('table')
:addClass('tmbox tmbox-notice mw-collapsible innercollapse wpb wpb-table')
:addClass('tmbox tmbox-notice mw-collapsible innercollapse wpb wpb-table')
:addClass(inactive and cfg.status.inactive_class or nil)
:addClass(inactive and cfg.inactive.class or nil)
:node(header_row)
:node(header_row)
:tag('tr')
:tag('tr')
Line 912: Line 920:
local project_name = args.PROJECT_NAME or 'WikiProject ' .. (args.PROJECT or 'PROJECT')
local project_name = args.PROJECT_NAME or 'WikiProject ' .. (args.PROJECT or 'PROJECT')
local project_link = mw.title.new(args.PROJECT_LINK or 'BattleIntelligence:' .. project_name)
local project_link = mw.title.new(args.PROJECT_LINK or 'BattleIntelligence:' .. project_name)
local _status = cfg.status[args.PROJECT_STATUS] or cfg.status.default_inactive
local _status = cfg.inactive.status[args.PROJECT_STATUS] or cfg.inactive.default
local main_text = cfg.inactive.text:format(
local main_text = cfg.inactive.text:format(
'_PAGETYPE_',
project_link.prefixedText,
project_link.prefixedText,
project_name,
project_name,