Module:Ifexist

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

The page: Page, returned this statement: true


local p = {}

local getArgs = require('Module:Arguments').getArgs

local format = mw.ustring.format

local function err(msg)
    return format('<strong class="error">Error: %s</strong>', msg)
end

function p.main(frame)
    args = getArgs(frame)
    return p._main(args)
end

function p._main(args)
    title = args[1] or args.title
    trueTxt = args[2] or args.trueTxt or 'true'
    falseTxt = args[3] or args.falseTxt or 'false'
    -- // declare, check, return
    if mw.title.new(title).exists then
        return format('The page: [[%s]], returned this statement: %s', title, trueTxt)
    elseif title == '' then
        return err('Page title is required')
    else
        return format('The page: [[%s]], returned this statement: %s', title, falseTxt)
    end
end

return p