Brighter Shores:Style guide/Semantic MediaWiki
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 source]
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 source]
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 source]
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 source]
Defining attributes[edit source]
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 | |
-- 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 source]
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]]
|
Example | Finds all pages that contain a property of "foo" that is "bar" or "baz" |
Lua[edit source]
For details on fetching information via lua, see mw.smw.ask documentation.
Retrieving attributes with #show[edit source]
Code | Display | Function |
---|---|---|
{{#show:Bar|?foo}}
Note: Use |
Example | Shows the property "foo" of page Bar |