Module:Asbox: Difference between revisions
From Zoophilia Wiki
Jump to navigationJump to search
meta>Codehydro (save progress w/ adoption of suggestions; replace wikitext italics with i tag; redid some lines after rereading original template) |
meta>Mr. Stradivarius (some formatting tweaks so that this mostly fits within 80 characters) |
||
Line 2: | Line 2: | ||
function p.main(frame) | function p.main(frame) | ||
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Asbox'}) | local args = require('Module:Arguments').getArgs(frame, { | ||
wrappers = 'Template:Asbox' | |||
}) | |||
local output = mw.html.create('table') | local output = mw.html.create('table') | ||
local page = mw.title.getCurrentTitle() | local page = mw.title.getCurrentTitle() | ||
local buffer = mw.html.create('td') | local buffer = mw.html.create('td') | ||
Line 13: | Line 15: | ||
if args.icon or args.image then | if args.icon or args.image then | ||
output | output | ||
:tag('td'):wikitext(args.icon or string.format('[[File:%s|%spx|alt=%s]]',args.image, args.pix and ('|' .. args.pix) or '40x30',args.imagealt or 'Stub icon')) | :tag('td'):wikitext(args.icon or string.format( | ||
'[[File:%s|%spx|alt=%s]]', | |||
args.image, | |||
args.pix and ('|' .. args.pix) or '40x30', | |||
args.imagealt or 'Stub icon' | |||
)) | |||
end | end | ||
buffer | buffer | ||
:tag('i') | :tag('i') | ||
:wikitext(string.format('This %s %s %s is a [[Wikipedia:stub|stub]]. | :wikitext(string.format( | ||
'This %s %s %s is a [[Wikipedia:stub|stub]]. You can help Wikipedia by [%s expanding it].', | |||
args.subject or '', | |||
args.article or 'article', | |||
args.qualifier or '', | |||
page:fullUrl('action=edit', 'relative') | |||
)) | |||
if args.name then | if args.name then | ||
buffer | buffer | ||
:wikitext(frame:expandTemplate{title = 'navbar', args = {args.name, mini = 'yes', style = 'position: absolute; right: 15px; display: none;'}}) | :wikitext(frame:expandTemplate{title = 'navbar', args = {args.name, mini = 'yes', style = 'position: absolute; right: 15px; display: none;'}}) | ||
end | end | ||
if args.note then | if args.note then | ||
buffer | buffer | ||
:wikitext('<br />') | :wikitext('<br />') | ||
Line 38: | Line 46: | ||
:node(buffer) | :node(buffer) | ||
output = tostring(output) | output = tostring(output) | ||
if page.namespace == 0 -- | if page.namespace == 0 then -- Main namespace | ||
output = output .. '[[Category:All stub articles]]' | output = output .. '[[Category:All stub articles]]' | ||
-- Instead of this loop, you should match all arg names that are category and then a number. | -- Instead of this loop, you should match all arg names that are category and then a number. | ||
Line 48: | Line 56: | ||
end | end | ||
if args.demo == nil and page.basePageTitle ~= 'Template:Asbox' then | if args.demo == nil and page.basePageTitle ~= 'Template:Asbox' then | ||
buffer = mw.title.new(args.name or '') | buffer = mw.title.new(args.name or '') | ||
if buffer == page.prefixedText then | if buffer == page.prefixedText then | ||
output = output .. frame:expandTemplate{ | |||
output = output .. frame:expandTemplate{title = 'Asbox/templatepage', args = args} | title = 'Asbox/templatepage', | ||
elseif not buffer.isSubpage and buffer.namespace == 10 -- | args = args | ||
output = output .. '[[Category:Stub message templates needing attention|' | } | ||
elseif not buffer.isSubpage and buffer.namespace == 10 then -- Template namespace and not a subpage | |||
output = output .. string.format( | |||
'[[Category:Stub message templates needing attention|%s]]', | |||
(args.name and 'E' or 'W') .. page.text | |||
) | |||
end | end | ||
end | end |
Revision as of 15:55, 24 December 2014
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() local buffer = mw.html.create('td') 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 '40x30', args.imagealt or 'Stub icon' )) end buffer :tag('i') :wikitext(string.format( 'This %s %s %s is a [[Wikipedia:stub|stub]]. You can help Wikipedia by [%s expanding it].', args.subject or '', args.article or 'article', args.qualifier or '', page:fullUrl('action=edit', 'relative') )) if args.name then buffer :wikitext(frame:expandTemplate{title = 'navbar', args = {args.name, mini = 'yes', style = 'position: absolute; right: 15px; display: none;'}}) end if args.note then buffer :wikitext('<br />') :tag('span') :css('font-style', 'normal') :css('font-size', 'smaller') :wikitext(args.note) end output :node(buffer) output = tostring(output) if page.namespace == 0 then -- Main namespace 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 buffer = mw.title.new(args.name or '') if buffer == page.prefixedText then output = output .. frame:expandTemplate{ title = 'Asbox/templatepage', args = args } elseif not buffer.isSubpage and buffer.namespace == 10 then -- Template namespace and not a subpage output = output .. string.format( '[[Category:Stub message templates needing attention|%s]]', (args.name and 'E' or 'W') .. page.text ) end end return output end return p