มอดูล:Update list overview

local p={}
local debuglog = ""
local listContent = ""
-- from http://lua-users.org/wiki/StringRecipes
function endswith(s, e)
	return e ==  or string.sub(s, -string.len(e)) == e
end
function cleanup(str)
	str = mw.ustring.match(str, "^%s*(%S.-%S)%s*$") or str -- (pass through "" and one character stuff)
	str = mw.ustring.gsub(str,"Module:","") -- remove all "Module:" from these, so they match up
	return str
end
function inList(name)
	name =  .. name:sub(1, 1):lower() .. name:sub(1, 1):upper() ..  .. name:sub(2)
	name = name:gsub(' ', ' _')
			   :gsub('%-', '%%%-')
	if listContent == "" then
		listContent = mw.title.new('User:Nullzerobot/ปรับปรุงหน้าอัตโนมัติ/ปกติ'):getContent()
	end
	if string.match(listContent, "page = u?'Mmodule:" .. name .. "'") then
		return 'yes'
	else
		return 'no'
	end
end
function p.getTable(frame)
local alltable = mw.text.split(p.getAll(frame), "\n")
for i = 1, #alltable do
alltablei = "
end
return '\n'
end
function p.getAll(frame)
	local modules = ""
local index = mw.text.unstrip(frame:preprocess("namespace=828"))
local nextlink = mw.ustring.gmatch(index, ".-:(.-)")
local pagelist = {}
from, to = nextlink(), nextlink()
while from and to do
	local tryget = "namespace=828" -- this is incredibly finicky, any variation yields list from A
	modules = mw.text.unstrip(frame:preprocess(tryget))
local nextmodule = mw.ustring.gmatch(modules, '(.-)')
modulelink = nextmodule()
while modulelink do
	modulelink = mw.ustring.gsub(modulelink, "Module:", "")
	name = mw.text.decode(modulelink)
	if (not endswith(name, '/sandbox')) and (not endswith(name, '/doc')) and (not endswith(name, '/testcases')) then
	    	table.insert(pagelist, name)
	    end
	    modulelink = nextmodule()
end
from, to = nextlink(),nextlink()
end
return table.concat(pagelist, "\n") .. debuglog
end
--=
function dictinsert(dict, data, heading) -- passing in a reference to the dictionary, not a copy of it, so whichever is specified gets altered
	local getentry = mw.ustring.gmatch(data, "(^\n\t+)")
	local entry = " "
	while entry do
		entry = cleanup(entry)
		dictentry = heading
	    entry = getentry()
	end
end
function p.main(frame)
	local args = frame.args -- not bothering reading parent frame, this is to be invoked only
local title = args1
return p._main(title, frame)
end
function p._main(title, frame)
local titleObject, titleContent
if title then
	titleObject = mw.title.new(title)
	if titleObject then
		datapage = titleObject:getContent()
	    end
	end
	if not datapage then
		return "Error: data page not found"
end
-- OK, we're now looking at a big juicy file with a lot of sections in top level headings surrounded by ==**
-- Many of these then are subject to commands in   that follow.  The heading name should be remembered to each of these.
-- Comments in  are to be ignored
-- All other terms are page names.
datapage = mw.ustring.gsub(datapage, "", "") -- remove all comments
datapage = datapage .. "\n== ==\n" -- add a final blank heading so it is easier to excise all headinged sections
datapage = mw.ustring.gsub(datapage, "==(^\n-)==", "end content tokenbegin heading token%1end heading token")
getsection = mw.ustring.gmatch(datapage, "%begin heading token%(.-)%end heading token%(.-)%end content token%")
local outtable = {} -- sequence
local entries = {} -- sequence
local rating = {} -- dictionary
local category = {} -- dictionary
section = ""
while section do
	-- within each section, there are commands in   which affect the content that follows, sometimes using the current heading.
	-- ONLY specific commands in   listed below are parsed; the rest don't count and will end up being interpreted as pages.
section = mw.ustring.gsub(section, "%%s*autoindex%s*%", "end data tokenbegin command tokenautoindexend command token")
	section = mw.ustring.gsub(section, "%%s*index%s*%", "end data tokenbegin command tokenindexend command token")
	section = mw.ustring.gsub(section, "%%s*rating%s*%", "end data tokenbegin command tokenratingend command token")
	section = mw.ustring.gsub(section, "%%s*keyword %-%s*%", "end data tokenbegin command tokenkeyword -end command token")
	section = mw.ustring.gsub(section, "%%s*category%s*%", "end data tokenbegin command tokencategoryend command token")	
	section = section .. "\nend data token" -- add a final blank command to make it easier to excise all commands
	getcommand = mw.ustring.gmatch(section, "%begin command token%(.-)%end command token%(.-)%end data token%")
	command = " "
	while command do
		command, data = getcommand()
		data = cleanup(data or "")
		if "autoindex" == command then
			command = "index"
			data = p.getAll(frame)
		end
		if "index" == command then
		   	local getentry = mw.ustring.gmatch(data, "(^\n\t+)")
		    local entry = true
		    while entry do
		    	entry = getentry()
		    	table.insert(entries, cleanup(entry or ""))
		    end
		elseif "keyword -" == command then
data = mw.text.trim(data)
			if data ~= "" then				
			    local i
			    for i = #entries,1,-1 do -- reverse order so the numbers stay accurate!
			        if mw.ustring.match(entriesi,data) then
			        	table.remove(entries,i)
			        end
			    end
			end
		elseif "category" == command then
			mw.log('c' .. heading)
		    dictinsert(category, data, heading)
			elseif "rating" == command then
				mw.log('r' .. heading)
				dictinsert(rating, data, heading)
			end
end
heading, section = getsection()
heading = cleanup(heading or "")
end
table.insert(outtable, '\n") -- end wikitable
local outdata = table.concat(outtable)
	return outdata..debuglog
end
**
return p