Module:Pagestat

From The Satanic Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Pagestat/doc

local ps = {}
local getArgs = require("Module:Arguments").getArgs
 
local i18n = require('Module:I18n').loadMessages('Pagestat')
-- result data.
 
function ps.main(frame)
    local args = getArgs(frame)
    if args then
        local title = mw.title.new(args[1])
        local page = title.prefixedText
        if title.isSpecialPage then
            return i18n:msg('special-page', page)
        elseif title.isExternal then
            return i18n:msg('inter-wiki', page)
        end
        local isfile = title:inNamespaces(-2,6)
        local isExist = title.exists
        local isRedirect = title.isRedirect
        if isfile then
            local isExistFile = title.fileExists
            if not isExistFile then
                return i18n:msg('nonexist-file', page)
            elseif isRedirect then
                return i18n:msg('redirect-file', page)
            elseif isExist then --File's isExist is descliption.
                return i18n:msg('desc-file', page)
            else
                return i18n:msg('nodesc-file', page)
            end
        elseif not isExist then
            return i18n:msg('nonexist-page', page)
        elseif isRedirect then
            local isDeadRedirect = (title.redirectTarget == false)
            if isDeadRedirect then
                return i18n:msg('dead-redirect', page)
            else
                return i18n:msg('exist-redirect', page,title.redirectTarget)
            end
        else
            return i18n:msg('exist-page', page)
        end
    else
        return i18n:msg('non-args')
    end
end
 
return ps