Module:Asbox
From Zoophilia Wiki
Documentation for this module may be created at Module:Asbox/doc
local p = {} function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Asbox'}) local output = mw.html.create('table') local page = mw.title.getCurrentTitle(); -- Instead of using the buffer variable, just store a reference to the td and keep calling :wikitext() on it. local buffer = '' output :addClass('metadata plainlinks stub') :css('background','transparent') :attr('role','presentation') if args.icon or args.image then output :tag('td'):wikitext(args.icon or string.format('[[File:%s|%spx|alt=%s]]',args.image, args.pix and ('|' .. args.pix) or '',args.imagealt or 'Stub icon')) end -- You should use double-quoted strings when they need to contain single quotes, rather than escaping them all. -- You can have more than one space in a row in wikitext without it changing anything, so you can save some complexity here. -- You don't need to call tostring on fullUrl(). buffer = '\'\'This ' .. (args.subject and args.subject .. ' ' or '') .. (args.article or 'article') .. ' ' .. (args.qualifier and args.qualifier .. ' ' or '') .. '[[Wikipedia:stub|stub]]. You can help Wikipedia by [' .. tostring(page:fullUrl('action=edit', 'relative')) .. ' expanding it].\'\'' if args.name then -- Is 'test' a leftover from something? buffer = buffer .. frame:expandTemplate{title = 'navbar', args = {'test', mini = 'yes', style = 'position: absolute; right: 15px; display: none;'}} end if args.note then -- Change these HTML tags to be made with mw.html (you'll need to change buffer first though). buffer = buffer .. '<br /><span style="font-style: normal; font-size: smaller;">' .. args.note .. '</span>' end output :tag('td'):wikitext(buffer) output = tostring(output) if page.nsText == '' --[[Article space]] then output = output .. '[[Category:All stub articles]]' -- Instead of this loop, you should match all arg names that are category and then a number. for k = 0,2 do if args['category' .. (k > 0 and k or '')] then output = string.format('%s[[Category:%s]]', output, args['category' .. (k > 0 and k or '')]) end end end if args.demo == nil and page.basePageTitle ~= 'Template:Asbox' then -- frame:preprocess('{{FULLPAGENAME}}') is the same as page.prefixedText. Use the latter. -- You should normalize args.name so that things like 'foo_bar' and 'Foo bar' count as identical. if frame:preprocess('{{FULLPAGENAME}}') == args.name then -- Don't call getArgs again. Just use the args variable you already have. output = output .. frame:expandTemplate{title = 'Asbox/templatepage', args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Asbox'})} elseif not page.isSubpage and page.nsText == 'Template' then output = output .. '[[Category:Stub message templates needing attention|' .. (args.name and 'E' or 'W') .. page.text .. ']]' end end return output end return p