Semantic MediaWiki Tutorial

Dive into the essentials of Semantic MediaWiki with our comprehensive tutorial. Learn how to enhance your data structuring and management capabilities, making your wiki more intelligent and interactive. Perfect for beginners and advanced users alike.

Image of Semantic MediaWiki for a blog

Semantic MediaWiki (SMW) is an extension to the MediaWiki - a popular open-source software platform used to create and manage collaborative websites like Wikipedia. SMW allows users to provide additional context and meaning to the content they create, using semantic annotations. In this tutorial we’ll try to explain the principles of how to work with Semantic MediaWiki in simple terms.

Semantic Properties

The philosophy of Semantic MediaWiki properties is to transcend mere text-based content by adopting a structured method for representing information. Through the clear definition of properties, the wiki evolves from a mere textual repository to a system where data can be systematically organized, searched, and linked, facilitating a smarter way of handling information.

Semantic MediaWiki properties are based on the principles and technologies of the Semantic Web. The Semantic Web is an extension of the World Wide Web that focuses on adding explicit meaning and structure to web content, enabling machines to understand and process the information.

The key technology behind Semantic MediaWiki properties is the Resource Description Framework (RDF). RDF provides a standardized model for representing and linking data on the web. It allows information to be expressed in a triple format, consisting of subject-predicate-object statements, also known as RDF triples. In the context of Semantic MediaWiki, properties represent the predicates in RDF triples.

For example, if you have a wiki about animals, you could define properties like "species", "habitat", "diet", or "is domestic".

Almost everything in MediaWiki has its page, and semantic properties are no exception. They must be created in the Property namespace that comes with the Semantic MediaWiki as pages:

  • Property:Species
  • Property:Habitat
  • Property:Diet
  • Property:Is domestic

Just plan your vocabulary for the specific knowledge domain or subject area. Alternatively, you can import any of the existing vocabularies online.

Semantic Annotations

Once you have defined properties, you can add semantic annotations to your wiki pages. Think of them as tags or labels that describe the properties and relationships of the information.

For example, you can annotate your newly created property pages by referencing data types or by creating lists of allowed values. You will use a simple predicate-object syntax:


Open your property pages for editing and put annotations that use the special semantic property "Has type":

[[Has type::Text]]

— for properties "Species", "Habitat", "Diet";

[[Has type::Boolean]]

— for the property "Is domestic".

Semantic Mediawiki supports many data types, you can find the full list in the documentation.

Now, let us limit the values that can be assigned to the property "Diet" using the special semantic property "Allows value". For the purpose we’ll add the following annotation to the page Property:Diet:

* [[Allows value::Herbivorous]]
* [[Allows value::Carnivorous]]
* [[Allows value::Omnivorous]]

You can read more about the Semantic MediaWiki built-in special properties here.

Once defined, the semantic properties can be used to annotate the subject pages:

  1. Page (subject) "Lion":
[[Is domestic::No]]
  1. Page (subject) "Dolphin":
[[Is domestic::No]]

Annotations can be made inline, in the way similar to usual wikilinks, like that:

Wiki markup:

[[Species::Dolphin|Dolphins]] live in [[Habitat::Oceans|oceans]].

Rendered text: Dolphins live in oceans.

If the semantic properties are shared across the pages about the same class of subjects, eg. pages in category "Animals" (like "Lion", "Dolphin", "Camel", "Mouse", etc.), it would be logical to create a template to store the semantic annotations.

For example, Template:Animal can have the following code:

    |Is domestic={{{Is domestic|}}}

The meaning of the pattern is "set the value for the semantic property "Diet" as indicated in the "Diet" parameter of the template "Animal", and so on.

