跳转到内容

模組:沙盒/Alvinz/Sandbox

维基百科,自由的百科全书
local p = {}
--p.main 修改自自module:Template:Weighted_page_size
function p.Weighted_page_size( titleText )
    if not titleText then
        return 0
    end
    local title = mw.title.new( titleText )
    if not title then
        return 0
    end
    local content = title:getContent()
    if not content then
        return 0
    end
    local chars = mw.ustring.len( content )
    return math.floor( chars * 3.786 + 0.5 )
end

function p.main( frame )
    local titleText = frame.args[1]
    local size
    local icontext
    size = p.Weighted_page_size(titleText)

    if size<2000 then
        icontext='(少於2KB)'
    elseif size<8000 then   
        icontext='(2至8KB)'
    elseif size<16000 then  
        icontext='(8至16KB)'
    else    
        icontext='(16KB或以上)'
    end
    return icontext
end

return p