Skip to content

Semantic MediaWiki — Structured Data, Properties, and Inline Queries

DodaTech Updated 2026-06-26 10 min read

In this tutorial, you will learn about Semantic MediaWiki. We cover key concepts, practical examples, and best practices to help you master this topic.

Semantic MediaWiki (SMW) extends MediaWiki with structured data capabilities — you define properties with types, annotate pages with facts, run inline queries to build dynamic listings, and create data-driven pages much like the structured knowledge systems used by Wikipedia for infobox automation.

What You'll Learn

  • Installing and configuring Semantic MediaWiki
  • Defining properties with data types
  • Annotating pages with semantic data
  • Running inline queries to display data
  • Using result formats (tables, lists, maps)
  • Building dynamic content pages

Why It Matters

Standard wiki pages store information as plain text. Search finds pages by title and full-text content. But it cannot answer questions like "Which products were released after 2025?" or "Show me all pages tagged with version 2.0 sorted by release date." Semantic MediaWiki adds a structured data layer on top of your wiki content. You add facts to pages, and SMW lets you query, aggregate, and display those facts dynamically.

Real-World Use

A DodaTech product wiki tracks all software releases with SMW. Each product page has semantic properties: "Released on," "Version," "License," and "Platform." A single inline query on the "Products" page lists all products by release date with version numbers. Another query on the "Downloads" page shows only Windows-compatible products. When a new product is released, it automatically appears in all relevant listings.

Learning Path

flowchart LR
  A["24: User Preferences"] --> B["25: Extension Installation"]
  B --> C["26: Semantic MediaWiki"]
  C:::current
  D["27: VisualEditor"]
  E["28: Scribunto & Lua"]
  F["29: Cite & References"]

  C --> D --> E --> F

  classDef current fill#38bdf8,color#0f172a,stroke-width:2px

Step 1: Install Semantic MediaWiki

SMW requires the Page Schemas extension and the Validator extension.

cd /opt/lampp/htdocs/mediawiki/extensions

# Download SMW
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/SemanticMediaWiki.git
cd SemanticMediaWiki
git checkout REL1_42
composer install --no-dev

Enable in LocalSettings.php:

wfLoadExtension( 'SemanticMediaWiki' );

// Enable SMW features
$smwgEnabledEditPageHelp = false;

After enabling, run the maintenance script to initialize the database:

php maintenance/update.php

Check Special:Version to confirm SMW is installed.

Step 2: Understand Properties and Types

A property is a piece of structured data — like a field in a database. Each property has a type that defines what kind of data it stores.

Built-in Property Types

Type Description Example
Page Link to another wiki page Has developer
Text Plain text Has description
Number Numeric value Has version number
Date Date value Has release date
Boolean True/false Is open source
URL External URL Has website
Email Email address Has contact email
Geographic coordinate Lat/long Has headquarters location

Creating a Property

Properties are created as pages in the Property: namespace. Create Property:Has release date:

[[Has type::Date]]

Create Property:Has version number:

[[Has type::Number]]

Create Property:Has developer:

[[Has type::Page]]

The [[Has type::...]] annotation on the property page defines its data type. This is a semantic annotation itself — meta-properties that describe properties.

Step 3: Annotate Pages with Semantic Data

Add semantic annotations to a product page using the [[Property::Value]] syntax:

= DodaSync =

'''DodaSync''' is a synchronization tool.

[[Has release date::2026-06-01]]
[[Has version number::2.1]]
[[Has developer::DodaTech]]
[[Has license::MIT]]
[[Is open source::true]]

These annotations are invisible in the rendered page (unless you use the factbox), but they add structured data to the page. SMW stores them in its database tables.

Inline Annotations

