Jump to content

Module:Sandbox/CX Zoom/WPBS

From Wikipedia, the free encyclopedia
local A = {}

function A.main( frame )
	local content = frame.args[1]
	local class = frame.args["class"]
	
	local temps = {}
	local name = {}
	local i = 1
	
	local params = {}
	local params_x = {}
	local params_y = {}
	local Y = {}
	local oldClass = {}
	
	for t in string.gmatch(content, "(.-)###") do
		temps[i] = mw.text.trim(t)
		
		params[i] = {}
		params_x[i] = {}
		params_y[i] = {}
		Y[i] = {}
		local j = 0
		
		for p in string.gmatch(temps[i], "([^&&&]-)&&&") do
			params[i][j] = mw.text.trim(p)
			
			if j ~= 0 then
				params_x[i][j], params_y[i][j] = string.match(params[i][j], "(.*)===(.*)")
				if params_y[i][j] ~= "000" then
					Y[i][params_x[i][j]] = params_y[i][j]
				end
			end
			
			j = j + 1
		end
		
		oldClass[i] = Y[i]["class"]
		
		if (class ~= nil) and (class ~= "") then
			Y[i]["class"] = class
		end
		
		m, n = string.match(params[i][0], "(.*)@@@(.*)")
			name[i] = mw.text.trim(n)
		
		if i == 1 then
			store = frame:expandTemplate{ title = name[i], args = Y[i] }
		else
			store = store .. frame:expandTemplate{ title = name[i], args = Y[i] }
		end
		
		i = i + 1
	end
	--[=[
	for k, v in pairs( oldClass ) do
		if v ~= nil then
			oldClassCat = "[[Category:Pages using WikiProject banners with internal class parameters]]"
			break
		else
			oldClassCat = ""
		end
	end
	
	local c = i
	while c > 2 do
		if oldClass[c-1] ~= oldClass[c-2] then
			oldClassCat = oldClassCat .. "[[Category:Pages using WikiProject banners with mismatching class parameters]]"
			c = 0
		else
			oldClassCat = oldClassCat .. ""
			c = c - 1
		end
	end
	
	if (class == nil) or (class == "") then
		oldClassCat = oldClassCat .. "[[Category:Pages using WikiProject banner shell without class parameter]]"
	else
		local d = i
		while d > 1 do
			if oldClass[d-1] ~= class then
				oldClassCat = oldClassCat .. "[[Category:Pages using WikiProject banner shell with class parameter distinct from internal banners]]"
				d = 0
			else
				oldClassCat = oldClassCat .. ""
				d = d - 1
			end
		end
	end
	]=]

	local output = store --.. oldClassCat
	
	return output
end

return A