"ഘടകം:Asbox" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

Content deleted Content added
imported>Codehydro
moved share initialization for p.main and p.templatepage to p.init; other minor changes
indent comments in line with the code
വരി 3:
local p = {
cats = {inv = {}},
--initializes variables required by both p.main and p.templatepage
init = function(self, frame, page)
args = args or require('Module:Arguments').getArgs(frame, {
വരി 9:
})
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
വരി 19:
Takes multiple or single categories in the form of 'cat'
or a table of strings and/or tables containing parts. (See below)
]]
]]function category(cat)
local attention, link = 'Stub message templates needing attention'
for _, v in ipairs((type(cat) == type'' or cat.t) and {cat} or cat) do
--[[
If v is a table:
[1] = full category name; defaults to local attention if blank
k = Category sort key. Prefix before v.t
t = page.text or args.tempsort#; appended after k (or in its place if omitted). Required if v is not a string
Basically the same as v = (v[1] or attention) .. ' | ' .. (v.k or '') .. v.t
]]
]] link = string.format(
'[[%sCategory:%s]]',
p.demo and ':' or '',
Line 37 ⟶ 40:
)
)
--Prevents dupli-cats... get it? Maybe not?
if not p.cats.inv[link] then
table.insert(p.cats, link)
Line 50 ⟶ 53:
Takes table {ifNot = Boolean, text, {cat. sort key, cat. sort name}}
Will return an empty string instead when ifNot evaluates to true
]]
function ombox(v)
if v.ifNot then
return ''
Line 65 ⟶ 69:
Unlike original template, module now takes unlimited cats! This function also performs
most stub category error checks except for the ombox for when main |category= is omitted (See p.template())
]]
]]function catStub(page, pageDoc)
stubCats = {missing = {}, v = {}}
for k, _ in pairs(args) do
--Find category parameters and store the number (main cat = '')
table.insert(stubCats, string.match(k, '^category(%d*)$'))
end
table.sort(stubCats)
for k, v in ipairs(stubCats) do
--Get category names and, if called by p.templatepage, the optional sort key
local cat, tsort = args['category' .. v], args['tempsort' .. v]
--Do not place in main category if |tempsort = 'no'; For example, if stub template merely
--adds |qualifier= to a meta stub and |category#= to a sub-category of meta's main category
if v ~= '' or tsort ~= 'no' then
--p.templatepage passes page; p.main does not, i.e. articles are categorized without sort keys.
table.insert(stubCats.v, page and
(tsort and {cat, t = tsort} or {cat, k = '*', t = page.text})
Line 84 ⟶ 89:
)
end
--Check category existance only if on the template page (i.e. stub documentation)
if page then
if not mw.title.new('Category:' .. cat).exists then
table.insert(stubCats.missing, '<code>category' .. v .. '</code>')
end
--[[
Checks non-demo stub template for documentation and flags if doc is present.
All stub cats names are checked and flagged if it does not match 'Category: [] stub'.
The main stub cat is exempt from the name check if the stub template has its own doc
(presumably, this doc would have an explanation as to why the main stub cat is non-conforming).
]]
]] table.insert(stubCats.v,
v == '' and not p.demo and pageDoc.exists and
'Stub message templates with documentation subpages'
Line 102 ⟶ 108:
end
end
--Add category names after loop is completed
category(stubCats.v)
return #stubCats.missing > 0 and ombox{
--Changed, original msg:
--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'
.. (#stubCats.missing == 1 and ' defines a stub category that does' or 's define stub categories that do')
Line 135 ⟶ 142:
local tStubDoc = mw.title.new'Template:Stub documentation'
local pageDoc = mw.title.new(page.fullText .. '/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()
return ombox{--Show ombox warnings for missing args.
ifNot = args.category,
Line 147 ⟶ 154:
{k = 'D', t = page.text}
}
--catStub() may return an ombox if there are non-existing categories
.. catStub(page, pageDoc)
.. category{
Line 165 ⟶ 172:
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 =
Line 248 ⟶ 255:
)
:allDone()
--[[
Stub categories for templates include a sort key (Otherwise all will be indexed under the letter 'T' for 'Template:[] stubs')
Articles using the template do not need a sort key since they have unique names.
When p.demo equals 'doc', the demo stub categories will appear as those for a stub template.
Otherwise, any non-nil p.demo will emulate article space categories (plus any error cats unless set to 'art')
]]
]] if p.demo ~= 'doc' then
catStub()
end
Line 259 ⟶ 267:
category'All stub articles'
elseif p.demo then
--Unless p.demo is set to 'art', it will also include error categories normally only shown on
--the template but not in the article. The elseif after namespace == 0 means demo cats will never show in article space.
p.demodoc = p.demo ~= 'art' and p.templatepage(frame, page) or nil
output:wikitext(string.format('<small>Demo categories: %s</small>', category{done = true}))
else
--Checks for valid name; emulates original template's check using {{FULLPAGENAME:{{{name|}}}}}
local normalizedName = mw.title.new(args.name or '')
if normalizedName and normalizedName.fullText == page.fullText then
"https://ml.wikipedia.org/wiki/ഘടകം:Asbox" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്