Module:RFC index

From Guild of Archivists

Documentation for this module may be created at Module:RFC index/doc

p = {}
subpages = require( 'Module:Subpages' ).subpages
function p.index( frame )
	root = 'Requests for comment/'
	-- initial table content
	s = '{| class="wikitable sortable"\n!Name !! Component !! Created !! Authors !! Bug !! Implementation !! Decision !! Last edited\n|-\n'
	-- See [[Module:Subpages]]. This loops through the prefixindex.
	for page in subpages( root ) do
		-- page is the subpage name
		if string.find( page, '/' ) == nil then
			-- skip subpages of subpages (e.g. Requests for comment/Foo/bar)
			-- TODO: modify to account for names containing / for which no parent exists
			
			-- get subpage text
			text = frame:expandTemplate{ title=':' .. root .. page }
			
			-- get fields
			component = string.match( text, '<span class="rfc%-component">(.-)</span>')
			created = string.match( text, '<span class="rfc%-created">(.-)</span>')
			authors = string.match( text, '<span class="rfc%-authors">(.-)</span>')
			bug = string.match( text, '<span class="rfc%-bug">(.-)</span>')
			implementation = string.match( text, '<span class="rfc%-implementation">(.-)</span>')
			decision = string.match( text, '<span class="rfc%-decision">(.-)</span>')
			lastedited = frame:preprocess( '{{REVISIONYEAR:'..root..page..'}}-{{REVISIONMONTH:'..root..page..'}}-{{REVISIONDAY2:'..root..page..'}}' )
			-- empty fields/useless values
			if component then component = mw.text.nowiki(component) else component = "General/Unknown" end
			if created then created = mw.text.nowiki(created) else created = "Unknown" end
			if not authors then authors = "Unknown" end
			if bug then bug = "[[bugzilla:" .. bug .. "]]" else bug = "" end
			if not implementation then implementation = "" end
			if not decision then decision = "" end

			-- this is the table format for now
			s=s..'|[['..root..page..'|'..page..']]||'..component..'||'..created..'||'..authors..'||'..bug..'||'..implementation..'||'..decision..'||'..lastedited..'\n|-\n'
		end
	end
	return s
end
return p