Bu modul uchun Modul:Pagelist/doc nomli hujjat sahifasini yaratishingiz mumkin

local p = {}

local separators = {
	dot = true,
	pipe = true,
	comma = true,
	['tpt-languages'] = true
}

local function getSeparator(sep)
	if type(sep) ~= 'string' then
		return nil
	end
	if separators[sep] then
		return mw.message.new(sep .. '-separator'):plain()
	else
		return sep
	end
end

local function generateLink(page, nspace, delim, endDelim)
	if not page then
		return nil
	end
	local pagename = mw.title.new(page)
	if not pagename then

		pagename = page
	else
		pagename = pagename.text
	end
	delim = delim or ''
	endDelim = endDelim or delim
	nspace = nspace or ''
	if nspace == 'all' then
		nspace = ''
		pagename = page
	end
	local outStr = mw.ustring.gsub( 
		string.format( 
			'%s[[:%s:%s|%s]]%s',
			delim, nspace, pagename, page, endDelim
		),
		 ':+',
		 ':' 
	)
	return outStr
end

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('Modul:Arguments').getArgs(frame, {
        trim = false,
        removeBlanks = false,
        wrappers = 'Andoza:Pagelist'
    })

    local args = {}
    for k, v in pairs(origArgs) do
        if type(k) == 'number' and 
            k >= 1 and
            math.floor(k) == k and
            string.match(v, '%S') then 
            table.insert(args, k)
        end
    end
    table.sort(args)
    for i, v in ipairs(args) do
        args[i] = origArgs[v]

        if type(args[i]) == 'string' then
            args[i] = mw.text.trim(args[i])
        end
    end

    args.delim = origArgs.delim
    args.edelim = origArgs.edelim
    args.nspace = origArgs.nspace

    if origArgs.separator and origArgs.separator ~= '' then
        args.separator = origArgs.separator
    end
    args.conjunction = origArgs.conjunction or ' va ' 

    return p._main(args)
end

return p