Brighter Shores:Style guide/Semantic MediaWiki

Revision as of 13:58, 15 November 2024 by BlackHawk (talk | contribs) (Created page with "{{Shortcut|BS:SMW}} '''Semantic MediaWiki''' is an excellent tool for creating retrievable data across every page. This project page aims to standardise the usage of SMW. For more details on how to use SMW, see [https://www.semantic-mediawiki.org/wiki/Help:User_manual the manual]. ==Declaring attributes== Most properties should be defined in infoboxes or other templates. In the few cases where this needs to be done inline, use {{T|Set}}. ==Fetching data== All attribute...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Semantic MediaWiki is an excellent tool for creating retrievable data across every page. This project page aims to standardise the usage of SMW. For more details on how to use SMW, see the manual.

Declaring attributes Edit

Most properties should be defined in infoboxes or other templates. In the few cases where this needs to be done inline, use {{Set}}.

Fetching data Edit

All attribute requests should be done via wrapper templates. These will be watched by an abuse filter that warns and prevents editors from changing dynamic data.

The primary template used to fetch data inline is {{Get}}. For more complex data display, see #ask and #show in the manual.

Property pages Edit

Property pages are where data types of the properties are defined. They should also include a short description and a list of what modules/templates automatically set the property. This can all be done using the {{property}} template.

{{Property|Name=|type=|desc=|templates=}}

Cheatsheet Edit

Defining attributes Edit

Code Display Function
[[foo::bar]] bar Defines the property "foo" as bar and creates a link to bar
[[foo::bar|baz]] baz Defines the property "foo" as bar and creates a link to bar on the text "baz"
[[foo::bar| ]] Defines the property "foo" as bar and creates no text
{{#set:foo=bar}} Defines the property "foo" as bar and displays nothing. Multiple properties can be defined this way.

Note: Use {{Set}} if defining properties in the content namespaces.

-- setup data table - standard key-value pairs where key is property name and value is property value
local data1 = {
    foo = 'bar',
    ['Has property2'] = 'value2'
}
-- set the properties
local result1 = mw.smw.set(data1)

if result1 == true then
    -- everything fine
else
    -- error message is in result1.error
end


-- setup data table - an array of strings, in format 'propname=propvalue'
local data2 = {
    'foo=bar',
    'Has property2=value2'
}
-- set the properties
local result2 = mw.smw.set(data2)

if result2 == true then
    -- everything fine
else
    -- error message is in result2.error
end
Used in lua modules to set data, similarly to the #set parser function - all methods are equivalent, so use whichever is easier for the module at the time. See SemanticScribunto documentation for more information.
-- setup data table - multiple property values for one property
local data3 = {
    foo = {
        'bar',
        'baz',
        'qok'
    }
}
-- set the properties
local result3 = mw.smw.set(data3)

if result3 == true then
    -- everything fine
else
    -- error message is in result3.error
end
As above, but setting multiple values to the same property.

Retrieving attributes with #ask Edit

Code Display Function
[[Category:Foo]] Example Finds all pages that are in category "foo"
?foo Example Shows the property "foo" of all results
limit=X Example Confines the displayed results to limit X
offset=X Example Begins the search at an offset of X
[[foo::bar]] Example Finds all pages that contain a property of "foo" that is equal to "bar"
[[foo::!bar]] Example Finds all pages that contain a property of "foo" that is not equal to "bar"
[[foo::>X]] Example Finds all pages that contain a property of "foo" that is greater than or equal to X
[[foo::>>X]] Example Finds all pages that contain a property of "foo" that is greater than X
[[foo::<X]] Example Finds all pages that contain a property of "foo" that is less than or equal to X
[[foo::<<X]] Example Finds all pages that contain a property of "foo" that is less than X
[[foo::bar||baz]]

[[foo::bar]] OR [[foo::baz]]

Example Finds all pages that contain a property of "foo" that is "bar" or "baz"

Lua Edit

For details on fetching information via lua, see mw.smw.ask documentation.

Retrieving attributes with #show Edit

Code Display Function
{{#show:Bar|?foo}}

Note: Use {{Get|Bar|foo}}

Example Shows the property "foo" of page Bar

See also Edit