Jump to content

Module:Sandbox/Aidan9382/DiscussionOverview

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Aidan9382 (talk | contribs) at 17:39, 9 November 2022 (Rewrite the comments now that im less stressed). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

--[=[
A module designed to provide an overall summary and some statistics on a discussion board
Inspired by, and partially borrowed from, [[Module:Sandbox/Smalljim/DiscussionIndexTest]]
--]=]
local Transcluder = require("Module:Transcluder")
local p = {}

--Specialised version of Transcluder.getSections, using a similar design
local function getSectionData(text)
	local sections = {}
	text = "\n"..text.."\n== "
	while true do
		local section,content = string.match(text,"\n==%s*([^=]-)%s*==\n(.-)\n==[^=]")
		if not section then
			break
		end
		text = string.sub(text,string.find(text,content,1,true)+#content,-1)
		sections[#sections+1] = {name=section,content=content}
	end
	return sections
end

local function getUserSigs(text)
	return {}
end

function p.main(frame)
	local page = frame.args[1] or frame.args.page
	assert(type(page)=="string","Invalid or no page provided")
	
	local success,text = pcall(Transcluder.get,page)
	assert(success,text)
	
	local sections = getSectionData(text)
	local tableContent = '{| class="wikitable sortable"\n! Section !! Initiator !! Last Comment !! Size !! Participants'
	for _,section in next,sections do
		local sanitisedName = string.gsub(string.gsub(section.name,"%[%[:?[^|]-|([^%]]-)]]","%1"),"%[%[:?([^%]]-)]]","%1")
		local wikilinkAnchor = "[[:"..page.."#"..sanitisedName.."|"..sanitisedName.."]]"
		local sectionContent = "\n|-\n| "..wikilinkAnchor.." || AHHHHHHHHH"
		
		tableContent = tableContent .. sectionContent
	end
	return tableContent .. "\n|}"
end

function p.maindev(frame)
	local content = p.main(frame)
	return content .. "\n\n" .. frame:extensionTag("syntaxhighlight",content,{lang="html5"})
end

return p