Module:Pagestat: Difference between revisions

From The Satanic Wiki
Jump to navigation Jump to search
m (1 revision imported)
No edit summary
 
Line 1: Line 1:
local ps = {}
local ps = {}
local getArgs = require("Dev:Arguments").getArgs
local getArgs = require("Module:Arguments").getArgs
   
   
local i18n = require('Dev:I18n').loadMessages('Pagestat')
local i18n = require('Module:I18n').loadMessages('Pagestat')
-- result data.
-- result data.
   
   

Latest revision as of 05:17, 2 May 2021

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