Difference between revisions of "Module:ExistNotRedirect/sandbox"
Jump to navigation
Jump to search
blackwiki>Psiĥedelisto (Implement great idea by User:Nardog at Wikipedia:Village_pump_(technical)##ifexist_and_Commons!) |
blackwiki>Psiĥedelisto (implement forcefile) |
||
| Line 5: | Line 5: | ||
local myArgs = mw.getCurrentFrame():getParent().args | local myArgs = mw.getCurrentFrame():getParent().args | ||
local myPageName = myArgs[1] | local myPageName = myArgs[1] | ||
| + | local forceFileOnly = myArgs.forcefile -- force File: namespace check only | ||
if (myPageName == nil) or (myPageName == "") then | if (myPageName == nil) or (myPageName == "") then | ||
| Line 10: | Line 11: | ||
end | end | ||
| − | if string.match(myPageName, "^:?File:") then | + | if string.match(myPageName, "^:?File:") and not forceFileOnly then |
myPageName = myPageName:gsub("^:?File:", "Media:") | myPageName = myPageName:gsub("^:?File:", "Media:") | ||
end | end | ||
Revision as of 07:25, 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 myPageTitle.exists then
if myPageTitle.isRedirect then
return ""
else
return myPageName
end
end
return ""
end
return p