"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
cats = {inv = {}},
function p:init(frame, page)
--initializes variables required by both p.main and p.templatepage
args = args or require('Module:Arguments').getArgs(frame, {
init = function(self, frame, page)
wrappers = WRAPPER_TEMPLATE
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
page = page or mw.title.getCurrentTitle()
self.demo = self.demo or page.namespace ~= 0 and args.demo or nil
--Ensures demo parameter will never affect category() output for articles
return args, page
self.demo = self.demo or page.namespace ~= 0 and args.demo or nil
end
return args, page
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 '',
not type(v.t) == type'' and v or string.format(
p.demo and '%s|Category:%s|%s' or '%s|%s%s',
v[1] or attention,
Line 40 ⟶ 51:
)
)
p.cats[link] = true
--Prevents dupli-cats... get it? Maybe not?
if not p.cats.inv[link] then
table.insert(p.cats, link)
p.cats.inv[link] = #p.cats
end
end
return cat.done and table.concat(p.cats, p.demo and ' | ' or ''nil) 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}
} or ''
end
 
--Shows population of categories found by catStub(). Outputs demo values if none
local function population()
local wikitext, base = ''{}, '* [[:Category:%s]] (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 = wikitext .., string.format(
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 = mw.title.new(page.fullText .. :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()
if args.icon then
return ombox{--Show ombox warnings for missing args.
category'Stub message templates using icon parameter'
ifNot = args.category,
elseif args.image then
'The <code>|category</code> parameter is not set. Please add an appropriate stub category.',
if not mw.title.new('Media:' .. mw.text.split(args.image, '|')[1]).exists then
{k = 'C', t = page.text}
category{k = 'B', t = page.text}
}
end
.. ombox{
else
ifNot = args.subject or args.article or args.qualifier,
category'Stub message templates without images'
'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.',
end
{k = 'D', t = page.text}
return table.concat(({_ = p.insert})
}
:_(ombox{--Show ombox warnings for missing args.
--catStub() may return an ombox if there are non-existing categories
ifNot = args.category,
.. catStub(page, pageDoc)
'The <code>|category</code> parameter is not set. Please add an appropriate stub category.',
.. category{
{k = 'C', t = page.text}
done = p.demo ~= 'doc',--Outputs categories if not doc demo
})
'Stub message templates',
:_(ombox{
'Exclude in print',
ifNot = args.subject or args.article or args.qualifier,
(args.icon and
'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.',
'Stub message templates using icon parameter'
{k = 'D', t = page.text}
or (args.image and
})
(mw.title.new('Media:' .. mw.text.split(args.image, '|')[1]).exists and
--catStub() may return an ombox if there are non-existing categories
nil
:_(catStub(page, pageDoc))
or {k = 'B', t = page.text}
:_(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.'
}
)
)
}
or 'Stub message templates without images'
)
),
args.imagealt and {k = 'I', t = page.text} or nil
}
--Add standard stub template documentation; demo calls will not call Module:Documentation unless p.demo = 'doc'
.. (p.demo and p.demo ~= 'doc' and '' or require('Module:Documentation').main{
content =
(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}}
or ''
)
.. '\n== About this template ==\nThis template is used to identify a '
.. string.format('%s stub%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=== 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}
or ''
)
.. '\n== General information ==\n'--Generic documentation
.. frame:expandTemplate{title = tStubDoc.text} .. '\n\n'
,
['link box'] =
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
" <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.'
or ''
)
})
end
 
"https://hi.wikipedia.org/wiki/Module:Asbox" से प्राप्त