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

From Neodyland Wiki
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')

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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.