Module:Used in system
From Neodyland Wiki
More actions
This documentation is transcluded from Module:Used in system/doc.
local p = {}
local _fetch = require('Module:Transclusion_count').fetch
local yesno = require('Module:Yesno')
local function get_arg(frame, key)
local args = frame.args or {}
local parentArgs = frame:getParent() and frame:getParent().args or {}
if args[key] and args[key] ~= '' then return args[key] end
if parentArgs[key] and parentArgs[key] ~= '' then return parentArgs[key] end
return nil
end
local function get_box_config(frame, count)
local custom_image = get_arg(frame, 'image')
local custom_type = get_arg(frame, 'type')
local threshold = tonumber(get_arg(frame, 'threshold')) or 100000
local category = get_arg(frame, 'category') or 'Pages used in system messages needing protection'
local system_param = get_arg(frame, 'system')
local image_filename = "OOjs UI icon notice-warning.svg"
local type_param = custom_type or "content"
local is_system = (system_param ~= nil and system_param ~= '')
local arg1 = get_arg(frame, 1)
local is_high_risk = (arg1 == "risk" or (count and count >= threshold))
if is_system then
image_filename = "OOjs UI icon notice-warning.svg"
type_param = custom_type or "content"
elseif is_high_risk then
image_filename = "OOjs UI icon alert-warning.svg"
type_param = custom_type or "content"
end
local image = custom_image
if not image or image == '' then
image = string.format("[[File:%s|40px|alt=Warning|link=]]", image_filename)
end
local epilogue = ''
if is_system then
local nocat = get_arg(frame, 'nocat')
local categorise = (nocat == nil or not yesno(nocat))
if categorise and not mw.title.getCurrentTitle().isRedirect then
epilogue = frame:preprocess(string.format(
'{{Sandbox other||{{#switch:{{#invoke:Effective protection level|{{#switch:{{NAMESPACE}}|File=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|templateeditor|interfaceadmin=|#default=[[Category:%s]]}}}}',
category
))
end
end
return image, type_param, epilogue
end
function p.num(frame, count)
local args = frame.args or {}
if count == nil then
if yesno(args['fetch']) == false or yesno(get_arg(frame, 'fetch')) == false then
local arg1 = get_arg(frame, 1)
if arg1 and arg1 ~= '' then
count = tonumber(arg1)
end
else
count = _fetch(frame)
end
end
if count == nil then
if get_arg(frame, 1) == "risk" then
return ""
else
return "unknown"
end
else
local sigfig = (count >= 100000) and 3 or 2
local f = math.floor(math.log10(count)) - sigfig + 1
local return_value = ""
local arg1 = get_arg(frame, 1) or ''
local arg2 = get_arg(frame, 2) or ''
if (arg2 == "yes") or (mw.ustring.sub(arg1, -1) == "+") then
return_value = string.format("%s+", mw.getContentLanguage():formatNum(math.floor((count / 10 ^ f)) * (10 ^ f)))
else
return_value = string.format("approximately %s", mw.getContentLanguage():formatNum(math.floor((count / 10 ^ f) + 0.5) * (10 ^ f)))
end
local no_percent = get_arg(frame, 'no-percent')
if count and count > 250000 and not yesno(no_percent) then
local percent = math.floor(((count / frame:callParserFunction('NUMBEROFPAGES', 'R')) * 100) + 0.5)
if percent >= 1 then
return_value = string.format("%s pages, or roughly %s%% of all", return_value, percent)
end
end
return return_value
end
end
function p.image(frame)
local count = _fetch(frame)
local image, _, _ = get_box_config(frame, count)
return image
end
function p.epilogue(frame)
local count = _fetch(frame)
local _, _, epilogue = get_box_config(frame, count)
return epilogue
end
function p.main(frame)
local args = frame.args or {}
local count = nil
if yesno(args['fetch']) == false or yesno(get_arg(frame, 'fetch')) == false then
local arg1 = get_arg(frame, 1)
if arg1 and arg1 ~= '' then count = tonumber(arg1) end
else
count = _fetch(frame)
end
local image, type_param, epilogue = get_box_config(frame, count)
local localized_text = frame:expandTemplate{
title = 'Autotranslate',
args = {
base = 'Used in system',
count = count and p.num(frame, count) or nil,
msg = get_arg(frame, 'msg') or get_arg(frame, 1),
system = get_arg(frame, 'system')
}
}
local expiry = get_arg(frame, 'expiry') or ''
if args["form"] == "editnotice" or get_arg(frame, "form") == "editnotice" then
return frame:expandTemplate{
title = 'editnotice',
args = {
["image"] = image,
["text"] = localized_text,
["expiry"] = expiry
}
} .. epilogue
else
return require('Module:Message box').main('ombox', {
type = type_param,
image = image,
text = localized_text,
expiry = expiry
}) .. epilogue
end
end
return p