跳转到内容

模組:AAINB26 talksize

维基百科,自由的百科全书
local p = {}

local WARN_SIZE = 262144   -- 256 KB,单位:字节

function p.check(frame)
    local title = mw.title.getCurrentTitle()

    -- PAGESIZE 是魔术字,不是解析器函数,名字不带 "#"
    local size = tonumber(frame:callParserFunction(
        'PAGESIZE',
        { title.prefixedText, 'R' }
    )) or 0

    local lang = mw.language.getContentLanguage()
    local display = lang:formatNum(size)
    local percent = string.format("%.1f%%", 100 * size / WARN_SIZE)

    if size > WARN_SIZE then
        return '<div id="longpagewarning" style="margin: 0 0 1em; padding: .5em 1em; vertical-align: middle; border: solid #aaaaaa 1px">'
            .. "'''注意''':本页长度达" .. display
            .. " 字节(预警线的" .. percent .. ")。请帮助把旧的讨论及时[[Help:如何將討論頁存檔|存档]]。</div>"
    end

    return "本页长度:" .. display .. " 字节(预警线的" .. percent .. ")"
end

return p