Jump to content

Module:Article stub box

Revision as of 10:46, 27 July 2025 by M.robin (talk | contribs) (Created page with "--[[ This module was created by User:CodeHydro (Alexander Zhikun He). User:Jackmcbarn and User:Mr._Stradivarius provided a great deal of assistance in writting p.main() p.main() draw heavily from the following version of Template:Asbox of the English Wikipedia, authored primarily by User:Rich_Farmbrough https://en.wikipedia.org/w/index.php?title=Template:Asbox&oldid=619510287 p.templatepage() is derived from the following revision of Template:Asbox/templatepage, author...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Article stub box/doc

--[[
This module was created by User:CodeHydro (Alexander Zhikun He).
User:Jackmcbarn and User:Mr._Stradivarius provided a great deal of assistance in writting p.main()

p.main() draw heavily from the following version of Template:Asbox of the English Wikipedia, authored primarily by User:Rich_Farmbrough
https://en.wikipedia.org/w/index.php?title=Template:Asbox&oldid=619510287

p.templatepage() is derived from the following revision of Template:Asbox/templatepage, authored primarily by User:MSGJ
https://en.wikipedia.org/w/index.php?title=Template:Asbox/templatepage&oldid=632914791

Both templates had significant contributions from numerous others listed in the revision history tab of their respective pages.
--]]
local WRAPPER_TEMPLATE, args = 'Template:Article stub box'
-- TODO: update this instance of Asbox to Article stub box eventually
local templatestyles = 'Module:Article stub box/styles.css'
local p, Buffer, stubCats = {
	--Prevents dupli-cats... get it? Maybe not?
	cats = setmetatable({}, {__newindex = function(t, i, v)
		if not rawget(t, i) then
			rawset(t, i, v)
			table.insert(t, i)
		end
	end}),
	--initializes variables required by both p.main and p.templatepage
	init = function(self, frame, page)
		args, page = args or require('Module:Arguments').getArgs(frame, {
			wrappers = WRAPPER_TEMPLATE
		}), page or mw.title.getCurrentTitle()
		--Ensures demo parameter will never affect category() output for articles
		self.demo = self.demo or page.namespace ~= 0 and args.demo
		return args, page
	end
}, require('Module:Buffer')

local attention, catTag, catKey = Buffer'Stub message templates needing attention', '[[Category:%s]]', '%s|%s%s'
local function category(cat)
	for _, v in ipairs((tostring(cat) == cat or cat.t) and {cat} or cat) do
		if v and v ~= true then
			local catText
			if tostring(v) == v then
				catText = v
			else
				local buf = v[1] and Buffer(v[1]) or attention
				catText = buf["in"](buf, v.k)(v.t):_str(2, nil, nil, '|')
			end
			p.cats[catTag:format(catText)] = true
		end
	end
	return cat.done and table.concat(p.cats, p.demo and ' | ' or nil) or ''
end