求真百科歡迎當事人提供第一手真實資料,洗刷冤屈,終結網路霸凌。

變更

前往: 導覽搜尋

模块:Unsubst

增加 1,884 位元組, 5 年前
导入1个版本
local checkType = require('libraryUtil').checkType
 
local p = {}
 
local BODY_PARAM = '$B'
local specialParams = {
['$Nparams'] = 'template nameparameter list', -- Deprecated ['$aliases'] = 'parameter aliases', ['$flags'] = 'flags', but keeping until it is removed from transcluding templates ['$B'] = 'template content',
}
function p[''] = function .main( frame , body) -- If we are substing, this function returns a template invocation, and if -- not, it returns the template body. The template body can be specified in -- the body parameter, or in the template parameter defined in the -- BODY_PARAM variable. This function can be called from Lua or from -- #invoke.  -- Return the template body if we aren't substing. if not frame:getParentmw.isSubsting() then if body ~= nil then return body elseif frame.args[BODY_PARAM] ~= nil then return frame.args[BODY_PARAM] else error( string.format( "no template content specified (use parameter '%s'{{from #invoke:Unsubst|}} makes no sense without a parent frame' )", BODY_PARAM ), 2) end
end
  -- Sanity check for the frame object. if not type(frame) ~= 'table' or type(frame.args[getParent) ~= '$Bfunction'] or not frame:getParent() then error( "argument #1 to '{{#invoke:Unsubst|}} requires parameter $B (template content)main' must be a frame object with a parent " .. "frame available", 2 )
end
  -- Find the invocation name. local mTemplateInvocation = require('Module:Template invocation') if mwlocal name = mTemplateInvocation.isSubstingname(frame:getParent():getTitle() then) ---- substing -- Combine passed args with passed defaults local args = {} if string.find( ','..(frame.args['$flags'] or '')..',', ',%s*override%s*,' ) then for k, v in pairs( frame:getParent().args ) do args[k] = v end
for k, v in pairs( frame.args ) do
if not specialParams[k] then
if v == '__DATE__' then
v = mw.getContentLanguage():formatDate( 'F Y' ) end args[k] = v end end else for k, v in pairs( frame.args ) do if not specialParams[k] then if v == '__DATE__' then v = mw.getContentLanguage():formatDate( 'F Y 年n月' )
end
args[k] = v
args[k] = v
end
end
 
-- Trim parameters, if not specified otherwise
if not string.find( ','..(frame.args['$flags'] or '')..',', ',%s*keep%-whitespace%s*,' ) then
for k, v in pairs( args ) do args[k] = mw.ustring.match(v, '^%s*(.*)%s*$') or '' end
end
-- Build an equivalent template invocationPull information from parameter aliases local aliases = {} -- First, find the title to use if frame.args['$aliases'] then local titleobj list = mw.titletext.newsplit(frame:getParent(.args['$aliases'], '%s*,%s*' ):getTitle for k, v in ipairs(list ))do local titletmp = mw.text.split( v, '%s*>%s*' ) if titleobj aliases[tonumber(mw.ustring.namespace == 10 then match(tmp[1], '^[1-9][0- NS_TEMPLATE title 9]*$')) or tmp[1]] = titleobj((tonumber(mw.text elseif titleobjustring.namespace == match(tmp[2], '^[1-9][0 then -- NS_MAIN9]*$'))) or tmp[2]) end end for k, v in pairs( aliases ) do title if args[k] and ( not args[v] or args[v] == ':' .. titleobj.text else) then title args[v] = titleobj.prefixedTextargs[k]
end
args[k] = nil
end
-- Build the invocation body with numbered Remove empty parameters, if specified if string.find( ','..(frame.args first['$flags'] or '')..',', ',%s*remove%-empty%s*, ' ) then named local ret tmp = '{{' .. title0
for k, v in ipairs( args ) do
if string.findv ~= '' or ( v, args[k+1] and args[k+1] ~= '') or ( args[k+2] and args[k+2] ~=', 1, true ' ) then -- likely something like 1tmp =foo=bar, we need to do it as a named argk else
break
end
ret = ret .. '|' .. v
args[k] = nil
end
for k, v in pairs( args ) do
ret if v == '' then if not (type(k) == 'number' and k < tmp) then args[k] = ret .nil end end end end  -- Order parameters if frame. args['|$params' ] then local params, tmp = mw.text.split( frame. args['$params'], '%s*,%s*' ), {} for k , v in ipairs(params) do v = tonumber(mw.ustring. match(v, '^[1-9][0-9]*$')) or v if args[v] then tmp[v], args[v] =' .. args[v], nil end
end
return ret .. '}}' else ---- Not substing -- Just return the "body" return frame.for k, v in pairs(args) do tmp['$B'k] .. (frame., args['$N'k] and frame:getParent():getTitle() == mw.title.getCurrentTitle().prefixedText and 'args[[Category:使用$N的Module:Unsubst调用k]]' or ''), nil end args = tmp
end
 
return mTemplateInvocation.invocation(name, args)
end
 
p[''] = p.main -- For backwards compatibility
return p
行政員使用者查核員拒收員巡檢員管理員、water、waterc、waterh、waterm、waterp、waters、watert、waterv、waterw、waterz
10,317
次編輯