此处公告通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告
本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~
编辑帮助:目录BWIKI反馈留言板

欢迎来到奇迹暖暖WIKI

bugfix1001.88136
全站通知:

模块:工具

来自奇迹暖暖WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

false false true


local p = {}
p["材料查询"] = function (frame)
	local pattern = mw.text.jsonDecode(frame:preprocess(mw.title.new('Mediawiki:Gadget-MaterialPattern.json'):getContent()))
	local mainType = frame.args[1]
	local clothId = tonumber(frame.args[2])
	local mainTypeTable = {'发型','连衣裙','外套','上装','下装','袜子','鞋子','饰品','妆容','萤光之灵'}
	local mainTypeIndex = 0
	local materialTable = {}
	local materialString = {}
	for i, v in ipairs(mainTypeTable) do
	    if v == mainType then
	    	mainTypeIndex = i - 1
	    	break
	    end
	end
	for i, v in ipairs(pattern["pattern_m"]) do
	    if v[1] == mainTypeIndex and v[2] == clothId then
	    	table.insert(materialTable, "{{#ask:[[分类:部件]][[类别::~" .. mainTypeTable[v[3] + 1] .. "*]][[编号::" .. v[4] .."]]}} x " .. v[5])
	    end
	    if v[1] >= mainTypeIndex and v[2] > clothId then
	    	break
	    end
	end
	materialString = table.concat( materialTable, " + " )
	if materialString ~= "" then 
		materialString = "(" .. materialString .. ")"
	end
	return frame:preprocess(materialString)
end
p["正则替换"] = function (frame)
    local matchPattern = string.gsub(frame.args[2], "</?nowiki>", "")
	local tempString = string.gsub(frame.args[1], matchPattern,frame.args[3])
	return frame:preprocess("{{#tag:pre|" .. frame.args[1] .. frame.args[2] .. frame.args[3] .. tempString .."}} ")
end

--[[
* 测试输入:
mw.log(p.pre(
   mw.getCurrentFrame():newChild{
      title="pre",
      args={"<pre>{{部件|银狼}}</pre>"}
   }
))
]]--


p["codeblock"] = function(frame)
	local wikitext = mw.text.unstripNoWiki(frame.args[1]):gsub('&lt;', '<'):gsub('&gt;', '>')
	return '<div class="panel panel-default">'
        ..     '<div class="panel-body">' .. frame:preprocess(wikitext) .. '</div>'
        ..     '<div class="panel-footer">' .. frame:extensionTag('pre', wikitext) .. '</div>' -- 直接用pre标签会丢失分类
     	.. '</div>'
end
p["embed"] = function(frame)
	local wikitext = frame:expandTemplate({title =frame.args[1]})
	return "" -- wikitext
end
p["getContent"] = function(frame)
	local wikitext = mw.title.new(frame.args[1]):getContent()
	return wikitext
end
p["processContent"] = function(frame)
	local wikitext = mw.title.new(frame.args[1]):getContent()
	wikitext = frame:preprocess(wikitext)
	return "" -- frame:preprocess(wikitext)
end
p["ifexist"] = function(frame)
	local wikitext = mw.title.new(frame.args[1]):getContent()
	if wikitext == nil then 
		return ""
	end
	return #wikitext
end


-- 辅助函数,用于字符串替换
local function rreplace(input, pattern, replacement)
    return mw.ustring.gsub(input, pattern, replacement)
end

-- 辅助函数,用于正则匹配
local function rmatch(input, pattern)
    return mw.ustring.match(input, pattern)
end


