Module:Asbox: Difference between revisions

Content deleted Content added
linkbox is not part of output
finished translation of documentation|contents= into Lua... now to work on |link box=
Line 2:
local WRAPPER_TEMPLATE = 'Template:Asbox'
local args, msgBox
local stubCatNum = {}
 
 
Line 29 ⟶ 30:
for k, v in pairs(args) do
if type(k) == 'string' then
ptable.catNum =insert(stubCatNum, string.match(k, '^category(%d*)$'))
--[[if stubCatNum[matchNum] then
wikitext = wikitext .. (
tempsort == 'no' and p.catNum == '' and ''
or (p.catNum and
category{v .. (page and --Note: p.templatepage passes page; p.main does not
('|' .. (args['tempsort' .. p.catNum]
or ('*' .. page.text)
Line 41 ⟶ 43:
)
or ''
)--]]
end
if page and p.catNum then
end
missingCats = missingCats + mw.getCurrentFrame():callParserFunction{
 
--if page then
table.sort(stubCatNum)
local key
for k, v in ipairs(stubCatNum) do
key = {
cat = 'category' .. v,
ts = 'tempsort' .. v
}
wikitext = wikitext .. (v == '' and args[key.ts] == 'no' and
''
or category{args[key.cat]
.. (page and--True if stubCats called by p.templatepage
('|' .. (
args[key.ts]
or ('*' .. page.text)
))
or ''
)
}
)
if page and p.catNum then
missingCats = missingCats + mw.getCurrentFrame():callParserFunction{
name = '#ifexist',
args = {'Category:' .. args[key.cat], 0, 1}
}
hasDoc = false
if p.catNumv == '' then
hasDoc = mw.getCurrentFrame():callParserFunction{
name = '#ifexist',
args = {'Category:'page.prefixedText .. v'/doc', 0true, 1false}
}
wikitext = wikitext .. (hasDoc and '[[Category:Stub message templates with documentation subpages]]' or '')
hasDoc = false
end
if p.catNum == '' then
if not hasDoc and not string.match(vargs[key.cat], ' stubs$') then
hasDoc = mw.getCurrentFrame():callParserFunction{
wikitext = wikitext .. category('S', page.text)
name = '#ifexist',
args = {page.prefixedText .. '/doc', true, false}
}
wikitext = wikitext .. (hasDoc and '[[Category:Stub message templates with documentation subpages]]' or '')
end
if not hasDoc and not string.match(v, ' stubs$') then
wikitext = wikitext .. category('S', page.text)
end
end
end
stubCatNum[k] = {args[key.cat], key.cat} -- replace with values used in population()
end
if missingCats > 0 then
Line 66 ⟶ 91:
'One or more of the stub categories defined in this template do not seem to exist! Please double-check the parameters {{para|category}}, {{para|category1}} and {{para|category2}}.'
)
end
return wikitext
end
 
function population()
local wikitext, base = '', '* [[:Category:%s]] (population: (%s)\n'
for k, v in stubCatNum do
wikitext = wikitext .. string.format(base, v[1], mw.site.stats.pagesInCategory(v[1], 'all'))
end
if wikitext == '' then
wikitext = string.format(base, '{{{category}}}', 0)
end
return wikitext
Line 114 ⟶ 150:
)
)
-- Note: Original Asbox/templatepage checks categories for valid category names and whether they exist here.
-- Module has already done theseso at the first call of stubCats, avoiding a repeat checking if category# args are set.
.. require('Module:Documentation').main{
content = (
content = frame:preprocess'\n{{Asbox/stubtree}}\n\n== About this template ==\n\nThis template is used to identify a{{#if:{{{subject|}}}|&#32;{{{subject|}}}}} stub{{#if:{{{qualifier|}}}|&#32;{{{qualifier|}}}}}. It uses {{tl|asbox}}, which is a meta-template designed to ease the process of creating and maintaining stub templates.\n\n=== Usage ===\n\nTyping <code><nowiki>{{</nowiki>{{#ifeq:{{PAGENAME:{{{name}}}}}|Stub|stub|{{PAGENAME:{{{name}}}}} }}<nowiki>}}</nowiki></code> produces the message shown at the beginning, and adds the article to the following categor{{#if:{{{category1|}}}{{{category2|}}}|ies|y}}:\n* [[:Category:{{{category}}}]] (population: {{PAGESINCAT:{{{category}}}}}){{#if:{{{category1|}}}|* [[:Category:{{{category1}}}]] (population: {{PAGESINCAT:{{{category1}}}}})\n}}{{#if:{{{category2|}}}|* [[:Category:{{{category2}}}]] (population: {{PAGESINCAT:{{{category2}}}}})\n}}<!--\n\n*** Transclusion of /doc if it exists ***\n-->\n{{#ifexist:{{FULLPAGENAME}}/doc|{{{{FULLPAGENAME}}/doc}}\n}}<!--\n\n*** Generic documentation ***\n-->\n== General information ==\n\n{{Stub documentation}}\n\n',
'\n' .. require('Module:Asbox stubtree').subtree{
pagename = page.text
}
.. '\n\n== About this template ==\n\nThis template is used to identify a '
.. string.format('%sstub%s.', args.subject or '', args.qualifier and (' ' .. args.qualifier) or '')
.. ' It uses {{[[Template:Asbox|asbox]]}}, which is a meta-template designed to ease the process of creating and maintaining stub templates.\n\n=== Usage ===\n\nTyping <code>{{'
.. (page.text == 'Stub' and
'stub'
or page.text
)
.. '}}</code> produces the message shown at the beginning, and adds the article to the following categor' .. (#stubCatNum > 1 and 'ies' or 'y') .. ':\n'
.. population()
.. '<!--\n\n*** Transclusion of /doc if it exists ***\n-->\n'
.. (mw.title.new(page.basePageTitle .. '/doc').exists and
frame:expandTemplate{title = page.basePageTitle .. '/doc'}
or ''
)
.. '<!--\n\n*** Generic documentation ***\n-->\n== General information ==\n\n'
.. frame:expandTemplate{title = 'Stub documentation'} .. '\n\n'
),
['link box'] = frame:preprocess'This documentation is automatically generated by [[Template:Asbox/templatepage]]. <br/>The general information is transcluded from [[Template:Stub documentation]]. <span style="font-size: smaller; font-style: normal; line-height: 130%;">([{{fullurl:Template:Stub documentation|action=edit}} edit] &#124; [{{fullurl:Template:Stub documentation|action=history}} history])</span>{{#ifeq:{{PROTECTIONLEVEL:edit}}|sysop\n |{{sp}}<br/>This template is [[WP:PROTECT|fully protected]] and any [[WP:CAT|categories]] should be added to the template\'s [{{fullurl:{{FULLPAGENAME}}/doc|action=edit&preload=Template:Category_interwiki/preload}} /doc] subpage, which is not protected.\n}}\n\n}}'
}
Line 166 ⟶ 222:
:wikitext'[[Category:All stub articles]]'
:wikitext(stubCats())
elseif not args.demo and page.basePageTitle ~= WRAPPER_TEMPLATE then
--not in original Template:Asbox, but shouldn't hurt
output:wikitext('<small>Demo categories: ' .. string.gsub(stubCats(), '%[%[', ' | %[%[:') .. '</small>')
elseif page.basePageTitle ~= WRAPPER_TEMPLATE then
--mw.title.new('') is always nil. This is intentional and matches the results of original {{FULLPAGENAME:{{{name|}}}}}
if mw.title.new(args.name or '') == page then