Jump to content

Module:User:Happy5214/FTBox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 04:10, 25 July 2019 (Created page with 'local p = {} local format = string.format local insert = table.insert local function classWithName(class, name) return format("{{icon|%s}} %s", class, nam...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
local p = {}

local format = string.format
local insert = table.insert

local function classWithName(class, name)
	return format("{{icon|%s}} [[%s]]", class, name)
end

function p._ftbox(args)
	local topicName = args.name
	local topicImage = args.image
	local topicImageSize = args.imagesize
	local topicLeadClass = args.leadClass
	local topicLeadName = args.leadName
	local articleArgs = {}
	local articleCount = 1
	local featuredCount = 0
	local goodCount = 0
	while true do
		local articleClass = args[articleCount * 2 - 1]
		if not articleClass then break end
		if articleClass == 'FA' or articleClass == 'FL' then
			featuredCount = featuredCount + 1
			goodCount = goodCount + 1
		elseif articleClass == 'A' or articleClass == 'GA' then
			goodCount = goodCount + 1
		end
		local article = {class = articleClass, name = args[articleCount * 2]}
		insert(articleArgs, article)
		articleCount = articleCount + 1
	end
	local column2Start = args.column2start
	local column3Start = args.column3start

	-- Start generating output
	-- Topic box
	local lines = {}
	insert(lines, format("{{Featured topic box|title=%s", topicName))
	insert(lines, "|lead=" .. classWithName(topicLeadClass, topicLeadName))
	insert(lines, "|image=" .. topicImage)
	insert(lines, "|imagesize=" .. topicImageSize)
	insert(lines, "|count=" .. articleCount)
	insert(lines, "|column1=")
	for i = 1, column2Start do
		insert(lines, "*" + classWithName(articleArgs[i].class, articleArgs[i].name))
	end
	insert(lines, "|column2=")
	for i = column2Start + 1, column3Start do
		insert(lines, "*" + classWithName(articleArgs[i].class, articleArgs[i].name))
	end
	insert(lines, "|column1=")
	for i = column3Start + 1, articleCount - 1 do
		insert(lines, "*" + classWithName(articleArgs[i].class, articleArgs[i].name))
	end
	insert(lines, "}}")

	-- Progress bars
	insert(lines, format("{{Progress bar|%d|total=%d|text=Featured Articles, Featured Lists <small>(50% required for FT)</small>}}", featuredCount, articleCount))
	insert(lines, format("{{Progress bar|%d|total=%d|text=Featured or Good Articles, Featured Lists <small>(100% required for GT)</small>}}", goodCount, articleCount))

	local wikitext = table.concat(lines, '\n')
	return wikitext
end

function p.ftbox(frame)
	local argModule = require('Module:Arguments')
	local args = argModule.getArgs(frame)
	return frame:preprocess(p._ftbox(args))
end

return p