Display annotated values on the page with {{#show:}}:

Release date: {{#show:DodaSync|?Has release date}}

This renders as "Release date: June 1, 2026" using SMW's date formatter.

Editing Annotations

Users with Semantic MediaWiki can edit annotations via:

  • Source editing: Direct [[Property::Value]] syntax
  • Semantic forms: The PageForms extension provides form-based editing
  • VisualEditor: With the SMW VisualEditor integration

Step 4: Run Inline Queries

Inline queries are the heart of SMW. They search the semantic database and display results.

Basic Query

{{#ask: [[Category:Products]]
  | ?Has release date
  | ?Has version number
}}

This query:

  • Finds all pages in the "Products" category
  • Shows their "Has release date" property values
  • Shows their "Has version number" property values

Query with Conditions

{{#ask: [[Category:Products]] [[Has release date::>2025-01-01]]
  | ?Has release date
  | ?Has version number
  | sort=Has release date
  | order=desc
}}

Conditions use comparison operators: >, <, >=, <=, :: (equals).

Query with Multiple Conditions

{{#ask: [[Category:Products]]
  [[Has developer::DodaTech]]
  [[Is open source::true]]
  | ?Has release date
  | ?Has version number
}}

Multiple conditions combine with AND logic by default.

Step 5: Format Query Results

SMW offers many result formats.

Table Format (Default)

{{#ask: [[Category:Products]]
  | ?Has release date
  | ?Has version number
  | format=table
  | class=wikitable sortable
}}

List Format

{{#ask: [[Category:Products]]
  | format=list
  | headers=hide
  | link=all
}}

Template Format

Pass results to a template for custom rendering:

{{#ask: [[Category:Products]]
  | format=template
  | template=ProductRow
  | link=none
  | sort=Has release date
}}

Each result is passed to Template:ProductRow as numbered parameters (1, 2, 3, ...).

Other Formats

  • ul: Unordered bullet list
  • ol: Ordered list
  • category: Category-style listing with subheadings
  • embedded: Embed the full pages
  • map: Display on a map (requires Maps extension)
  • calendar: Display as a calendar (requires Calendar extension)
  • gallery: Display as an image gallery
  • datatables: Interactive table with sorting and search

Step 6: The Factbox

The factbox displays all semantic annotations for a page. It appears at the bottom of the page by default.

Configuring the Factbox

// Show factbox for all users
$smwgShowFactbox = SMW_FACTBOX_NONEMPTY;

// Show factbox on every page (even empty ones)
$smwgShowFactbox = SMW_FACTBOX_ALWAYS;

// Hide factbox
$smwgShowFactbox = SMW_FACTBOX_HIDDEN;

Users can toggle the factbox with __SHOWFACTBOX__ or __HIDEFACTBOX__ on individual pages.

Factbox Content

The factbox shows:

  • All property-value pairs on the page
  • Links to browse by each property
  • Links to the property page for documentation

Step 7: Property Pages

Each property page (Property:Has version number) shows:

  • Property type: Date, Number, Page, etc.
  • All pages using this property: Listed with their values
  • Property statistics: How many pages use it
  • Declarations: Sub-properties or property constraints

Property Constraints

Define value restrictions on property pages:

[[Has type::Number]]
[[Allows value::1.0]]
[[Allows value::2.0]]
[[Allows value::3.0]]

This restricts the property to only those three values. Values outside the allowed list are rejected.

Step 8: Concept Pages

A concept is a saved query that can be reused. Create a page in the Concept: namespace:

= Concept: RecentProducts =

{{#concept: [[Category:Products]] [[Has release date::>{{CURRENTYEAR}}-{{CURRENTMONTH}}-{{CURRENTDAY}} || > 2026-01-01]]
}}

Use the concept in queries:

{{#ask: [[Concept:RecentProducts]]
  | ?Has release date
  | ?Has version number
}}

Concepts are ideal for queries you use repeatedly. They are cached for better performance.

What You Learned

  • SMW adds structured data with property-value annotations
  • Properties have types: Page, Text, Number, Date, Boolean, URL
  • [[Property::Value]] annotates pages with facts
  • {{#ask:}} runs inline queries to display semantic data
  • Multiple result formats: table, list, template, map, calendar
  • The factbox displays annotations at the bottom of pages
  • Property constraints restrict allowed values
  • Concepts save reusable queries

In the next lesson, you'll learn about VisualEditor and WYSIWYG editing.

Common Mistakes

Mistake Why It Happens How to Fix
Property page not showing type [[Has type::Date]] syntax incorrect Check the property page syntax. It must be exactly [[Has type::TypeName]]. Valid types: Page, Text, Number, Date, Boolean, URL
Query returns no results Property name or value mismatch Verify the property name exists and is spelled correctly. Check that the value format matches the property type (Date requires YYYY-MM-DD).
Factbox not showing Factbox disabled in configuration Set $smwgShowFactbox = SMW_FACTBOX_ALWAYS in LocalSettings.php or add SHOWFACTBOX to the page.
"Property "Has X" is not used" warning Property created but not yet used This is normal for new properties. The warning disappears once at least one page uses the property.
Date queries return wrong results Date format not YYYY-MM-DD SMW requires ISO 8601 date format: YYYY-MM-DD. Dates in other formats (MM/DD/YYYY, DD Month YYYY) are not parsed correctly.
Query performance is slow on large wikis No Caching or concept usage Use concepts for frequently used queries. Enable SMW query caching with $smwgQueryResultCacheType. Consider a dedicated SMW store backend.

Practice Questions

  1. What is the difference between a regular category and a semantic property?
  2. How would you create a property that stores a geographic coordinate and display it on a map?
  3. Write an inline query that shows all pages released after 2025 sorted by release date in descending order.
  4. Challenge: Build a complete semantic product database. Install SMW if not already installed. Create properties: Has release date (Date), Has version (Text), Has developer (Page), Is stable (Boolean), Has platform (Page). Create 5 product pages with full semantic annotations. Create a "Product Listing" page that runs an inline query showing all products in a sortable table with release dates. Create a "Stable Releases" concept that only includes products with Is stable = true. Create a property constraint that limits Has platform to "Windows," "macOS," or "Linux." Add a factbox to all product pages and verify annotations display correctly.

FAQ

Is Semantic MediaWiki compatible with the latest MediaWiki version?

SMW is actively maintained. Check the SMW mediawiki.org page for the latest compatibility matrix. At the time of writing, SMW 4.2+ supports MediaWiki 1.39-1.42.

Can I use SMW data from outside the wiki?

Yes. SMW provides a Semantic Web export. Append ?output=json to an inline query URL to get JSON data. SMW also supports SPARQL endpoints for external querying.

Does SMW work with VisualEditor?

Partially. Basic property annotations can be added through VE, but complex queries and property creation require source editing. The PageForms extension provides a better VE-like experience for SMW.

Can SMW properties be used in templates?

Yes. This is a very powerful pattern. Define properties inside templates using tags. When a page uses the template, it automatically gets semantic annotations without the editor needing to know SMW syntax.

{{< faq "How does SMW handle property values that change over time?" "SMW stores the current value of each property. For historical data (e.g., "Version as of 2025"), you would need to store each version as a separate annotation or use time-dependent properties with the SMWApprovedReleases extension." >}}

Mini Project

Goal: Build a complete product database with dynamic listings using Semantic MediaWiki.

  1. Install SMW and run the database setup
  2. Create 5 semantic properties relevant to software products
  3. Create 6 product pages with full semantic annotations using all 5 properties
  4. Build a dynamic "Product Catalog" page with:
    • Sortable table of all products
    • Filtered list showing only stable products
    • "Upcoming Releases" section for products released in the future
    • A map or list grouped by developer
  5. Create 2 concepts for reuse
  6. Add factbox and verify data is captured correctly
  7. Create a template that automatically adds semantic properties to any product page when used
  8. Test that adding a new product automatically appears in all queries

What's Next

Structured data makes your wiki intelligent. Now let's improve the editing experience with a WYSIWYG interface.

Continue to Lesson 27: VisualEditor & WYSIWYG — learn how to install and configure VisualEditor for a word-processor-like editing experience.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro