查看“模块:Inherit”的源代码
←
模块:Inherit
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
p = {} function _table_to_keys(tb) local res = {} for i, k in ipairs(tb) do res[k] = true end return res end function _merge_keys(a, b) local res = {} for k, _ in pairs(a) do res[k] = true end for k, _ in pairs(b) do res[k] = true end return res end function _keys_to_table(set) local res = {} local ctr = 1 for k, v in pairs(set) do res[ctr] = k ctr = ctr + 1 end return res end function p.query_inherited_property(anchor_property, query_property, parent_list) local results = {} for idx, parent in ipairs(parent_list) do local anchor_query = "[["..anchor_property.."::"..parent.."]]" local property_query = "[[" .. query_property .. "::+]]" local content_query = "?"..query_property local query = anchor_query .. property_query .. "|" ..content_query .. "|format=plainlist" local res = mw.smw.getQueryResult(query) for j, r in ipairs(res.results) do for k, t in ipairs(r.printouts[query_property]) do results[t.fulltext] = true end end end return results end function p.query_children(name, anchor_property, parent_property) local results = {} local anchor_query = "[["..parent_property.."::"..name.."]]" local property_query = "[[" .. anchor_property .. "::+]]" local content_query = "?"..anchor_property local query = anchor_query .. property_query .. "|" ..content_query .. "|format=plainlist" local res = mw.smw.getQueryResult(query) for j, r in ipairs(res.results) do for k, t in ipairs(r.printouts[anchor_property]) do results[t.fulltext] = true end end return results end function _create_list(root, title, list) local node = root:tag("div") node:wikitext([[ ''' ]] .. title .. [[''':]]) local ul = node:tag("ul") for k, v in ipairs(list) do ul:tag("li"):wikitext("[["..v.."]]") end end function p.inherited_lists(frame) local name = frame.args.name local parents = (frame.args.parents and #frame.args.parents > 0) and mw.text.split(frame.args.parents, ",") or {} local parent_property = frame.args.parent_property local parent_title = frame.args.parent_title local anchor_property = frame.args.anchor_property local properties = mw.text.split(frame.args.properties, ",") local children_title = frame.args.children_title local root = mw.html.create("div") _create_list(root, parent_title, parents) mw.smw.set({[anchor_property]=name}) for i, parent in ipairs(parents) do mw.smw.set({[parent_property]=parent}) end for i, prop in ipairs(properties) do local title = frame.args[prop.."_title"] local values_str = frame.args[prop.."_values"] local values = (values_str and #values_str > 0) and mw.text.split(values_str, ",") or {} local values_set = _table_to_keys(values) local inherited_values = p.query_inherited_property(anchor_property, prop, parents) mw.logObject(inherited_values) local final_values = _merge_keys(values_set, inherited_values) local final_list = _keys_to_table(final_values) _create_list(root, title, final_list) for i, k in ipairs(final_list) do mw.smw.set({[prop]=k}) end end if children_title then local children = p.query_children(name, anchor_property, parent_property) local children_list = _keys_to_table(children) _create_list(root, children_title, children_list) end return root:done() end return p
该页面使用的模板:
模块:Inherit/doc
(
查看源代码
)
返回至
模块:Inherit
。
导航菜单
个人工具
创建账户
登录
名字空间
模块
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息