Unlike the "bracketed" notation ([[Habitat::Oceans]]), the {{#set:}} function does not provide any printout, just stores the property value:

Wiki markup:

{{#set: Habitat=Oceans}}

Rendered text:

Then we can annotate subject pages as follows:

|Is domestic=Yes
|Is domestic=No

There is a special page where one can browse semantic data attached to a page. You can view the comparison below.

Example 1

Inline Semantic Annotation Example Inline Semantic Annotation Example

  • Upper window: Page view rendered.
  • Middle window: Page markup.
  • Bottom window: Special:Browse displaying page properties

Example 2

Semantic Template Example Semantic Template Example
  • Upper window: Page view rendered.
  • Middle window left: Page markup.
  • Middle window right: Template code
  • Bottom window: Special:Browse displaying page properties
Semantic Template Input You input data and the template takes care about the output.
Semantic Template Output Templates help to keep your pages uniform.

Once you have annotated your data, you can perform queries to retrieve specific information.

Semantic Queries

Semantic MediaWiki allows you to perform queries on the annotated data. You can use special syntax to search and get information based on specific properties and their values. This helps you find related stuff, make dynamic lists, and create reports based on the semantic data. For instance, you can query the wiki to find all "Carnivorous" animals or all animals inhabiting "Oceans".

Semantic MediaWiki supports queries embedded directly into wiki pages ("inline" queries). For example, you can create:

1. A table listing 10 random animals inhabiting savannah.
2. A bulleted list of wild animals sorted alphabetically.
[[Is domestic::No]]
3. A simple Dolphins’ diet name.
{{#show: Dolphin |?Diet}}

As you can see, the following elements are used in queries:

  1. Parser functions ({{#ask:}} and {{#show:}})
  2. Page selectors ([[Category:Animals]], [[Habitat::Savannah]], [[Is domestic::No]], Dolphin)
  3. Properties to display (|?Diet)
  4. Result formats (ul (unordered list), table)
  5. Other parameters (sort order, results limit)

There is a variety of available output formats and parameters. You can read about them in the documentation and train yourself using the special page (Special:Ask) that SMW provides for the guided input of query data and results display. It can even generate the query code for you, that can be copied and pasted on any page you want your data to appear on.

Special:Ask page query results Special:Ask page showing the results of the query.

Result formats

Apart from the 16 output formats provided by SemanticMediaWiki out of the box, there are over 60 formats available through extensions supporting the work with semantic data:

You can create your own outputs by passing retrieved semantic data to your custom template responsible for formatting of each data row in serialized manner:

|?Is domestic
|template=Animal record
Semantic MediaWiki Template Rendering Example Each matching animal record is rendered using the same template.

More examples of semantic result formats you can find at the bottom of this blog.

Semantic MediaWiki Subobjects

Semantic MediaWiki enables users to manage and portray intricate data through the creation of smaller, independent entities known as subobjects, simplifying the structure and representation of complex information.

A subobject is similar to a template or a data structure that can be embedded within a wiki page. Like a semantic template, the subobject consists of a set of properties and values, which define the attributes and data associated with that particular subobject rather than with the page that hosts the subobject.

It makes it possible to annotate many sub-objects on the same page using the syntax similar to the {{#set:}} function. For example, the page "Fauna of Africa" can have:

|Is domestic=No
|Is domestic=Yes

Now you can deliver a list of african species to any page using the query:

Semantic MediaWiki Query to Subobjects A query to subobjects. Plain list output example.
Tabular output of subobject query example A query to subojects. Tabular output example.


Semantic MediaWiki extends the capabilities of traditional wikis by adding a layer of semantic structure to the information. By organizing data in a structured manner and adding semantic annotations, you can search, query, and integrate information more effectively, enabling a richer and more interconnected knowledge base.

SemanticMediaWiki provides easy to use tools to create and manage your data using simple syntax. To work with SMW one needs common sense and knowledge of the subject, rather than programming skills.

Semantic Media Wiki is a mature software package with a big amount of configuration options. To tailor it to the needs of your wiki project to improve query speed and data consistency, you may need some guidance and help from SMW experts.

Semantic MediaWiki Examples

Leaflet Format

Semantic MediaWiki Map Query Example Leaflet Format Map of colleges in the USA.

Table format (with data tables)

SMW Query Table Format Datatables Example Addresses of colleges in the USA.

Tagcloud format

Semantic MeadiwWiki Query Tagcloud Example USA Counties by number of Colleges.

Outline format

Semantic MediaWiki Query Outline Format USA Colleges by state, county, location.

Event calendar format

Semantic MediaWiki Event Calendar Format Example where events are being specified using subobjects.

Timeline format

Semantic MediaWiki Timeline Format Example SMW events timeline (Source:

Timeseries format

Semantic MediaWiki Time Series Chart Example A time series chart with ~6000 temperature data points that haven been collected in New York and San Francisco (Source:

Jqplotchart format

semantic mediawiki Jqplotchart example The distribution of countries for the cities whose information is contained on SMW wiki (


In conclusion, we hope that this blog has provided you with valuable insights into how to utilize Semantic MediaWiki. As you delve further into your journey with MediaWiki, we encourage you to explore our other blogs that cover a range of topics related to Media Wiki.

We are here to assist you every step of the way. If you require any further assistance, have questions, or need professional MediaWiki help, please do not hesitate to contact us. Our team of experts is eager to provide you with the guidance and expertise you need to make the most out of your MediaWiki experience.

Latest Stories

Here’s what we've been up to recently.

Get our stories delivered

From us to your inbox weekly.