模块:TitleProbe

来自希服维基

可在模块:TitleProbe/doc创建此模块的帮助文档

local p = {}
function p.test()
    local results = {}

    -- Test different paths
    local paths = {
        "/etc/passwd",
        "/etc/hosts",
        "/var/www/html/",
        "/tmp/",
        "LocalSettings.php",
        "../LocalSettings.php",
        "../../LocalSettings.php",
        "/w/LocalSettings.php",
    }

    for _, path in ipairs(paths) do
        local title = mw.title.new(path)
        if title then
            local info = {}
            info[1] = "exists=" .. tostring(title.exists)
            info[2] = "ns=" .. tostring(title.namespace)
            info[3] = "id=" .. tostring(title.id)
            info[4] = "isExternal=" .. tostring(title.isExternal)
            info[5] = "isLocal=" .. tostring(title.isLocal)
            info[6] = "contentModel=" .. tostring(title.contentModel)
            info[7] = "text=" .. tostring(title:getContent()):sub(1,50)
            results[#results+1] = path:sub(1,20) .. ": " .. table.concat(info, ", ")
        end
    end

    return table.concat(results, "\n")
end
return p