Difference between revisions of "Module:ExistNotRedirect/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Psiĥedelisto
(This module was copied from Module:ExistNotRedirect revision 905684347. See that page's history for copyright attribution.)
 
blackwiki>Psiĥedelisto
Line 5: Line 5:
 
local myArgs = mw.getCurrentFrame():getParent().args
 
local myArgs = mw.getCurrentFrame():getParent().args
 
local myPageName = myArgs[1]
 
local myPageName = myArgs[1]
 +
 
if (myPageName == nil) or (myPageName == "") then
 
if (myPageName == nil) or (myPageName == "") then
 
return ""
 
return ""
 +
end
 +
 +
if string.match(myPageName, "^:?File:") then
 +
myPageName = myPageName:gsub("^:?File:", "Media:")
 
end
 
end
  
local mypageTitle = mw.title.makeTitle("", myPageName)
+
local myPageTitle = mw.title.makeTitle("", myPageName)
if mypageTitle.exists then
+
if myPageTitle.exists then
if mypageTitle.isRedirect then
+
if myPageTitle.isRedirect then
 
return ""
 
return ""
 
else
 
else
Line 19: Line 24:
  
 
return ""
 
return ""
 
 
end
 
end
  
 
return p
 
return p

Revision as of 07:20, 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]
	
	if (myPageName == nil) or (myPageName == "") then
		return ""
	end
	
	if string.match(myPageName, "^:?File:") then
		myPageName = myPageName:gsub("^:?File:", "Media:")
	end

	local myPageTitle = mw.title.makeTitle("", myPageName)
	if myPageTitle.exists then
		if myPageTitle.isRedirect then
			return ""
		else
			return myPageName
		end
	end

	return ""
end

return p