| 第40行: |
第40行: |
| | results[t] = true | | results[t] = true |
| | end | | 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 = "?"..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] = true |
| | end | | end |
| | end | | end |
| 第57行: |
第72行: |
| | local name = frame.args.name | | local name = frame.args.name |
| | local parents = mw.text.split(frame.args.parents, ",") | | local parents = mw.text.split(frame.args.parents, ",") |
| | + | local parent_property = frame.args.parent_property |
| | local parent_title = frame.args.parent_title | | local parent_title = frame.args.parent_title |
| | local anchor_property = frame.args.anchor_property | | local anchor_property = frame.args.anchor_property |
| | local properties = mw.text.split(frame.args.properties, ",") | | local properties = mw.text.split(frame.args.properties, ",") |
| | + | local children_title = frame.args.children_title |
| | | | |
| | local root = mw.html.create("div") | | local root = mw.html.create("div") |
| 第65行: |
第82行: |
| | _create_list(root, parent_title, parents) | | _create_list(root, parent_title, parents) |
| | mw.smw.set({[anchor_property]=name}) | | 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 | | for i, prop in ipairs(properties) do |
| 第78行: |
第98行: |
| | mw.smw.set({[prop]=k}) | | mw.smw.set({[prop]=k}) |
| | end | | 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 | | end |
| | | | |