Modul:Homokozó/Pepo41/Sablonhomokozó

Innen: Hungaropédia
Ugrás a navigációhozUgrás a kereséshez

A modult a Modul:Homokozó/Pepo41/Sablonhomokozó/doc lapon tudod dokumentálni

-- próbálgatásokhoz
require 'Modul:No globals'
local args = {}
local used_args = {}
local config = {}
local sablon_kimenetek_kellenek = nil
local alkategoriak_kellenek = nil
-- hibakeresésre szolgáló lokális változó, ami tartalmazza az analízisre
-- szolgáló üzeneteket, az alábbi pop() függvény gyűjtögeti a tartalmát
local ou = {}
local oumax = 500 -- a tesztüzenetek számának maximuma
local oumarad = oumax
local hibavan = false
local hiba_jelzes = {}
local kategorizalas_van = false
local miki = nil
local function getConf(conf)
	local v = config[conf]
	return (v ~= '' and v) or nil
end
local function error(kategorizalas_kell, about)
	-- Enclose errorMsg with <span>
	-- Precondition:
	--     about  -- string
	hibavan = true
	if kategorizalas_kell then
		kategorizalas_van = true
	end
	local r = about
	if type( about ) == 'string' then
		if #about == 0 then
			r = 'Lua-hiba'
		end
	else
		r = tostring( about )
	end
	table.insert(hiba_jelzes, '<span class="error">' .. r .. '</span>')
end
local function pop(...)    -- idézőjeles rész és bővítmények az ou számára
                           -- memóriatúllépést okozhat, csak teszteléshez
	local list = {...}
	oumarad = oumarad - 1 -- előre csökkentjük, így mindig a maradék lehetséges pop hívások számát mutatja
	if oumarad == 0 then return end -- hogy ne legyen memóriatúllépés
	for _, var in pairs(list) do
		table.insert(ou,tostring(var))
		mw.log(ou)
	end
end
local function getArgMain( le,names,suffix)
	for _, v in ipairs(names) do
		if suffix then
			v = v .. tostring(suffix)
		end
		used_args[v] = true
		if args[v] and args[v] ~= '' then
			if le and type(args[v]) == 'string' then
				-- lecsípjük az utolsó pontot vagy vesszőt
				return args[v]:gsub('[%.,]$', '')
			else
				return args[v]
			end
		end
	end
	return nil
end
local function getArg(le, ...) -- itt eredetileg a frame nem paraméter
	-- Retrieve template argument
	-- Precondition:
	-- 	   le: true értékkel jelzi, hogy levágható a paraméter végéről a felesleges vessző és pont
	--     ...: paraméternevek, az első megadott és nem üreset adja vissza
	return getArgMain(le, {...})
end
local function getArgMore(le, max, ...)
	local ret = {}
	local val = getArg(le, ...)
	if val then
		table.insert(ret, val)
	end
	for i = 2, max do
		val = getArgMain({...}, le, i)
		if val then
			table.insert(ret, val)
		end
	end
	return ret
end
local function checkArgs()
	for n, v in pairs(args) do
		if not used_args[n] then
			local msg = 'Sablonhomokozó: Nem használt paraméter: ' .. n
			mw.log(msg)
			mw.addWarning(msg)
			kategorizalas_van = true
		end
	end
end
local function _homokozunk()
	local alkategoriak_kellenek= getConf('alkategoriak_kellenek')
	if not(alkategoriak_kellenek) then
		pop('alkategoriak nem kellenek')
	else
		pop('alkategoriak_kellenek')
	end
	if alkategoriak_kellenek then
		if alkategoriak_kellenek == 'igen' then
			alkategoriak_kellenek = true
		else
			alkategoriak_kellenek = false
		end
	end
    local sablon_kimenetek_kellenek = getConf('sablon kimenetek kellenek') -- kívánságra kikapcsolható
	pop('sablon_kimenetek_kellenek') -- igen, vagy nem a lehetséges válasz
	if sablon_kimenetek_kellenek then
		if sablon_kimenetek_kellenek == 'igen' then
			sablon_kimenetek_kellenek = true
		else
			sablon_kimenetek_kellenek = false
		end
	else
		-- ha a getConf nil értékkel tért vissza
		sablon_kimenetek_kellenek = true
	end
	local mi = getArg(false, 'mi')
	if mi then
		miki = mw.text.trim( mi )
		pop("miki="..miki)
	else
		miki = nil
		pop("a mi paraméter üres")
	end
local s = ''
	if sablon_kimenetek_kellenek then
		if miki then s = s .. miki .. ' ' end
		if #ou > 0 then s = s .. table.concat(ou,'{}')end --ez csak nyomkövetésnél kell, de akkor nagyon
	end
    if alkategoriak_kellenek and #alkategoriak > 0 then
    	local alkat= table.concat(alkategoriak, '[[Kategória:')
		s = s .. '[[Kategória:' .. alkat..']]'
	end
	checkArgs()
	if hibavan then
		s = s .. table.concat(hiba_jelzes, ', ')
	end
    return mw.text.trim(s)
end
local function _run(a, c)
	args = a
	config = c or {}
	return _homokozunk()
end
local function run(frame)
	args = frame:getParent().args -- a sablon hívásakor megadott paraméterek
	config = frame.args -- az #invoke utasításban átadott paraméterek
	pop("config=", table.concat (config, "'&#8201;&#8211;&#8201;"))
	return _homokozunk()
end
local p = {
	run = run,
	_run = _run
}
return p