"Module:Asbox": अवतरणों में अंतर
Content deleted Content added
छो Protected Module:Asbox: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)) |
imported>Codehydro Streamlined a few functions |
||
पंक्ति 1:
local WRAPPER_TEMPLATE = 'Template:Asbox'
local args, stubCats
local p = {}
--initializes variables required by both p.main and p.templatepage
function p:init(frame, page)
args = args or require('Module:Arguments').getArgs(frame, {
wrappers = WRAPPER_TEMPLATE
})
page = page or mw.title.getCurrentTitle()
--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
function p:insert(v)
if v then
table.insert(self, v)
end
return self
end
--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 33 ⟶ 44:
'[[%sCategory:%s]]',
p.demo and ':' or '',
p.demo and '%s|Category:%s|%s' or '%s|%s%s',
v[1] or attention,
Line 40 ⟶ 51:
)
)
p.cats[link] = true
end
return cat.done and table.concat(p.cats, p.demo and ' | ' or
end
Line 56 ⟶ 63:
local function ombox(v)
if v.ifNot then
return
end
p.ombox = p.ombox or require('Module:Message box').ombox
Line 118 ⟶ 125:
.. ' not exist: ' .. mw.text.listToText(stubCats.missing),
{k = 'N', t = page.text}
}
end
--Shows population of categories found by catStub(). Outputs demo values if none
local function population()
local wikitext, base =
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,
v and args['category' .. v] or '{{{category}}}',
v and mw.site.stats.pagesInCategory(args['category' .. v], 'all') or 0
end
return table.concat(wikitext)
end
Line 141 ⟶ 148:
args, page = p:init(frame, page)
local tStubDoc = mw.title.new'Template:Stub documentation'
local pageDoc =
--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()
if args.icon then
category'Stub message templates using icon parameter'
elseif args.image then
if not mw.title.new('Media:' .. mw.text.split(args.image, '|')[1]).exists then
category{k = 'B', t = page.text}
end
else
category'Stub message templates without images'
end
return table.concat(({_ = p.insert})
:_(ombox{--Show ombox warnings for missing args.
ifNot = args.category,
'The <code>|category</code> parameter is not set. Please add an appropriate stub category.',
{k = 'C', t = page.text}
})
:_(ombox{
ifNot = args.subject or args.article or args.qualifier,
'This stub template contains no description! At least one of the parameters <code>|subject</code>, <code>|article</code> or <code>|qualifier</code> must be defined.',
{k = 'D', t = page.text}
})
--catStub() may return an ombox if there are non-existing categories
:_(catStub(page, pageDoc))
:_(category{
done = p.demo ~= 'doc',--Outputs categories if not doc demo
'Stub message templates',
'Exclude in print',
args.imagealt and {k = 'I', t = page.text} or nil
})
:_((not p.demo or p.demo == 'doc') and--Add standard stub template documentation; demo calls will not call Module:Documentation unless p.demo = 'doc'
require('Module:Documentation').main{
content = table.concat(({_ = p.insert})
:_(page.text ~= 'Stub' and--This comparison performed in {{Asbox/stubtree}} before it invokes Module:Asbox stubtree
require('Module:Asbox stubtree').subtree{args = {pagename = page.text}}
)
:_'\n== About this template ==\nThis template is used to identify a '
:_(args.subject)
:_' stub'
:_(args.qualifier and ' ' .. args.qualifier)
:_'. It uses {{[[Template:Asbox|asbox]]}}, which is a meta-template designed to ease the process of creating and maintaining stub templates.\n=== Usage ===\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'
:_(#stubCats > 1 and 'ies' or 'y')
:_':\n'
:_(population())
:_(pageDoc.exists and--transclusion of /doc if it exists
frame:expandTemplate{title = pageDoc.text}
)
:_'\n== General information ==\n'
:_(frame:expandTemplate{title = tStubDoc.text})
:_'\n\n'
),
['link box'] = table.concat(({_ = p.insert})
:_(string.format(
'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%%">([%s edit] | [%s history])</span>',
tStubDoc:fullUrl('action=edit', 'relative'),
tStubDoc:fullUrl('action=history', 'relative')
))
:_(page.protectionLevels.edit[1] == 'sysop' and
table.concat{
" <br/>This template is [[WP:PROTECT|fully protected]] and any [[WP:CAT|categories]] should be added to the template's [",
pageDoc:fullUrl('action=edit&preload=Template:Category_interwiki/preload', 'relative'),
'| /doc] subpage, which is not protected.'
}
)
)
}
end
|