Module:Article stub box: Difference between revisions

Content deleted Content added
place main category in article even if |tempsort=no
m code simplification and performance improvements
Line 11:
Both templates had significant contributions from numerous others listed in the revision history tab of their respective pages.
--]]
local WRAPPER_TEMPLATE, catTag, catKey, args = 'Template:Asbox', '[[Category:%s]]', '%s|%s%s'
local argsp, Buffer, stubCats = {
--Prevents dupli-cats... get it? Maybe not?
local p = {}
p. cats = setmetatable({}, {__newindex = function(t, i, v)
local Buffer = require('Module:Buffer')
if not rawget(t, i) then
--initializes variables required by both p.main and p.templatepage
rawset(t, i, v)
function p:init(frame, page)
table.insert(t, i)
args = args or require('Module:Arguments').getArgs(frame, {
end
wrappers = WRAPPER_TEMPLATE
end}),
--initializes variables required by both p.main and p.templatepage
page = page or mw.title.getCurrentTitle()
init = function(self, frame, page)
--Ensures demo parameter will never affect category() output for articles
args, page = args or require('Module:Arguments').getArgs(frame, {
self.demo = self.demo or page.namespace ~= 0 and args.demo or nil
wrappers = WRAPPER_TEMPLATE
return args, page
page = }), page or mw.title.getCurrentTitle()
end
--Ensures demo parameter will never affect category() output for articles
self.demo = self.demo or page.namespace ~= 0 and args.demo or nil
return args, page
end
local Buffer =}, require('Module:Buffer')
 
--Prevents dupli-cats... get it? Maybe not?
p.cats = setmetatable({}, {__newindex = function(t, i, v)
if not rawget(t, i) then
rawset(t, i, v)
table.insert(t, i)
end
end})
--[[
Formats category links. Stores them until called with cat.done=true
Line 38 ⟶ 36:
or a table of strings and/or tables containing parts. (See below)
]]
local attention, link = Buffer'Stub message templates needing attention'
local function category(cat)
for _, v in ipairs((typetostring(cat) == type''cat or cat.t) and {cat} or cat) do
local attention, link = 'Stub message templates needing attention'
for _, v in ipairs((type(cat) == type'' or cat.t) and {cat} or cat) do
--[[
If v is a table:
Line 49 ⟶ 47:
]]
if v and v ~= true then--reject v = nil, false, or true
link = ('p.cats[[%sCategory:%s]]')catTag:format(tostring(v) == v and
)v
p.demo and ':' or '',
p.demoor (v[1] and Buffer(v[1]) or attention) or :_in(v.k):_(v.t):_str(2, ornil, nil, '|',)
type(v) == type'' and
v)] = true
or (p.demo and '%s|Category:%s|%s' or '%s|%s%s'):format(
v[1] or attention,
p.demo and (v[1] or attention) or v.k or '',
p.demo and ((v.k or '') .. v.t) or v.t
)
)
p.cats[link] = true
end
end
Line 253 ⟶ 244:
)
:node(args.note and
'<br />' mw.html. tostringcreate()
mw.html.create:tag'spanbr':done()
:tag'span'
:css{['font-style'] = 'normal', ['font-size'] = 'smaller'}
:wikitext(args.note)
:done()
)
:allDone()
Line 276 ⟶ 268:
output = mw.html.create()
:node(output)
:tag'small':wikitext(
string.format('<small>Demo categories: %s</small>', category{done = true}),
(category{done = true}:gsub('(%[%[)(Category:)([^|%]]-)(%|)', '%1%2%3|%2%3%4'):gsub('(%[%[)(Category:)', '%1:%2'))
p.demo == 'doc' and p.demodoc or nil
):done()
:wikitext(p.demo == 'doc' and p.demodoc or nil)
else
--Checks for valid name; emulates original template's check using {{FULLPAGENAME:{{{name|}}}}}
Line 289 ⟶ 282:
end
end
return output:wikitext(not p.demo and category{done = not p.demotrue} or nil)
end