Difference between revisions of "Module:ExistNotRedirect/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Psiĥedelisto
(implement forcefile)
m (6 revisions imported)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
 
  
 
function p.main(args)
 
function p.main(args)
Line 7: Line 6:
 
local forceFileOnly = myArgs.forcefile -- force File: namespace check only
 
local forceFileOnly = myArgs.forcefile -- force File: namespace check only
 
 
if (myPageName == nil) or (myPageName == "") then
+
if not myPageName or myPageName == "" then
 
return ""
 
return ""
 
end
 
end
 
 
if string.match(myPageName, "^:?File:") and not forceFileOnly then
+
local myPageTitle = mw.title.makeTitle("", myPageName)
myPageName = myPageName:gsub("^:?File:", "Media:")
+
if not myPageTitle then
 +
error("Invalid page title passed, MediaWiki cannot understand it", 1)
 
end
 
end
 
+
if myPageTitle.exists
local myPageTitle = mw.title.makeTitle("", myPageName)
+
or not forceFileOnly and myPageTitle.file and myPageTitle.file.exists
if myPageTitle.exists then
+
then
if myPageTitle.isRedirect then
+
if not myPageTitle.isRedirect then
return ""
+
return myArgs[1]
else
 
return myPageName
 
 
end
 
end
 
end
 
end
 
+
 
return ""
 
return ""
 
end
 
end
  
 
return p
 
return p

Latest revision as of 16:32, 26 September 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 not myPageName or myPageName == "" then
		return ""
	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
		or not forceFileOnly and myPageTitle.file and myPageTitle.file.exists
	then
		if not myPageTitle.isRedirect then
			return myArgs[1]
		end
	end
	
	return ""
end

return p