第1行: |
第1行: |
| p = {} | | p = {} |
| | | |
− | function p.keys_to_table(set) | + | function _table_to_keys(tb) |
| + | local res = {} |
| + | for i, k in ipairs(tb) do |
| + | res[k] = true |
| + | end |
| + | return res |
| + | end |
| + | |
| + | function _merge_keys(...) |
| + | local res = {} |
| + | for m in ipairs{...} do |
| + | for k, _ in ipairs(m) do |
| + | res[k] = true |
| + | end |
| + | end |
| + | return res |
| + | end |
| + | |
| + | function _keys_to_table(set) |
| local res = {} | | local res = {} |
| for k, v in ipairs(set) do | | for k, v in ipairs(set) do |
第25行: |
第43行: |
| return results | | return results |
| end | | end |
| + | |
| + | function _create_list(root, title, list) |
| + | local node = root:tag("div") |
| + | node:wikitext([[ ''' ]] .. title .. [[''':]]) |
| + | local ul = node:tag("ul") |
| + | for k, v in ipair(list) do |
| + | ul:tag("li"):wikitext("[["..v.."]]") |
| + | end |
| + | end |
| + | |
| + | function p.inherited_lists(frame) |
| + | local name = frame.args.name |
| + | local parents = mw.text.split(frame.args.parents, ",") |
| + | local parent_title = frame.args.parent_title |
| + | local anchor_property = frame.args.anchor_property |
| + | local properties = mw.text.split(frame.args.properties, ",") |
| + | |
| + | local root = mw.html.create("div") |
| + | |
| + | _create_list(root, parent_title, parents) |
| + | mw.smw.set({[anchor_property]=name}) |
| + | |
| + | for i, prop in ipairs(properties) do |
| + | local title = frame.args[prop.."_title"] |
| + | local values = mw.text.split(frame.args[prop.."_values"]) |
| + | local values_set = _table_to_keys(values) |
| + | local inherited_values = p.query_inherited_property(anchor_property, prop, parents) |
| + | 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 |
| + | |
| + | return root:done() |
| + | end |
| + | |
| return p | | return p |