匿名
未登录
中文(中国大陆)
登录
「荏苒之境」
搜索
查看“︁模块:TemplateDemo”︁的源代码
来自「荏苒之境」
命名空间
模块
讨论
更多
更多
页面操作
阅读
查看源代码
历史
清除缓存
←
模块:TemplateDemo
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local html = mw.html local template_demo = {} local function trim(str) return string.gsub(str, "^%s*(.-)%s*$", "%1") end local function parse_template_data(title) local content = mw.title.new(title).content local raw = string.match(content, "<templatedata>(.-)</templatedata>") if raw == nil then return nil end local succ, res = pcall(mw.text.jsonDecode, raw) return succ and res or nil end local function append_template_argument(t, k, v) local num = tonumber(k) if num ~= nil then if num == 1 then k = nil else k = tostring(num - 1) end end if k ~= nil then t[#t+1] = "| " t[#t+1] = k t[#t+1] = " = " t[#t+1] = v t[#t+1] = "\n" end end template_demo.show = function(frame) local args = frame.args local template_name = args[1] if template_name == nil or template_name == '' then return html.create("p"):addClass("error") :wikitext("没有指定模板名!") end local t = {"{{", trim(template_name), "\n"} local template_data = parse_template_data(frame:getTitle()) local args = frame:getParent().args if type(template_data.paramOrder) == "table" then local order = template_data.paramOrder for i = 1, #order do local k = paramOrder[i] local v = args[k] if v ~= nil then append_template_argument(t, k, v) end end else for k, v in pairs(args) do append_template_argument(t, k, v) end end t[#t+1] = "}}" local source = table.concat(t) local result = frame:preprocess(source) return result.."示例:\n<pre>"..source.."\n</pre>" end return template_demo
该页面使用的模板:
模块:TemplateDemo/doc
(
查看源代码
)
返回
模块:TemplateDemo
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
wiki工具
wiki工具
Cargo数据
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志