विभाग:Parameters

-- This module implements [[Template:Parameters]].-- [SublimeLinter luacheck-globals:mw]local DEFINITIONS = {alt = {code = '<!-- text alternative for image; see WP:ALT -->',dlist = 'text alternative for image; see [[WP:ALT]]'},coordinates = {code = '<!-- use {{Coord}} -->',dlist = 'using {{tl|Coord}}'},coords = {code = '<!-- use {{Coord}} -->',dlist = 'using {{tl|Coord}}'},native_name = {code = '<!-- name in local language; if more than one, separate ' ..'using {{Plainlist}} use {{lang}}, and omit native_name_lang -->',dlist = 'name in local language; if more than one, separate ' ..'using {{tl|Plainlist}}, use {{tl|lang}}, and omit {{para|native_name_lang}}'},native_name_lang = {code = '<!-- language two- or three-letter ISO code -->',dlist = 'language two- or three-letter ISO code'},start_date = {code = '<!-- {{Start date|YYYY|MM|DD|df=y}} -->',dlist = 'use {{tlx|Start date|YYYY|MM|DD|df=y}}'},end_date = {code = '<!-- {{End date|YYYY|MM|DD|df=y}} -->',dlist = 'use {{tlx|Start date|YYYY|MM|DD|df=y}}'},url = {code = '<!-- use {{URL|example.com}} -->',dlist = 'using {{tl|URL}}'},website = {code = '<!-- use {{URL|example.com}} -->',dlist = 'using {{tls|URL|example.com}}'},}local p = {}local removeDuplicates = require('Module:TableTools').removeDuplicateslocal yesno = require('Module:Yesno')local function makeInvokeFunction(funcName)return function(frame)local getArgs = require('Module:Arguments').getArgsreturn p[funcName](getArgs(frame, {removeBlanks = false}))endendlocal function extractParams(page)local source = mw.title.new(page, 'Template'):getContent()local parameters = {}for parameter in string.gmatch(source, '{{{(.-)%f[}|<>]') dotable.insert(parameters, parameter)endreturn removeDuplicates(parameters)endlocal function map(tbl, transform)local returnTable = {}for k, v in pairs(tbl) doreturnTable[k] = transform(v)endreturn returnTableendlocal function strMap(tbl, transform)local returnTable = map(tbl, transform)return table.concat(returnTable)endfunction p._check(args)local title = args._base or mw.title.getCurrentTitle().fullTextreturn string.format('{{#invoke:Check for unknown parameters|check|unknown=' ..'[[Category:Pages using %s with unknown parameters]]|%s}}', title,table.concat(extractParams(args.base), '|'))endfunction p._code(args)local definitions = yesno(args.definitions)local pad = yesno(args.pad)local parameters = extractParams(args.base)-- Space-pad the parameters to align the equal signs verticallyif pad thenlocal lengthPerPara = map(parameters, function (parameter)return string.len(parameter) end)-- Lua doesn't support printf's <*> to specify the width, apparentlylocal fs = string.format('%%-%ss', math.max(unpack(lengthPerPara)))for i, parameter in pairs(parameters) doparameters[i] = string.format(fs, parameter)endendlocal title = args._base or mw.title.getCurrentTitle().baseTextreturn string.format([[{{%s%s}}]], title, strMap(parameters,function(s)if definitions thenreturn string.format('| %s = %s\n', s,DEFINITIONS[s] and DEFINITIONS[s].code or '')elsereturn string.format('| %s = \n', s)endend))endfunction p._compare(args)local Set = require('Module:Set')local function normaliseParams(parameters)local paramsNorm = {}-- Prepare a key lookup metatable, which will hold the original-- parameter names for each normalised parameter, e.g.-- [test] = {TEST, Test}. paramIndex functions like a Python-- defaultdict, where the default is a table.local paramIndex = setmetatable({}, {__index = function(t, k)if not rawget(t, k) thenrawset(t, k, {})endreturn rawget(t, k)end})for _, parameter in pairs(parameters) dotable.insert(paramsNorm,string.lower(string.gsub(parameter, '%A', '')))table.insert(paramIndex[string.lower(string.gsub(parameter, '%A', ''))], parameter)endparamsNorm = removeDuplicates(paramsNorm)-- Overload key lookup in paramsNorm. While [[Module:Set]] will-- operate on the table (which is to say, the normalised parameters-- array), key access will be by way of the paramIndex metatable.setmetatable(paramsNorm, {__index = paramIndex})return paramsNormendlocal baseParams = extractParams(args.base)local otherParams = extractParams(args.other)local baseNormParams = normaliseParams(Set.valueComplement(otherParams, baseParams))local otherNormParams = normaliseParams(otherParams)return string.format([[Identical:%sSimilar:%sDisparate:%s]],strMap(Set.valueIntersection(baseParams, otherParams),function(v) return string.format('* %s\n', v) end),strMap(Set.valueIntersection(baseNormParams, otherNormParams),function(v) return string.format('* %s < %s [%s]\n',table.concat(baseNormParams[v], '; '),table.concat(otherNormParams[v], '; '),v)end),strMap(Set.valueComplement(otherNormParams, baseNormParams),function(v) return strMap(baseNormParams[v],function(s) return string.format('* %s\n', s) end)end))endfunction p._demo(args)local title = args._base and ('|_template=' .. args._base) or ''return string.format('{{Parameter names example%s|%s}}', title,table.concat(extractParams(args.base), '|'))endfunction p._dlist(args)local definitions = yesno(args.definitions, true)return strMap(extractParams(args.base),function(s)if definitions thenreturn string.format('; %s: %s\n', s,DEFINITIONS[s] and DEFINITIONS[s].dlist or '')elsereturn string.format('; %s: \n', s)endend)endfunction p._list(args)return strMap(extractParams(args.base),function(s) return string.format('* %s\n', s) end)endp.check = makeInvokeFunction('_check')p.code = makeInvokeFunction('_code')p.compare = makeInvokeFunction('_compare')p.demo = makeInvokeFunction('_demo')p.dlist = makeInvokeFunction('_dlist')p.list = makeInvokeFunction('_list')return p
🔥 Top keywords: क्लिओपात्राजिजाबाई शहाजी भोसलेमुखपृष्ठशिवाजी महाराजविशेष:शोधाईद-उल-अधारत्‍नागिरी जिल्हादिशागणपती स्तोत्रेनवग्रह स्तोत्रसंत तुकाराममुंजा (भूत)मुरलीकांत पेटकरज्ञानेश्वरजागतिक दिवसगोवा क्रांती दिनराणी लक्ष्मीबाईरायगड (किल्ला)बाबासाहेब आंबेडकरमहाराष्ट्ररत्‍नागिरीमहाराष्ट्रामधील जिल्हेभारताचे संविधानॐ नमः शिवायमटकास्वामी समर्थमहाराष्ट्रातील अनुसूचित जातींची यादीआंब्यांच्या जातींची यादीशिवाजी महाराजांची राजमुद्रापसायदानमहाराष्ट्र शासनसंभाजी भोसलेए.पी.जे. अब्दुल कलामवटपौर्णिमाज्योतिर्लिंगमराठी भाषाविनायक दामोदर सावरकरमहाराष्ट्रातील इतर मागास वर्गीय जातींची यादीभारत