-- 原模板实现:{{#switch:{{{类型|}}}|函数={{#tag:div|{{#tag:span|{&#123;|class="f"}}{{#rreplace:{{{{{{prefix|}}}1|#函数名}}}|^([^:]+)(:*)([\s\S]*)$|{{#tag:span|$1$2|class="fn"}}$3}}{{#forargs:{{{prefix|}}}|k|v|{{#rmatch:{{#var:k}}|^(类型{{!}}1)$||{{#vardefine:s|1}}{{#tag:span|&#124;|class="fn"}}{{#rmatch:{{#var:k}}|^(\d+)$||{{#var:k}}&#61;|multiline=1}}{{#var:v}}|multiline=1}}}}{{#ifeq:{{#var:s}}|1|{{#vardefine:s|0}}}}{{#tag:span|&#125;}|class="f"}}|class="gaoliang"}}}}
-- 原模板输入:{{高亮|类型=函数|#ifeq: 01 | 1 | equal | not equal}}
-- 原模板输出:<div class="gaoliang"><span class="f">{{</span><span class="fn">#ifeq:</span> 01<span class="fn">|</span>1<span class="fn">|</span>equal<span class="fn">|</span>not equal<span class="f">}}</span></div>
-- 模块测试代码:mw.log(p["函数"]({ args = {"#ifeq: 01 ", "1","equal","not equal" } }))
 p["函数"] = function(frame)
    local args = {}
    local output = ""
    for k, v in pairs(frame.args) do
        args[k] = v
    end
    local functionName = table.remove(args, 1)
  
    -- Apply regular expression replacement for the function name
    local nameParts = mw.text.split(functionName, ':', true)
    if #nameParts > 1 then
        functionName = '<span class="fn">' .. nameParts[1] .. ':</span>' .. table.concat(nameParts, '', 2)
    else
        functionName = '<span class="fn">' .. functionName .. '</span>'
    end
    output =  '<span class="f">{{</span>' .. functionName

    for i, v in ipairs(args) do
        output = output .. '<span class="fn">|</span>' .. mw.text.trim(v)
    end

    output = '<div class="gaoliang">' .. output .. '<span class="f">}}</span>' .. '</div>'
    return output
end


-- 原模板实现:{{#switch:{{{类型|}}}|函数={{#tag:div|{{#tag:span|{&#123;|class="f"}}{{#rreplace:{{{{{{prefix|}}}1|#函数名}}}|^([^:]+)(:*)([\s\S]*)$|{{#tag:span|$1$2|class="fn"}}$3}}{{#forargs:{{{prefix|}}}|k|v|{{#rmatch:{{#var:k}}|^(类型{{!}}1)$||{{#vardefine:s|1}}{{#tag:span|&#124;|class="fn"}}{{#rmatch:{{#var:k}}|^(\d+)$||{{#var:k}}&#61;|multiline=1}}{{#var:v}}|multiline=1}}}}{{#ifeq:{{#var:s}}|1|{{#vardefine:s|0}}}}{{#tag:span|&#125;}|class="f"}}|class="gaoliang"}}}}
-- 原模板输入:{{高亮|类型=函数|#ifeq: 01 | 1 | equal | not equal}}
-- 原模板输出:<div class="gaoliang"><span class="f">{{</span><span class="fn">#ifeq:</span> 01<span class="fn">|</span>1<span class="fn">|</span>equal<span class="fn">|</span>not equal<span class="f">}}</span></div>
-- 模块测试代码:mw.log(p["函数"]({ args = {"#ifeq: 01 ", "1","equal","not equal" } }))
 p["函数m"] = function(frame)
    local args = {}
    local output = ""
    for k, v in pairs(frame:getParent().args) do
        args[k] = v
    end
    local functionName = table.remove(args, 1)
  
    -- Apply regular expression replacement for the function name
    local nameParts = mw.text.split(functionName, ':', true)
    if #nameParts > 1 then
        functionName = '<span class="fn">' .. nameParts[1] .. ':</span>' .. table.concat(nameParts, '', 2)
    else
        functionName = '<span class="fn">' .. functionName .. '</span>'
    end
    output =  '<span class="f">{{</span>' .. functionName

    for i, v in ipairs(args) do
        output = output .. '<span class="fn">|</span>' .. mw.text.trim(v)
    end

    output = '<div class="gaoliang">' .. output .. '<span class="f">}}</span>' .. '</div>'
    return output
end

 p["函数c"] = function(frame)
    local args = {}
    local output = ""
    for k, v in pairs(frame:getParent().args) do
        args[k] = v
    end
    output = mw.text.trim(table.remove(args, 1))
    for i, v in ipairs(args) do
        output = output .. '|' .. mw.text.trim(v)
    end

    output = '<code>{{' .. output .. '}}</code>'
    return output
end


-- 模块测试代码:mw.log(p["code"]({ args = {"<nowiki>{{#ifeq: 01 | 1 | equal | not equal}}</nowiki>" } }))
p["code"] = function(frame)
    
end


return p