Module:Used in system: Difference between revisions
From Neodyland Wiki
More actions
←Created page with 'function p.num(frame, count) end function p.image(frame) if frame.args['system'] and frame.args['system'] ~= '' then return "40px|alt=Warning|link=" elseif (frame.args[1] == "risk" or (_fetch(frame) and _fetch(frame) >= 100000)) then return "40px|alt=Warning|link=" end return "[[File:OOjs UI icon alert-yellow.svg|40px|alt=War...' |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | |||
local _fetch = require('Module:Transclusion_count').fetch | |||
local yesno = require('Module:Yesno') | |||
function p.num(frame, count) | function p.num(frame, count) | ||
local args = frame.args | |||
local parentArgs = frame:getParent() and frame:getParent().args or {} | |||
if count == nil then | |||
if yesno(args['fetch']) == false then | |||
if (args[1] or '') ~= '' then | |||
count = tonumber(args[1]) | |||
end | |||
else | |||
count = _fetch(frame) | |||
end | |||
end | |||
if count == nil then | |||
if args[1] == "risk" then | |||
return "a very large number of" | |||
else | |||
return "many" | |||
end | |||
else | |||
local sigfig = 2 | |||
if count >= 100000 then | |||
sigfig = 3 | |||
end | |||
local f = math.floor(math.log10(count)) - sigfig + 1 | |||
local return_value = "" | |||
if (args[2] == "yes") or (mw.ustring.sub(args[1] or '', -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 | |||
if count and count > 250000 and not yesno(parentArgs['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 | end | ||
function p.image(frame) | function p.image(frame) | ||
local args = frame.args | |||
if args['system'] and args['system'] ~= '' then | |||
return "[[File:OOjs UI icon notice-warning.svg|40px|alt=Warning|link=]]" | return "[[File:OOjs UI icon notice-warning.svg|40px|alt=Warning|link=]]" | ||
end | |||
local count = _fetch(frame) | |||
if args[1] == "risk" or (count and count >= 100000) then | |||
return "[[File:OOjs UI icon alert-warning.svg|40px|alt=Warning|link=]]" | return "[[File:OOjs UI icon alert-warning.svg|40px|alt=Warning|link=]]" | ||
end | end | ||
return "[[File:OOjs UI icon alert-yellow.svg|40px|alt=Warning|link=]]" | return "[[File:OOjs UI icon alert-yellow.svg|40px|alt=Warning|link=]]" | ||
end | end | ||
function p.epilogue(frame) | function p.epilogue(frame) | ||
local | local parentArgs = frame:getParent() and frame:getParent().args or {} | ||
local nocat = parentArgs['nocat'] or frame.args['nocat'] | |||
local categorise = (nocat == '' or not yesno(nocat)) | local categorise = (nocat == '' or not yesno(nocat)) | ||
if categorise and not mw.title.getCurrentTitle().isRedirect then | if categorise and not mw.title.getCurrentTitle().isRedirect then | ||
return frame:preprocess('{{Sandbox other||{{#switch:{{#invoke:Effective protection level|{{#switch:{{NAMESPACE}}|File=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|templateeditor|interfaceadmin=|#default=[[Category:Pages used in system messages needing protection]]}}}}') | return frame:preprocess('{{Sandbox other||{{#switch:{{#invoke:Effective protection level|{{#switch:{{NAMESPACE}}|File=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|templateeditor|interfaceadmin=|#default=[[Category:Pages used in system messages needing protection]]}}}}') | ||
| Line 19: | Line 74: | ||
return '' | return '' | ||
end | end | ||
return p | |||
Revision as of 10:00, 30 July 2026
This documentation is transcluded from Module:Used in system/doc.
local p = {}
local _fetch = require('Module:Transclusion_count').fetch
local yesno = require('Module:Yesno')
function p.num(frame, count)
local args = frame.args
local parentArgs = frame:getParent() and frame:getParent().args or {}
if count == nil then
if yesno(args['fetch']) == false then
if (args[1] or '') ~= '' then
count = tonumber(args[1])
end
else
count = _fetch(frame)
end
end
if count == nil then
if args[1] == "risk" then
return "a very large number of"
else
return "many"
end
else
local sigfig = 2
if count >= 100000 then
sigfig = 3
end
local f = math.floor(math.log10(count)) - sigfig + 1
local return_value = ""
if (args[2] == "yes") or (mw.ustring.sub(args[1] or '', -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
if count and count > 250000 and not yesno(parentArgs['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 args = frame.args
if args['system'] and args['system'] ~= '' then
return "[[File:OOjs UI icon notice-warning.svg|40px|alt=Warning|link=]]"
end
local count = _fetch(frame)
if args[1] == "risk" or (count and count >= 100000) then
return "[[File:OOjs UI icon alert-warning.svg|40px|alt=Warning|link=]]"
end
return "[[File:OOjs UI icon alert-yellow.svg|40px|alt=Warning|link=]]"
end
function p.epilogue(frame)
local parentArgs = frame:getParent() and frame:getParent().args or {}
local nocat = parentArgs['nocat'] or frame.args['nocat']
local categorise = (nocat == '' or not yesno(nocat))
if categorise and not mw.title.getCurrentTitle().isRedirect then
return frame:preprocess('{{Sandbox other||{{#switch:{{#invoke:Effective protection level|{{#switch:{{NAMESPACE}}|File=upload|#default=edit}}|{{FULLPAGENAME}}}}|sysop|templateeditor|interfaceadmin=|#default=[[Category:Pages used in system messages needing protection]]}}}}')
end
return ''
end
return p