Difference between revisions of "Module:ExistNotRedirect"
Jump to navigation
Jump to search
blackwiki>MusikBot II m (Protected "Module:ExistNotRedirect": High-risk template or module (more info) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))) |
m (3 revisions imported) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| − | |||
function p.main(args) | function p.main(args) | ||
local myArgs = mw.getCurrentFrame():getParent().args | local myArgs = mw.getCurrentFrame():getParent().args | ||
local myPageName = myArgs[1] | local myPageName = myArgs[1] | ||
| − | if | + | local forceFileOnly = myArgs.forcefile -- force File: namespace check only |
| + | |||
| + | if not myPageName or myPageName == "" then | ||
return "" | return "" | ||
end | end | ||
| − | + | ||
| − | local | + | local myPageTitle = mw.title.makeTitle("", myPageName) |
| − | if | + | if not myPageTitle then |
| − | if | + | error("Invalid page title passed, MediaWiki cannot understand it", 1) |
| − | return | + | 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 | ||
end | end | ||
| − | + | ||
return "" | return "" | ||
| − | |||
end | end | ||
return p | return p | ||
Latest revision as of 16:32, 26 September 2020
Implements {{ExistNotRedirect}}
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