Documentation for this module may be created at Module:Ifexists/doc
local p = {}
function p.exists(frame)
local sPage = frame.args[1]
if sPage then
local num = frame:preprocess('{{:'..sPage..'}}')
if string.sub(num,1,3) ~="[[:" then
-- page exists. output the second parameter or the named parameter "true"
return frame.args[2] or frame.args["true"]
end
end
-- page does not exists. output the third parameter or the named parameter "false"
return frame.args[3] or frame.args["false"]
end
function p.existsSlow(frame)
local tArgs = frame:getParent()
if not(tArgs.args[1]) then
tArgs = frame
end
local sText = tArgs.args[1]
if sText and sText ~= "" then
if mw.title.new( sText ).exists then
-- page exists. output the second parameter or the named parameter "true"
return tArgs.args[2] or tArgs.args["true"]
else
-- page does not exists. output the third parameter or the named parameter "false"
return tArgs.args[3] or tArgs.args["false"]
end
end
end
return p