Help:SMW

From Guild Wars 2 Wiki
Jump to navigationJump to search

Semantic MediaWiki, or SMW, is an advanced feature on Guild Wars 2 Wiki that allows us to store data on articles in a way that it can be queried and displayed in other articles. In other words, it allows us to automate the display of information across articles and reduce duplication of work. This is useful not only in that it reduces the workload of our editors, but it also prevents less visited articles from becoming outdated.

It is strongly recommended not to dabble with SMW until you have a basic understanding of how Templates work, as they are used heavily in manipulating SMW properties.

Overview[edit]

There are three stages to working with SMW.

  1. Define the data type to be stored on the Property page.
  2. Set property values on the source page.
  3. Retrieve those property values on another target page (or many pages).

The examples on this page will use the following:

  • Property → Property:Has game icon, which as the name implies, stores the name of the file associated with a given page.
  • A source page → We'll pretend we're recreating the Meteor Shower page
  • A target page → We could pretend we'll be displaying the information on the Staff weapon page.

Defining types on Property pages[edit]

Pages prefixed with "Property:" signify that they are within the Property namespace. On this wiki, they can be found under Category:Properties. Most properties have already been set up, but occasionally as new content is added it is considered beneficial to create new properties to store additional information.

Take a look at Property:Has game icon. If you press "edit" at the top, you'll see the following:

  • This [[has type::page]] property identifies the filename where the subject's in-game icon is stored on the wiki.

The double-colon within double brackets notation shows that a property is being set. All property pages will set the data "type" property. In this example all values set for "Property:Has game icon" are of type "page". Most properties will use "Text", "Page" or "Number". The other more niche types can be observed on Special:Types.

Setting property values[edit]

There are two typical methods of setting property values. As an example for the Meteor Shower page you might write:

  • [[Has game icon::File:Meteor Shower.png]] — As well as setting the Has game icon property value, this will also display the stored value, in this case Meteor Shower.png.
  • {{#set: Has game icon=File:Meteor Shower.png }} — This will set the Has game icon property value, but will not display the stored value.

Editing a page containing either of the above statements, and then pressing Preview, would show a preview of the stored property values in a box beneath the main article.

Pressing submit on a page with either of the above would then store the value against the property. At this point you could click on the "Browse properties" button in the sidebar which would take you to Special:Browse/Meteor Shower. The Browse page displays a list of all of the properties that have been set on a given page (on the left), and all of their respective values (on the right). Any listed property could potentially be retrieved from another page.

Setting properties is usually done in a template, often an infobox template which appears at the top-right of an article.

Retrieving the information[edit]

There are two methods to retrieve a stored property:

  • {{#show: Meteor Shower | ?Has game icon }}— #show: works great for straightforward simple requests.
  • {{#ask: [[Meteor Shower]] | ?Has game icon | headers = hide | mainlabel = - }}— #ask: also works. If you were to remove the "headers = hide" and "mainlabel = -" parts, the information would be displayed in a table with a heading for each different property retrieved.

The first part of the statement (in green) identifies the page(s) for which the information is being requested. The second part (in purple) identifies the properties to be retrieved, prefixed with a question mark. The third optional part (in orange) of the statement changes the output formatting.

Although #ask: seems more awkward than #show:, it is more powerful when trying to retrieve the information from multiple pages. As an example, you could retrieve all of the icons for "Staff" weapon skills associated with "Fire Attunement" by:

  • {{#ask: [[Is for weapon::Staff]] [[Is for attunement::Fire Attunement]] | ?Has game icon | format = table }}

To use a slightly more complicated real template as an example, check out the source of Template:Weapon skill table row:

{{#ask: [[{{{1}}}]]
 | ?Has canonical name
 | ?Has game icon
 | ?Has game description
 | ?Is for profession
 | ?Has skill type
 | ?Has skill slot number
 | ?Has activation time
 | ?Has recharge time 
 | ?Has initiative cost
 | ?Has energy cost
 | ?Is for weapon
 | ?Requires offhand
 | ?Has chain sequence position
 | ?Is usable underwater
 | link = none
 | format = template
 | template = weapon skill table row format
 | default = {{Weapon skill table row format|{{{1}}}|{{{1}}}|File:{{{1}}}.png}}
}}

The page selection has been parameterised, but is very similar to the previous example. It still has three sections, and the output is funneled into a template which applies some custom formatting. In this case the formatting is performed by the Template:Weapon skill table row template. Each of the purple properties is fed in order to the formatting template as an unnamed (but numbered) parameter.

See also[edit]