അജ്ഞാത ഉപയോക്താവ്
ഘടകം:TemplateBox (മൂലരൂപം കാണുക)
18:49, 30 ഒക്ടോബർ 2022-നു നിലവിലുണ്ടായിരുന്ന രൂപം
, 30 ഒക്ടോബർ 2022use require('strict') instead of require('Module:No globals')
(ചെ.) (ഒരു പതിപ്പ് ഇറക്കുമതി ചെയ്തു) |
(use require('strict') instead of require('Module:No globals')) |
||
വരി 1: | വരി 1: | ||
require('strict') | |||
--[[ | --[[ | ||
@exports | @exports | ||
വരി 12: | വരി 14: | ||
-- Helper function, not exposed | -- Helper function, not exposed | ||
function tobool(st) | local function tobool(st) | ||
if type( st ) == 'string' then | if type( st ) == 'string' then | ||
return st == 'true' | return st == 'true' | ||
വരി 39: | വരി 41: | ||
i18n['param-default-empty'] = "empty" | i18n['param-default-empty'] = "empty" | ||
function initLangModule() | local function initLangModule(frame) | ||
if langIsInit then | if langIsInit then | ||
return | return | ||
end | end | ||
userLang = frame:preprocess( '{{int:lang}}' ) | |||
--! From [[:de:Modul:Expr]]; by [[:de:User:PerfektesChaos]]; | --! From [[:de:Modul:Expr]]; by [[:de:User:PerfektesChaos]]; | ||
--! Derivative work: Rillke | --! Derivative work: Rillke | ||
msg = function( key ) | msg = function( key ) | ||
-- Retrieve localized message string in content language | -- Retrieve localized message string in content language | ||
വരി 91: | വരി 93: | ||
t = 'InterfaceText', | t = 'InterfaceText', | ||
alias = 'desc' | alias = 'desc' | ||
} | }, | ||
format = { | |||
default = 'inline', | |||
t = 'selection', | |||
selection = 'inline|block', | |||
alias = 'print', | |||
extract = function(pargs, number, paramVal) | |||
local m = { multi = 'block', one = 'inline', infobox = 'block' } | |||
return m[paramVal] or 'inline' | |||
end | |||
} | |||
} | } | ||
local paraminfoTLParams = { | local paraminfoTLParams = { | ||
വരി 131: | വരി 143: | ||
local tdkey = key .. '-td' | local tdkey = key .. '-td' | ||
local aliases = pargs[tdkey] or pargs[key] | local aliases = pargs[tdkey] or pargs[key] | ||
if aliases then | if aliases and mw.text.trim( aliases ) ~= '' then | ||
local cleaned = {} | |||
for m in mw.text.gsplit( aliases, '/', true ) do | |||
cleaned[#cleaned+1] = mw.text.trim(m) | |||
end | |||
return cleaned | |||
else | |||
return nil | |||
end | end | ||
end | end | ||
}, | }, | ||
വരി 145: | വരി 162: | ||
default = 'unknown', | default = 'unknown', | ||
t = 'selection', | t = 'selection', | ||
selection = 'unknown|number|string|string/wiki-user-name|string/wiki-page-name|string/line|line|wiki-page-name|wiki-file-name|wiki-user-name|content|unbalanced-wikitext' | selection = 'unknown|number|string|string/wiki-user-name|string/wiki-page-name|string/line|line|wiki-page-name|wiki-file-name|wiki-user-name|wiki-template-name|content|unbalanced-wikitext|date|url|boolean' | ||
}, | }, | ||
inherits = { | inherits = { | ||
default = nil, | default = nil, | ||
t = 'string' | t = 'string' | ||
} | }, | ||
autovalue = { | |||
default = '', | |||
t = 'string', | |||
alias = 'av', | |||
}, | |||
suggestedvalues = { | |||
default = '', | |||
t = 'table', | |||
alias = 'sv', | |||
extract = function(pargs, number, paramVal) | |||
if paramVal == nil then | |||
return nil | |||
end | |||
local cleaned = {} | |||
for m in mw.text.gsplit( paramVal, '/', true ) do | |||
cleaned[#cleaned+1] = mw.text.trim(m) | |||
end | |||
return cleaned | |||
end, | |||
}, | |||
-- sets will be treated differently because we can only have a plain structure in wikitext | -- sets will be treated differently because we can only have a plain structure in wikitext | ||
} | } | ||
വരി 159: | വരി 196: | ||
extract = function(item, renderCell, monolingual) | extract = function(item, renderCell, monolingual) | ||
local alias, param = '', item.key | local alias, param = '', item.key | ||
local aliasTT = '< | local aliasTT = '<span style="font-family: monospace; color:#777; border:1px solid #6A6A6A">' | ||
param = '<code>' .. param .. '</code>' | param = '<code>' .. param .. '</code>' | ||
if item.aliases then | if item.aliases then | ||
alias = aliasTT .. table.concat(item.aliases, '</ | alias = aliasTT .. table.concat(item.aliases, '</span><br />' .. aliasTT) .. '</span>' | ||
param = table.concat({param, '<br /><div>', alias, '</div>'}) | param = table.concat({param, '<br /><div>', alias, '</div>'}) | ||
end | end | ||
renderCell(param | renderCell(param) | ||
end | end | ||
}, { | }, { | ||
വരി 213: | വരി 250: | ||
-- Initialize param info | -- Initialize param info | ||
-- Avoids having to add redundant information to the preceding tables | -- Avoids having to add redundant information to the preceding tables | ||
function init( which ) | local function init( which ) | ||
local setDefault = function(v) | local setDefault = function(v) | ||
if v.t == nil and v.default ~= nil then | if v.t == nil and v.default ~= nil then | ||
വരി 219: | വരി 256: | ||
end | end | ||
if v.selection then | if v.selection then | ||
local selection = mw.text.split(v.selection, '|', true) | |||
v.selection = {} | |||
for _, sel in ipairs(selection) do | |||
v.selection[sel] = true | |||
end | |||
end | end | ||
end | end | ||
വരി 226: | വരി 267: | ||
end | end | ||
end | end | ||
function initParamTables() | local function initParamTables() | ||
init( paraminfoTemplate ) | init( paraminfoTemplate ) | ||
init( paraminfoTLParams ) | init( paraminfoTLParams ) | ||
വരി 264: | വരി 305: | ||
sep = sep .. sepStart | sep = sep .. sepStart | ||
local sparseIpairs = require('Module:TableTools').sparseIpairs | |||
local comapareLegacyVal = function(val) | local comapareLegacyVal = function(val) | ||
return val == 'optional-' or val == 'deprecated' | return val == 'optional-' or val == 'deprecated' | ||
വരി 277: | വരി 319: | ||
eachArg = function(cb) | eachArg = function(cb) | ||
for i, arg in | for i, arg in sparseIpairs( pargs ) do | ||
if ('number' == type(i)) then | if ('number' == type(i)) then | ||
argName = mw.text.trim( arg or '' ) | argName = mw.text.trim( arg or '' ) | ||
വരി 329: | വരി 371: | ||
initParamTables() | initParamTables() | ||
local sets, asParamArray, laxtype, processParams, processDesc | local sets, asParamArray, laxtype, processParams, processDesc, unstrip | ||
if 'paramtable' == consumer then | if 'paramtable' == consumer then | ||
asParamArray = true | asParamArray = true | ||
വരി 351: | വരി 393: | ||
-- Ensure that tables end up as array/object (esp. when they are empty) | -- Ensure that tables end up as array/object (esp. when they are empty) | ||
local tdata = {description="", params={}, sets={}} | local tdata = {description="", params={}, sets={}} | ||
local isObject = { __tostring = function() return "JSON object" end } isObject.__index = isObject | |||
local isArray = { __tostring = function() return "JSON array" end } isArray.__index = isArray | local isArray = { __tostring = function() return "JSON array" end } isArray.__index = isArray | ||
setmetatable(tdata.params, isObject) | |||
setmetatable(tdata.sets, isArray) | setmetatable(tdata.sets, isArray) | ||
onGetKey = onGetKey or function( prefix, alias, param ) | onGetKey = onGetKey or function( prefix, alias, param ) | ||
വരി 424: | വരി 468: | ||
if info.selection then | if info.selection then | ||
if info.selection | if info.selection[paramVal] then | ||
insertValue() | insertValue() | ||
end | end | ||
വരി 522: | വരി 566: | ||
end | end | ||
if processParams then | if processParams then | ||
-- Ensure that `templateArgs` contains indicies in ascending order | |||
table.sort( templateArgs ) | |||
for i, number in pairs( templateArgs ) do | for i, number in pairs( templateArgs ) do | ||
extractData( paraminfoTLParams, number ) | extractData( paraminfoTLParams, number ) | ||
വരി 544: | വരി 590: | ||
return key2, key, tdkey2, tdkey | return key2, key, tdkey2, tdkey | ||
end | end | ||
local toUserLanguage = function(input | local toUserLanguage = function(input) | ||
if type(input) == 'table' then | if type(input) == 'table' then | ||
input = | input = require( 'Module:LangSwitch' )._langSwitch( input, userLang ) or '' | ||
end | end | ||
return input | return input | ||
വരി 553: | വരി 599: | ||
function p.description(frame) | function p.description(frame) | ||
local pargs = ( frame:getParent() or {} ).args or {} | local pargs = ( frame:getParent() or {} ).args or {} | ||
-- Initialize the language-related stuff | |||
initLangModule(frame) | |||
local tdata, paramLen | local tdata, paramLen | ||
tdata, paramLen = p.args2table(pargs, customOnGetKey, 'description') | tdata, paramLen = p.args2table(pargs, customOnGetKey, 'description') | ||
return | return toUserLanguage(tdata.description) | ||
end | end | ||
വരി 571: | വരി 618: | ||
-- Initialize the language-related stuff | -- Initialize the language-related stuff | ||
initLangModule( | initLangModule(frame) | ||
tdata, paramLen = p.args2table(pargs, customOnGetKey, 'paramtable') | tdata, paramLen = p.args2table(pargs, customOnGetKey, 'paramtable') | ||
വരി 609: | വരി 653: | ||
row = '' | row = '' | ||
for i2, field in ipairs( tableLayout ) do | for i2, field in ipairs( tableLayout ) do | ||
field.extract(item, renderCell, | field.extract(item, renderCell, toUserLanguage) | ||
end | end | ||
table.insert(rows, row) | table.insert(rows, row) |