Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Used in system: Difference between revisions

From Neodyland Wiki
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
local _fetch = require('Module:Transclusion_count').fetch
local _fetch = require('Module:Transclusion_count').fetch
local yesno = require('Module:Yesno')
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)
function p.num(frame, count)
     local args = frame.args
     local args = frame.args or {}
    local parentArgs = frame:getParent() and frame:getParent().args or {}


     if count == nil then
     if count == nil then
         if yesno(args['fetch']) == false then
         if yesno(args['fetch']) == false or yesno(get_arg(frame, 'fetch')) == false then
             if (args[1] or '') ~= '' then  
             local arg1 = get_arg(frame, 1)
                 count = tonumber(args[1])  
            if arg1 and arg1 ~= '' then  
                 count = tonumber(arg1)  
             end
             end
         else
         else
Line 19: Line 71:


     if count == nil then
     if count == nil then
         if args[1] == "risk" then
         if get_arg(frame, 1) == "risk" then
             return "a very large number of"
             return ""
         else
         else
             return "many"
             return "unknown"
         end
         end
     else
     else
         local sigfig = 2
         local sigfig = (count >= 100000) and 3 or 2
        if count >= 100000 then
            sigfig = 3
        end
 
         local f = math.floor(math.log10(count)) - sigfig + 1
         local f = math.floor(math.log10(count)) - sigfig + 1
         local return_value = ""
         local return_value = ""


         if (args[2] == "yes") or (mw.ustring.sub(args[1] or '', -1) == "+") then
        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)))
             return_value = string.format("%s+", mw.getContentLanguage():formatNum(math.floor((count / 10 ^ f)) * (10 ^ f)))
         else
         else
Line 39: Line 90:
         end
         end


         if count and count > 250000 and not yesno(parentArgs['no-percent']) then
        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)
             local percent = math.floor(((count / frame:callParserFunction('NUMBEROFPAGES', 'R')) * 100) + 0.5)
             if percent >= 1 then
             if percent >= 1 then
Line 51: Line 103:


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=]]"
    end
   
     local count = _fetch(frame)
     local count = _fetch(frame)
     if args[1] == "risk" or (count and count >= 100000) then
     local image, _, _ = get_box_config(frame, count)
        return "[[File:OOjs UI icon alert-warning.svg|40px|alt=Warning|link=]]"
     return image
    end
   
     return "[[File:OOjs UI icon alert-yellow.svg|40px|alt=Warning|link=]]"
end
end


function p.epilogue(frame)
function p.epilogue(frame)
     local parentArgs = frame:getParent() and frame:getParent().args or {}
     local count = _fetch(frame)
     local nocat = parentArgs['nocat'] or frame.args['nocat']
    local _, _, epilogue = get_box_config(frame, count)
     local categorise = (nocat == '' or not yesno(nocat))
    return epilogue
      
end
     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]]}}}}')
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 ''
end
end


return p
return p

Latest revision as of 10:55, 30 July 2026

Module documentation[ create · purge ]
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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.