Bots, Bureaucrats, Moderators (CommentStreams), Interface administrators, Administrators (Semantic MediaWiki), Curators (Semantic MediaWiki), Editors (Semantic MediaWiki), Administrators
1,273
edits
(Update package: OSW Core) Tag: Reverted |
m (Reverted edits by 0000-0003-0410-3616 (talk) to last revision by Maintenance script) Tag: Rollback |
||
Line 23: | Line 23: | ||
} | } | ||
p.slots = { --slot names | p.slots = { --slot names | ||
jsondata='jsondata', | jsondata='jsondata', | ||
jsonschema='jsonschema', | jsonschema='jsonschema', | ||
Line 35: | Line 34: | ||
query='query' | query='query' | ||
} | } | ||
--loads json from a wiki page | --loads json from a wiki page | ||
Line 43: | Line 40: | ||
function p.loadJson(args) | function p.loadJson(args) | ||
local page_title = p.defaultArg(args.title, "JsonSchema:Entity") --for testing | local page_title = p.defaultArg(args.title, "JsonSchema:Entity") --for testing | ||
local slot = p.defaultArg(args.slot, | local slot = p.defaultArg(args.slot, nil) | ||
local debug = p.defaultArg(args.debug, nil) | local debug = p.defaultArg(args.debug, nil) | ||
local msg = "" | local msg = "" | ||
Line 49: | Line 46: | ||
local json = {} | local json = {} | ||
if (slot == nil) then | |||
if (slot == | |||
--json = mw.loadJsonData( "JsonSchema:Entity" ) --requires MediaWiki 1.39 | --json = mw.loadJsonData( "JsonSchema:Entity" ) --requires MediaWiki 1.39 | ||
local page = mw.title.makeTitle(p.splitString(page_title, ':')[1], p.splitString(page_title, ':')[2]) | local page = mw.title.makeTitle(p.splitString(page_title, ':')[1], p.splitString(page_title, ':')[2]) | ||
Line 64: | Line 52: | ||
if (text ~= nil) then json = mw.text.jsonDecode(text) end | if (text ~= nil) then json = mw.text.jsonDecode(text) end | ||
else | else | ||
if (debug) then msg = msg .. "Fetch slot " .. p.slots.jsondata .. " | if (debug) then msg = msg .. "Fetch slot " .. p.slots.jsondata .. " from page " .. title .. "<br>" end | ||
local text = mw.slots.slotContent( slot , page_title ) | local text = mw.slots.slotContent( slot , page_title ) | ||
if (text ~= nil) then json = mw.text.jsonDecode(text) end | if (text ~= nil) then json = mw.text.jsonDecode(text) end | ||
Line 70: | Line 58: | ||
--mw.logObject(json) | --mw.logObject(json) | ||
return {json=json, debug_msg=msg} | return {json=json, debug_msg=msg} | ||
end | end | ||
-- test: mw.logObject(p.walkJsonSchema({jsonschema=p.loadJson({title="Category:Hardware", slot="jsonschema"}).json, debug=true}).jsonschema) | -- test: mw.logObject(p.walkJsonSchema({jsonschema=p.loadJson({title="Category:Hardware", slot="jsonschema"}).json, debug=true}).jsonschema) | ||
Line 316: | Line 302: | ||
-- store metadata where properties were defined / overridden | -- store metadata where properties were defined / overridden | ||
for i, category in ipairs(schema_res.visited) do | for i, category in ipairs(schema_res.visited) do | ||
for k, v in pairs | for k, v in pairs(schema_res.jsonschemas[category]['properties']) do | ||
if smw_res.definitions[k] == nil then smw_res.definitions[k] = {} end | if smw_res.definitions[k] == nil then smw_res.definitions[k] = {} end | ||
if smw_res.definitions[k]['defined_in'] == nil then smw_res.definitions[k]['defined_in'] = {} end | if smw_res.definitions[k]['defined_in'] == nil then smw_res.definitions[k]['defined_in'] = {} end | ||
Line 362: | Line 348: | ||
if j > i then | if j > i then | ||
local subjsonschema = schema_res.jsonschemas[subcategory] | local subjsonschema = schema_res.jsonschemas[subcategory] | ||
for k, v in pairs | for k, v in pairs(subjsonschema['properties']) do | ||
-- skip properties that are overwritten in subschemas, render them only once at the most specific position | -- skip properties that are overwritten in subschemas, render them only once at the most specific position | ||
ignore_properties[k] = true | ignore_properties[k] = true | ||
Line 386: | Line 372: | ||
-- Todo: Consider moving the category and this block to p.getSemanticProperties with store=true. However, settings categories with @category is only possible for subobjects | -- Todo: Consider moving the category and this block to p.getSemanticProperties with store=true. However, settings categories with @category is only possible for subobjects | ||
if (smw_res ~= nil) then | if (smw_res ~= nil) then | ||
if (debug) then msg = msg .. "Store page properties" end | if (debug) then msg = msg .. "Store page properties" end | ||
-- category handling | -- category handling | ||
Line 397: | Line 380: | ||
-- label and display title handling | -- label and display title handling | ||
smw_res.properties['Display title of'] = display_label --set special property display title | |||
smw_res.properties['Display title of lowercase'] = display_label:lower() --store lowercase for case insensitive query | |||
smw_res.properties['Display title of normalized'] = display_label:lower():gsub('[^%w]+','') --store with all non-alphanumeric chars removed for normalized query | |||
p.setNormalizedLabel(smw_res.properties) --build normalized multilang label | p.setNormalizedLabel(smw_res.properties) --build normalized multilang label | ||
mw.ext.displaytitle.set(display_label) | mw.ext.displaytitle.set(display_label) | ||
Line 436: | Line 417: | ||
local ignore_properties = p.defaultArg(args.ignore_properties, {}) | local ignore_properties = p.defaultArg(args.ignore_properties, {}) | ||
local schema_label = | local schema_label = "" | ||
if schema['title'] ~= nil then schema_label = schema['title'] end | |||
-- see also: https://help.fandom.com/wiki/Extension:Scribunto/HTML_Library_usage_notes | -- see also: https://help.fandom.com/wiki/Extension:Scribunto/HTML_Library_usage_notes | ||
Line 453: | Line 435: | ||
--mw.logObject(def) | --mw.logObject(def) | ||
local label = | local label = k | ||
if def['title'] ~= nil then label = def['title'] end | |||
if def['title*'] ~= nil then -- multilang label with switch | |||
label = "{{#switch:{{USERLANGUAGECODE}} |#default=" .. label | |||
for k,v in pairs(def['title*']) do label = label .. " |" .. k .. "=" .. v end | |||
label = label .. " }}" | |||
end | |||
local description = | local description = "" | ||
if def['description'] ~= nil then description = def['description'] end | |||
if def['description*'] ~= nil then -- multilang label with switch | |||
description = "{{#switch:{{USERLANGUAGECODE}} |#default=" .. description | |||
for k,v in pairs(def['description*']) do description = description .. " |" .. k .. "=" .. v end | |||
description = description .. " }}" | |||
end | |||
if (p.tableLength(p.defaultArgPath(property_definitions, {k, 'defined_in'}, {})) > 0) then description = description .. "<br>Definition: " end | if (p.tableLength(p.defaultArgPath(property_definitions, {k, 'defined_in'}, {})) > 0) then description = description .. "<br>Definition: " end | ||
for i, c in pairs(p.defaultArgPath(property_definitions, {k, 'defined_in'}, {})) do | for i, c in pairs(p.defaultArgPath(property_definitions, {k, 'defined_in'}, {})) do | ||
Line 490: | Line 484: | ||
elseif (type(v) == 'boolean') then | elseif (type(v) == 'boolean') then | ||
if (v) then v = "✅" else v = "❌" end -- green check mark or red cross | if (v) then v = "✅" else v = "❌" end -- green check mark or red cross | ||
elseif ( | elseif ((string.len(e) > 100) and (string.find(e, "{{") == nil) and (string.find(e, "</") == nil)) then | ||
e = string.sub(e, 1, 100) .. "..."; -- limit infobox plain text to max 100 chars | e = string.sub(e, 1, 100) .. "..."; -- limit infobox plain text to max 100 chars | ||
elseif (debug) then | elseif (debug) then | ||
Line 517: | Line 511: | ||
elseif (type(v) == 'boolean') then | elseif (type(v) == 'boolean') then | ||
if (v) then v = "✅" else v = "❌" end -- green check mark or red cross | if (v) then v = "✅" else v = "❌" end -- green check mark or red cross | ||
elseif ( | elseif ((string.len(v) > 100) and (string.find(v, "{{") == nil) and (string.find(v, "</") == nil)) then | ||
v = string.sub(v, 1, 100) .. "..."; -- limit infobox plain text to max 100 chars | v = string.sub(v, 1, 100) .. "..."; -- limit infobox plain text to max 100 chars | ||
elseif (debug) then | elseif (debug) then | ||
Line 796: | Line 790: | ||
p.tableMerge(properties['@category'], properties[p.keys.category_pseudoproperty]) -- from json-ld context 'Property:Category' | p.tableMerge(properties['@category'], properties[p.keys.category_pseudoproperty]) -- from json-ld context 'Property:Category' | ||
properties[p.keys.category_pseudoproperty] = nil -- delete pseudo property | properties[p.keys.category_pseudoproperty] = nil -- delete pseudo property | ||
if (jsondata[p.keys.name] ~= nil) then properties['Display title of'] = jsondata[p.keys.name] | |||
elseif (jsondata[p.keys.label] ~= nil and jsondata[p.keys.label][1] ~= nil) then properties['Display title of'] = p.splitString(jsondata[p.keys.label][1], '@')[1] | |||
else properties['Display title of'] = p.defaultArg(subschema['title'], "") end | |||
p.setNormalizedLabel(properties) --build normalized multilang label | p.setNormalizedLabel(properties) --build normalized multilang label | ||
if (p.tableLength(properties) > 0) then | if (p.tableLength(properties) > 0) then | ||
Line 1,041: | Line 1,032: | ||
for k, v in pairs(obj) do res[p.copy(k, s)] = p.copy(v, s) end | for k, v in pairs(obj) do res[p.copy(k, s)] = p.copy(v, s) end | ||
return res | return res | ||
end | end | ||
Line 1,090: | Line 1,065: | ||
end | end | ||
end | end | ||
end | end | ||
return p | return p |