[go: nahoru, domu]

Module:Sandbox/CX Zoom/TestPage3

local function remove_wiki_link (str)
	return (str:gsub( "%[%[([^%[%]]*)%]%]", function(l)
		return l:gsub( "^[^|]*|(.*)$", "%1" ):gsub("^%s*(.-)%s*$", "%1");
	end));
end

local function main (frame)
	local user = frame.args[1]
	local page = {
		[1] = "Wikipedia:List of Wikipedians by number of edits/1–1000",
		[2] = "Wikipedia:List of Wikipedians by number of edits/1001–2000",
		[3] = "Wikipedia:List of Wikipedians by number of edits/2001–3000",
		[4] = "Wikipedia:List of Wikipedians by number of edits/3001–4000",
		[5] = "Wikipedia:List of Wikipedians by number of edits/4001–5000",
		[6] = "Wikipedia:List of Wikipedians by number of edits/5001–6000",
		[7] = "Wikipedia:List of Wikipedians by number of edits/6001–7000",
		[8] = "Wikipedia:List of Wikipedians by number of edits/7001–8000",
		[9] = "Wikipedia:List of Wikipedians by number of edits/8001–9000",
		[10] = "Wikipedia:List of Wikipedians by number of edits/9001–10000",
	}
	
	local i = 1
	local content
	
	repeat
		content = mw.title.new (page[i]):getContent();
		if string.find(content, "|"..user.."]]\n") or string.find(content, "| "..user.."\n") then
			pgnum = i
		else
			if i == 10 then
				pgnum = 0
			else
				pgnum = nil
			end
		end
		i = i + 1
	until ((pgnum == i - 1) or (pgnum == 0))
	
	if pgnum == 0 then
		outputRank = "nil"
		outputName = user
		outputCount = "nil"
	else
		for rank, name, count in string.gmatch(content, "|%-\n|%s(.-)\n|%s(.-)\n|%s(.-)\n") do
			rank = mw.text.trim(rank)
			name = mw.text.trim(name)
			count = mw.text.trim(count)
			
			name = remove_wiki_link (name)
			
			if name == user then
				outputRank = rank
				outputName = name
				outputCount = count
				break
			end
		end
	end
	
	if frame.args[2] == "rank" then
		return outputRank
	elseif frame.args[2] == "count" then
		return outputCount
	else
		return outputRank .. " " .. outputName .. " " .. outputCount
	end
	
end

return	{
	main = main,
	}