local p = {}
local separators = {
-- Get the page object. This will return the page object for the page
dot = true,
-- specified, or nil if there are errors in the title, if the
pipe = true,
-- expensive function count has been exceeded, or if the page was not
comma = true,
-- specified.
['tpt-languages'] = true
function getPageObject( page )
}
if not page then
return nil
end
-- Get the page object, passing the function through pcall
-- in case we are over the expensive function count limit.
local noError, pageObject = pcall(mw.title.new, page)
if not noError then
return nil
else
return pageObject
end
end
local function getSeparator(sep)
-- Process the separator parameter.
if type(sep) ~= 'string' then
local function getSeparator( sep )
return nil
if sep and type(sep) == 'string' then
end
if sep == 'dot'
if separators[sep] then
or sep =='pipe'
return mw.message.new(sep .. '-separator'):plain()
or sep == 'comma'
else
or sep == 'tpt-languages' then
return sep
return mw.message.new( sep .. '-separator' ):plain()
end
else
return sep
end
else
return nil
end
end
local function generateLink( page, nspace, delim, edelim endDelim)
if not page then
return nil
end
local pagename = getPageObjectmw.title.new( page )
if not pagename then
-- Default to the args we were passed if our page
-- object was nil.
pagename = page
else
pagename = pagename.text
end
delim = delim or ''
edelim endDelim = edelimendDelim or delim
nspace = nspace or mw.title.getCurrentTitle().nsText''
if nspace == 'all' then
return mw.ustring.format(
nspace = ''
'%s[[:%s:%s|%s]]%s',
pagename = page
delim, nspace, pagename, page, edelim
end
)
local outStr = mw.ustring.gsub(
string.format(
'%s[[:%s:%s|%s]]%s',
delim, nspace, pagename, page, endDelim
),
':+',
':'
)
return outStr
end
local function p._main( args )
local t = {}
local separator = getSeparator( args.separator )
local conjunction = getSeparator( args.conjunction )
for i, v in ipairs( args ) do
table.insert( t, generateLink(
v, args.nspace, args.delim, args.edelim
))
) )
end
return mw.text.listToText( t, separator, conjunction )
end
function p.main( frame )
local origArgs = require('Module:Arguments').getArgs(frame, {
local origArgs
trim = false,
if frame == mw.getCurrentFrame() then
removeBlanks = false,
-- We're being called via #invoke. If the invoking template passed any arguments,
wrappers = 'Template:Pagelist'
-- use them. Otherwise, use the arguments that were passed into the template.
})
origArgs = frame:getParent().args
for k, v in pairs( frame.args ) do
-- Process integer args. Allow for explicit positional arguments that are
origArgs = frame.args
-- specified out of order, e.g. {{br separated entries|3=entry3}}.
break
-- After processing, the args can be accessed accurately from ipairs.
end
local args = {}
else
for k, v in pairs(origArgs) do
-- We're being called from another module or from the debug console, so assume
if type(k) == 'number' and
-- the arguments are passed in directly.
k >= 1 and
origArgs = frame
math.floor(k) == k and
end
string.match(v, '%S') then -- Remove blank or whitespace values.
table.insert(args, k)
-- Process integer args. Allow for explicit positional arguments that are
end
-- specified out of order, e.g. {{br separated entries|3=entry3}}.
end
-- After processing, the args can be accessed accurately from ipairs.
table.sort(args)
local args = {}
for ki, v in pairsipairs( origArgs args) do
args[i] = origArgs[v]
if type( k ) == 'number' and
-- Trim whitespace.
k >= 1 and
if type(args[i]) == 'string' then
math.floor( k ) == k and
args[i] = mw.text.trim(args[i])
mw.ustring.match( v, '%S' ) then -- Remove blank or whitespace values.
end
table.insert( args, k )
end
end
-- Get old named args. We don't need to remove blank values
table.sort( args )
-- as for the nspace and edelim parameters the behaviour is different
for i, v in ipairs( args ) do
-- depending on whether the parameters are blank or absent, and for
args[ i ] = origArgs[ v ]
-- the delim parameter the default should be the blank string anyway.
end
args.delim = origArgs.delim
args.edelim = origArgs.edelim
-- Get old named args. We don't need to remove blank values
args.nspace = origArgs.nspace
-- as for the nspace and edelim parameters the behaviour is different
-- depending on whether the parameters are blank or absent, and for
-- Get new named args, "separator" and "conjunction", and strip blank values.
-- the delim parameter the default should be the blank string anyway.
if origArgs.separator and origArgs.separator ~= '' then
args.delim = origArgs.delim
args.edelimseparator = origArgs.edelimseparator
end
args.nspace = origArgs.nspace
if origArgs.conjunction and origArgs.conjunction ~= '' then
args.conjunction = origArgs.conjunction
-- Get new named args, "separator" and "conjunction", and strip blank values.
end
if origArgs.separator and origArgs.separator ~= '' then
args.separator = origArgs.separator
return p._main(args)
end
if origArgs.conjunction and origArgs.conjunction ~= '' then
args.conjunction = origArgs.conjunction
end
return _main( args )
end
return p
|