To edit the documentation or categories for this module, click here.
local util_args = require('Module:ArgsUtil')
local p = {}
function p.makeSuffixedLink(link, display, suffix)
if suffix and suffix ~= '' then
local newlink, class = p.pickLink(link, suffix)
return string.format('<span class="%s">[[%s|%s]]</span>',
class or '',
newlink or '',
display or ''
)
else
return string.format('[[%s|%s]]',
link or'',
display or ''
)
end
end
function p.pickLink(link, suffix)
local target = p.doesSuffixExist(link, suffix)
if target then
return target, ''
else
return link, 'no-subpage'
end
end
function p.doesSuffixExist(link, suffix)
if not suffix then
return link
end
local target = string.format('%s/%s',link or '',suffix or '')
local targetpage = mw.title.makeTitle('',target)
return targetpage.exists and targetpage.text
end
function p.getSuffix(useSuffix, title)
if not title then title = mw.title.getCurrentTitle() end
if util_args.castAsBool(useSuffix) then
titleparts = mw.text.split(title.text,'/')
table.remove(titleparts,1)
if #titleparts == 0 then
return nil
end
-- make a table where the first entry is the full suffix
-- subsequent suffixes are shorter and shorter
local output = table.concat(titleparts,'/')
return output
else
return nil
end
end
function p.makeNavbox(args)
if not args then return nil end
if not args.group1 and not args.list1 then return nil end
return mw.getCurrentFrame():expandTemplate{
title = 'navbox',
args = args
}
end
return p