"Module:Asbox": अवतरणों में अंतर

Content deleted Content added
imported>Codehydro
छोNo edit summary
imported>Codehydro
replace |link box= value with Lua; streamlined code to
पंक्ति 3:
local args, msgBox
local stubCats
 
 
function category(cat, name)
Line 21 ⟶ 20:
return msgBox.ombox{
type = 'content',
text = mw.getCurrentFrame():preprocess(text)
}
.. category(catSort, name)
end
 
function catStub(page, tempsortpageDoc)
local wikitext, missingCats, hasDoc = '', 0{}
stubCats = {}
for k, v_ in pairs(args) do
if type(k) == 'string' then
table.insert(stubCats, string.match(k, '^category(%d*)$'))
Line 54 ⟶ 53:
)
if page then
argsif =not {mw.title.new('Category:' .. args[key.cat], 0,).exists 1}then
missingCats = missingCats + mw.getCurrentFrame():callParserFunction{
table.insert(missingCats, key.cat)
name = '#ifexist',
}end
args = {'Category:' .. args[key.cat], 0, 1}
}
hasDoc = false
if v == '' then
hasDoc = mwpageDoc.getCurrentFrame():callParserFunction{exists
name = '#ifexist',
args = {page.fullText .. '/doc', true, false}
}
wikitext = wikitext .. (hasDoc and '[[Category:Stub message templates with documentation subpages]]' or '')
end
Line 69 ⟶ 64:
wikitext = wikitext .. category('S', page.text)
end
stubCats[k] = {args[key.cat], key.cat} -- replace with values to be used in population()
end
end
if #missingCats > 0 then
missingCats.text = ''
for k, meowFeedMe in ipairs(missingCats) do
missingCats.text = missingCats.text
.. (k == #missingCats and #missingCats > 1 and 'and ' or '')
.. '<code class="nowrap">|' .. meowFeedMe .. '</code>'
.. (k == #missingCats and '.' or (#missingCats < 3 and ' ' or ', '))
end
wikitext = wikitext .. ombox(
'N',
'--Changed from original: 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}}.'
'The following parameter'
.. (#missingCats == 1 and
' defines a stub category that does'
or 's define stub categories that do'
})
.. ' not exist: ' .. missingCats.text,
category('B', page.text)
)
end
Line 93 ⟶ 102:
 
function p.templatepage(frame, page)
local tStubDoc = mw.title.new('Template:Stub documentation')
.. local pageDoc = (mw.title.new(page.fullText .. '/doc').exists and
page = page or mw.title.getCurrentTitle()
args = args or require('Module:Arguments').getArgs(frame, {
Line 101 ⟶ 112:
'Exclude in print'
}
.. catStub(page, args.tempsortpageDoc)
.. ((args.icon and
'[[Category:Stub message templates using icon parameter]]')
or (args.image and
(mw.title.new('Media:' .. mw.text.split(args.image, '|')[1],).exists and
frame:callParserFunction{
name = '#ifexist',
or category('B', page.text)
args = {
)
'Media:' .. mw.text.split(args.image, '|')[1],
'',
category('B', page.text)
}
}
or '[[Category:Stub message templates without images]]'
)
Line 124 ⟶ 131:
or ombox(
'C',
'The {{para<code class="nowrap">|category}}</code> parameter is not set. Please add an appropriate stub category.',
page.text
)
Line 132 ⟶ 139:
or ombox(
'D',
'This stub template contains no description! At least one of the parameters {{para<code class="nowrap">|subject}}</code>, {{para<code class="nowrap">|article}}</code> or {{para<code class="nowrap">|qualifier}}</code> must be defined.',
page.text
)
)
--NoteChanged from original: Original Asbox/templatepage checks categories for valid names and whether they exist here.
--Module has already done so when it called of catStub, avoiding a repeat checking if category# args are set.
.. require('Module:Documentation').main{
content = (
'\n' .. (page.text ~= 'Stub' and --This comparison in {{Asbox/stubtree}} before invoking the Module:Asbox stubtree
require('Module:Asbox stubtree').subtree{args = {pagename = page.text}}
or ''
)
.. '\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'
Line 153 ⟶ 160:
.. '}}</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 --\n\n*** Transclusiontransclusion of /doc if it exists ***\n-->\n'
frame:expandTemplate{title = pagepageDoc.text .. '/doc'}
.. (mw.title.new(page.fullText .. '/doc').exists and
frame:expandTemplate{title = page.text .. '/doc'}
or ''
)
.. '<!--\n\n*** Generic documentation ***\n-->\n== General information ==\n\n'--Generic documentation
.. frame:expandTemplate{title = 'Stub documentation'tStubDoc.text} .. '\n\n'
),
['link box'] = (
['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}}'
'This documentation is automatically generated by [[Template:Asbox/templatepage]]. <br/>The general information is transcluded from [[Template:Stub documentation]]. '
.. tostring(mw.html.create'span'
:cssText('font-size:smaller;font-style:normal;line-height:130%')
:wikitext(string.format(
'([%s edit] | [%s history])',
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.'
})
argsor = {''
})
)
}
end
Line 211 ⟶ 234:
elseif args.demo then
--not in original Template:Asbox, but shouldn't hurt
output:wikitext('<small>Demo categories: ' .. string.gsub(catStub(), '%[%[', ' | %[%[:') .. '</small>')
else
elseif page.fullText ~= WRAPPER_TEMPLATE then
local normalizedName = mw.title.new(args.name or '')
--mw.title.new('') is always nil. This is intentional and matches the results of original {{FULLPAGENAME:{{{name|}}}}}
if mw.title.new(args.namenormalizedName orand '')normalizedName.fullText == page.fullText then
output:wikitext(p.templatepage(frame, page))
elseif not page.isSubpage and page.namespace == 10 then -- Template namespace and not a subpage
Line 223 ⟶ 246:
end
end
--Uncomment below to see templatepage when previewing Template:Asbox/testcases
--if page.fullText == 'Template:Asbox/testcases' then return output:wikitext(p.templatepage(frame, page)) end
return output
end
"https://hi.wikipedia.org/wiki/Module:Asbox" से प्राप्त