Pāriet uz saturu

Modulis:Saraksts

Vikipēdijas lapa
Dokumentācijas ikona Moduļa dokumentācija[izveidot]
local p = {}
local getArgs = require('Module:Arguments').getArgs

function createLinks(id,pattern,page)
	local id,pattern,page=id,pattern,page
	local result
	
	result = " <span class='plainlinks'>([" .. string.gsub(pattern, "$1", id) .. " ieraksts katalogā]; " .. 
	" [https://www.google.lv/search?q=" .. string.gsub(page, " ", "+") .. "+site:wikipedia.org meklēt Vikipēdijā caur ''Google'']; " .. 
	" [https://www.google.lv/search?q=" .. string.gsub(page, " ", "+") .. " meklēt ''Google''])</span>"
	
	return result
	
end

function p._main(args)
	local t = {}
	local argcount = 0
	local offset = 1
	local pattern = args.pattern

	for k, v in ipairs( args ) do
			if( k >= 1 and math.floor(k) == k and k > argcount) then
				argcount = k
			end
	end

	local rows
	
	rows = argcount/2
	
	for r = 1,rows do
			if(offset <= argcount) then
				local name,id,link,page
				local split = {}
				
				name = args[offset]
				id = args[offset+1]
				
				for word in string.gmatch(name, '([^<]+)') do
					   table.insert(split, word)
				end
				
				page = split[1]
				link = split[2]
				
			--	page,link = mw.ustring.match(name,"([^%<]+)<?([^%>]+)>?")
				
				if link then
				t[#t+1] = '* [[' .. link .. '|' .. page .. ']] ' .. createLinks(id,pattern,page)
				else
				t[#t+1] = '* [[' .. page .. ']] ' .. createLinks(id,pattern,page)
				end
				offset = offset + 2
			end
		end

		return table.concat(t, '\n')
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

return p