Tesseract:Style guide/Semantic MediaWiki

From the Tesseract Wiki, the wiki for all things Marvel Cinematic Universe
Jump to navigation Jump to search
Shortcut:

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::fridge]] fridge Defines the property "foo" as fridge and creates a link to fridge
[[foo::fridge|fridg]] fridg Defines the property "foo" as fridge and creates a link to fridge on the text "fridg"
[[foo::fridge| ]] Defines the property "foo" as fridge and creates no text
{{#set:foo=fridge}} Defines the property "foo" as fridge 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 = 'fridge',
    ['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=fridge',
    '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 = {
        'fridge',
        '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::fridge]] Example Finds all pages that contain a property of "foo" that is equal to "fridge"
[[foo::!fridge]] Example Finds all pages that contain a property of "foo" that is not equal to "fridge"
[[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::fridge||baz]]

[[foo::fridge]] OR [[foo::baz]]

Example Finds all pages that contain a property of "foo" that is "fridge" 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:Fridge|?foo}}

Note: Use {{get|Fridge|foo}}

Example Shows the property "foo" of page Fridge

See also[edit source]