Difference between revisions of "Module:ExistNotRedirect/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Psiĥedelisto
(Always return back to them what they gave us.)
blackwiki>Psiĥedelisto
(Better error handling)
Line 16: Line 16:
  
 
local myPageTitle = mw.title.makeTitle("", myPageName)
 
local myPageTitle = mw.title.makeTitle("", myPageName)
 +
if not myPageTitle then
 +
error("Invalid page title passed, MediaWiki cannot understand it", 1)
 +
end
 
if myPageTitle.exists then
 
if myPageTitle.exists then
 
if myPageTitle.isRedirect then
 
if myPageTitle.isRedirect then

Revision as of 08:24, 11 July 2020

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

local p = {}


function p.main(args)
	local myArgs = mw.getCurrentFrame():getParent().args
	local myPageName = myArgs[1]
	local forceFileOnly = myArgs.forcefile -- force File: namespace check only
	
	if (myPageName == nil) or (myPageName == "") then
		return ""
	end
	
	if string.match(myPageName, "^:?File:") and not forceFileOnly then
		myPageName = myPageName:gsub("^:?File:", "Media:")
	end

	local myPageTitle = mw.title.makeTitle("", myPageName)
	if not myPageTitle then
		error("Invalid page title passed, MediaWiki cannot understand it", 1)
	end
	if myPageTitle.exists then
		if myPageTitle.isRedirect then
			return ""
		else
			return myArgs[1]
		end
	end

	return ""
end

return p