For example, when an article contains a geographic coordinate, it is useful to provide links to online mapping services so that users can retrieve a map of that location with one click. Another example is to provide a link to an online currency converter for financial amounts. This page explains how you can add such features to a semantic wiki.
The information for additional links to online services in the factbox and on special page Browse is associated with the property used. For example, this wiki's Property:Has coordinates will show various links to online maps in the factbox and on special page Browse, if it is used on a wikipage, whereas other properties that also use datatype Geographic coordinate might not show this. This is crucial in many applications, since the datatype alone usually does not say much about the type of link. For example a property "IMDb number" of datatype Number might be used for a movie's id number at IMDb, but not every property of datatype Number should display a link to IMDb.
To make a property display service links, add the special property provides service on its page. For example, the page Property:Has coordinates might include the annotation
[[provides service::online maps]]
Here, "online maps" is the name of a set of service links provided by the wiki. The next section explains how you specify these service links.
After you specify that a property provides service links, its property values in the factbox, on special page Browse and on the property's own page will show an icon () that displays the service links when clicked. Note: As of Semantic MediaWiki 2.1 service links will no longer be shown within the factbox since the labelling of the link was user unfriendly (broken).
In a nutshell, a wiki administrator puts the text specifying the appearance of service links in a system message article in the "MediaWiki" namespace.
Normally only users that have sysop (administrator) privileges in the wiki can add or edit pages in the MediaWiki namespace, hence only they can modify service links. This is a reasonable restriction for most wikis: since service links may appear in thousands of factboxes, they need to be trusted. Adding or modifying services should usually be discussed among many users before an administrator puts the change into practice.
All users, however, are free to associate properties with available services as described above.
Name of the system message
The format for the system message is
MediaWiki:Smw service service name. The part "MediaWiki:Smw service" always remains unchanged while the service name changes with every system message providing a service link.
Content of the system message
If you look at MediaWiki:Smw service online maps, though the message might be hard to read due to the long lines, its format essentially is as follows:
label text1|http://someurl.com label text2|http://anotherurl.org ...
Every line contains one service link. The label is the text that users will see in the service link pop-up. After the pipe symbol '|' is the URL that the link will lead to. For better comprehension, please click on "View source" at the top of the page to see the raw text of the page.
Placeholders in the system message
In most cases, you want to provide information from the property value in the link. For example, a link to an online map service has to include the coordinates to display, and a link to a movie web site will have to include the ID of the movie. Since the exact data values are not known in advance, you use placeholders of the form $1, $2, $3, etc., in the URL. For example, the message text for a service link to IMDb could be:
When SMW displays the service links for a property value, it substitutes the property value's information for these placeholders. In this IMDB example, a movie ID of Type:Number will replace $1 with the numeric value, and voilà, the service link for a movie links to its information on IMDB, e.g. "0019254" to http://www.imdb.com/title/tt0019254/!
Information passed for each placeholder
The number and contents of the parameters that replace $1, $2, $3, … depend on the datatype of the property. For instance, a simple property of datatype number replaces $1 with its value, whereas a geographic coordinate provides parameters for latitude, longitude, direction, and much more. In most cases, $1 is the most relevant parameter that just provides a URL-safe string version of the property value. The datatypes listed below support service links. All other datatypes do not support service links.
- Help:Type Page
- $1: URL-encoded article name (no namespace), with underscores replaced by spaces
- Help:Type Number
- $1: numerical value in English punctuation
- $2: integer version of value, in English punctuation
- $3: From SMW version 1.1 onwards unit, if any.
- Help:Type Email
- $1: URL-encoded value of the URL including
- Help:Type Geographic coordinate
- Note: You need Semantic Maps 0.6.5 and SMW 1.5.1 or later for this.
- $1: The location in non-directional float notation.
- $2: The location in directional DMS notation.
- $3: The latitude in non-directional float notation.
- $4: The longitude in non-directional float notation.
Since geographic coordinates are complex, a sample content for the default message MediaWiki:Smw service online maps is provided on this wiki.
To illustrate the whole process of creating and using a new service, we provide an extended example, also implemented on SemanticWeb.org. Articles about Semantic Web vocabularies such as FOAF contain information about the vocabulary's "namespace" and the online service Swoogle allows users to search for background information on such namespaces. Our goal thus is to add a new "Swoogle service" to the Property:Namespace that is used on the vocabularies articles.As a first step, we edit the page Property:Namespace and add the line
As an additional service, this property provides a [[provides service::Swoogle lookup]] of the entered namespace.After saving, the factbox shows a link to the (still non-existing) service Swoogle lookup. Clicking this link, an administrator gets a new edit field, into which she enters
The link was retrieved by using Swoogle and replacing the search string (at the end of the link) with the parameter "$1".
After those changes are saved, the new service is fully functional, and each page that uses Property:Namespace will show a suitable link to Swoogle. Some articles will still show the old version, if they are retrieved from cache, but after the next edit or purge, all articles will display the links as expected.
Help:Service links en 1.0