This documentation is transcluded from Module:SMWUtil/doc. Changes can be proposed in the talk page.
This module is unused.
This module is neither invoked by a template nor required/loaded by another module. If this is in error, make sure to add
{{Documentation}}
/{{No documentation}}
to the calling template's or parent's module documentation.Function list |
---|
L 5 — p.set L 9 — p.createSubobject L 13 — p.createAnonymousSubobject L 17 — p.askForPages L 22 — p.getPages L 33 — p.get L 37 — p.createQueryString L 43 — p.createTableHeader L 57 — p.checkValue L 71 — p.declareInfoboxProperties |
This module is used to simplify the execution of various SemanticMediawiki parser functions via lua.
local getArgs = require( 'Module:Arguments' ).getArgs
local p = {}
function p.set(frame, data)
frame:callParserFunction("#set", data)
end
function p.createSubobject(frame, identifier, data)
return frame:callParserFunction("#subobject", {identifier, unpack(data)})
end
function p.createAnonymousSubobject(frame, data)
return frame:callParserFunction("#subobject", data)
end
function p.askForPages(frame, queryString, data)
return frame:callParserFunction("#ask", {queryString, unpack(data or {})})
end
-- returns a table with the page names/identifiers that match the query
function p.getPages(frame, queryString)
local str = p.askForPages(frame, queryString, {"link=none", "sep=;"})
local pages = {}
for page in str:gmatch("[^;]+") do
table.insert(pages, page)
end
return pages
end
function p.get(frame, pageName, propertyName, additionalData)
return frame:callParserFunction("#show", {pageName, "?" .. propertyName, unpack(additionalData or {})})
end
function p.createQueryString(categoryName, condition)
local subobjectQuery = "[[-Has subobject::<q>[[Category:" .. categoryName .. "]]</q>]] " .. (condition or "")
local pageQuery = "[[Category:" .. categoryName .. "]] " .. (condition or "")
return subobjectQuery .. " OR " .. pageQuery
end
function p.createTableHeader(frame)
local args = getArgs(frame)
-- the table headers are set via the userparam
local userparam = args["#userparam"] or "Name"
local str = "{| class=\"wikitable\"\n"
str = str .. "! " .. userparam
str = str .. "\n|-"
return str
end
-- returns the second parameter if the first is 'true', otherwise the third
function p.checkValue(frame)
local args = getArgs(frame)
local value = args[1] or ""
local first = args[2] or ""
local second = args[3] or ""
if value:gsub("%s+", "") == "true" then
return first
end
return second
end
-- declares properties for an infobox
function p.declareInfoboxProperties(frame, properties)
local args = getArgs(frame)
local use_subobject = args.use_subobject
local title = args.title or mw.title.getCurrentTitle().text
local smwIdentifier = frame:preprocess("{{FULLPAGENAME}}")
local data = {}
-- defaults
table.insert(properties, "Title")
table.insert(properties, "Image")
table.insert(properties, "Status")
table.insert(properties, "Status Description")
for _, property in ipairs(properties) do
local paramName = p.get(frame, "Property:" .. property, "Parameter Name")
if paramName ~= nil and paramName ~= "" then
local value = args[paramName]
-- set a default value for the title property
if property == "Title" and value == nil then
value = frame:preprocess("{{SUBPAGENAME}}")
end
table.insert(data, property .. "=" .. (value or ""))
end
end
if #data == 0 then
return
end
if use_subobject == "true" then
smwIdentifier = smwIdentifier .. "#" .. title
p.createSubobject(frame, title, data)
else
p.set(frame, data)
end
end
return p