Zeroclanzhang(讨论 | 贡献) 无编辑摘要 |
Zeroclanzhang(讨论 | 贡献) 无编辑摘要 |
||
| 第1行: | 第1行: | ||
-- Module: | -- Module:NavplateSMWRow2 | ||
local p = {} | local p = {} | ||
local mw = require('mw') | local mw = require('mw') | ||
| 第7行: | 第7行: | ||
local cache = {} | local cache = {} | ||
function p. | function p.navplateSmwRow2(frame) | ||
local category = frame.args[1] | local category = frame.args[1] | ||
local property = frame.args[2] | local property = frame.args[2] | ||
local text = frame.args[3] | local text = frame.args[3] | ||
local icon = frame.args[4] | local icon = frame.args[4] | ||
-- 参数有效性检查 | |||
if not category or not property then | |||
return '错误:缺少必要的参数' | |||
end | |||
-- 使用缓存结果,减少查询 | -- 使用缓存结果,减少查询 | ||
local cacheKey = category .. | local cacheKey = category .. property .. (text or '') .. (icon or '') | ||
if cache[cacheKey] then | if cache[cacheKey] then | ||
return cache[cacheKey] | return cache[cacheKey] | ||
| 第40行: | 第45行: | ||
:wikitext(icon and '[[File:' .. icon .. '|20px|link=]]' or '') | :wikitext(icon and '[[File:' .. icon .. '|20px|link=]]' or '') | ||
:wikitext(text) | :wikitext(text) | ||
) | |||
:node(mw.html.create('div') | :node(mw.html.create('div') | ||
:addClass('template-navplate-item__list') | :addClass('template-navplate-item__list') | ||
:wikitext(results) | :wikitext(results) | ||
) | |||
:allDone() | :allDone() | ||
end | end | ||
return p | return p | ||
2024年1月24日 (三) 15:01的版本
可在模块:Navplate SMW row/doc创建此模块的帮助文档
-- Module:NavplateSMWRow2
local p = {}
local mw = require('mw')
local frame = mw.getCurrentFrame()
-- 缓存查询结果
local cache = {}
function p.navplateSmwRow2(frame)
local category = frame.args[1]
local property = frame.args[2]
local text = frame.args[3]
local icon = frame.args[4]
-- 参数有效性检查
if not category or not property then
return '错误:缺少必要的参数'
end
-- 使用缓存结果,减少查询
local cacheKey = category .. property .. (text or '') .. (icon or '')
if cache[cacheKey] then
return cache[cacheKey]
end
-- 构建查询
local query = '[[Category:' .. category .. ']]'
if property and property:find("::") then
local propertyParts = mw.text.split(property, "::")
query = query .. '[[Category:' .. propertyParts[1] .. ']]'
query = query .. '[[' .. propertyParts[2] .. '::SubCategory]]'
end
-- 执行查询
local results = frame:extensionTag('ask', query .. '|format=list')
-- 缓存查询结果
cache[cacheKey] = results
-- 格式化输出
return mw.html.create('div')
:addClass('template-navplate-item')
:node(mw.html.create('div')
:addClass('template-navplate-item__label')
:wikitext(icon and '[[File:' .. icon .. '|20px|link=]]' or '')
:wikitext(text)
)
:node(mw.html.create('div')
:addClass('template-navplate-item__list')
:wikitext(results)
)
:allDone()
end
return p