--local WRAPPER_TEMPLATE, args = 'Template:Asbox'local templatestyles = 'Asbox/styles.css'local p, Buffer, stubCats =, require('Module:Buffer')
--Formats category links. Stores them until called with cat.done=trueTakes multiple or single categories in the form of 'cat'or a table of strings and/or tables containing parts. (See below)local attention, catTag, catKey = Buffer'Stub message templates needing attention', '', '%s|%s%s'local function category(cat) for _, v in ipairs((tostring(cat)
--Makes an ombox warning;Takes table Will return an empty string instead when ifNot evaluates to true local function ombox(v) if v.ifNot then return end p.ombox = p.ombox or require('Module:Message box').ombox category return p.omboxend
--category= is omitted (See p.template)local function catStub(page, pageDoc) stubCats = -- zwj and zwnj have semantical use in other other wikis, don't remove them local zwj = '\226\128\141' -- U+200D, E2 80 8D local zwnj = '\226\128\140' -- U+200C, E2 80 8C local disallowedUnicodeChars = '[^%w%p%s' .. zwj .. zwnj .. ']' -- for i18n we make this a separate string local code for k, _ in pairs(args) do --Find category parameters and store the number (main cat = ) table.insert(stubCats, string.match(k, '^category(%d*)$')) end table.sort(stubCats) for k, v in ipairs(stubCats) do --Get category names and, if called by p.templatepage, the optional sort key local tsort, cat = args['tempsort' .. v], mw.ustring.gsub(args['category' .. v], disallowedUnicodeChars, )--remove all hidden unicode chars --Do not place template in main category if |tempsort = 'no'. However, DO place articles of that template in the main category. table.insert(stubCats.v, page and (--p.templatepage passes page; p.main does not, i.e. articles are categorized without sort keys. v
'no'--if true, inserts 'true' in table, which category will reject or tsort and or --note space in front of sort key ) or cat ) --Check category existance only if on the template page (i.e. stub documentation) if page then if not mw.title.new('Category:' .. cat).exists then code = code or mw.html.create'code':wikitext'|category' table.insert(stubCats.missing, tostring(mw.clone(code):wikitext(v))) end -- table.insert(stubCats.v, v
--Shows population of categories found by catStub. Outputs demo values if nonelocal function population local wikitext, base =, '* (population: %s)\n' if not args.category and stubCats[1] ~= false then table.insert(stubCats, 1, false) end for _, v in ipairs(stubCats) do table.insert(wikitext, base:format(v and args['category' .. v] or '', v and mw.site.stats.pagesInCategory(args['category' .. v], 'all') or 0 )) end return table.concat(wikitext)end
--Includes standard stub documention and flags stub templates with bad parameter values.function p.templatepage(frame, page) args, page = p:init(frame, page) local tStubDoc = mw.title.new'Template:Stub documentation' local pageDoc = page:subPageTitle('doc') --Reorganization note: Original Asbox alternates between outputting categories and checking on params |category#=. --Rather than checking multiple times and switching tasks, all stub category param operations have been rolled into catStub return Buffer(ombox) :_(ombox) :_(catStub(page, pageDoc))--catStub may also return an ombox if there are non-existing categories :_(category) :_((not p.demo or p.demo
function p.main(frame, page) args, page = p:init(frame, page) local output = mw.html.create'div' :attr :addClass'metadata plainlinks asbox stub' :tag'table' :attr :tag'tr' :addClass'noresize' :node((args.icon or args.image) and mw.html.create'td' :wikitext(args.icon or (''):format(args.image or , args.pix or '40x30', args.imagealt or 'Stub icon' )) ) :tag'td' :tag'p' :addClass'asbox-body' :wikitext(Buffer'This':_(args.subject):_(args.article or 'article'):_(args.qualifier)' ',--space ' is a stub. You can help Wikipedia by [', page:fullUrl('action=edit', 'relative'), ' expanding it].' ) :done :node(args.note and mw.html.create :tag'p' :addClass'asbox-note' :wikitext(args.note) :done ) :allDone :node(args.name and require'Module:Navbar'._navbar ) --Stub categories for templates include a sort key; this ensures that all stub tags appear at the beginning of their respective categories. Articles using the template do not need a sort key since they have unique names. When p.demo equals 'doc', the demo stub categories will appear as those for a stub template. Otherwise, any non-nil p.demo will emulate article space categories (plus any error cats unless set to 'art') if page.namespace
0 means demo cats will never show in article space. p.demodoc = p.demo ~= 'art' and p.templatepage(frame, page) output = mw.html.create :node(output) :tag'small':wikitext('Demo categories: ', (category:gsub('(%[%[)(Category:)([^|%]]-)(%|)', '%1%2%3|%2%3%4'):gsub('(%[%[)(Category:)', '%1:%2')) ):done :wikitext(p.demo == 'doc' and p.demodoc or nil) else --Checks for valid name; emulates original template's check using {{FULLPAGENAME:{{{name|}}}}} local normalizedName = mw.title.new(args.name or '') if normalizedName and normalizedName.fullText == page.fullText then output = mw.html.create:node(output):wikitext(p.templatepage(frame, page)) elseif not page.isSubpage and page.namespace == 10 then-- Template namespace and not a subpage category{{k = args.name and 'E' or 'W', t = page.text}} end end return frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} } .. tostring(output:wikitext(not p.demo and category{done = true} or nil)) end return p]