Introduction to Semantic MediaWiki

What is Semantic MediaWiki?

Semantic MediaWiki (SMW) is a powerful MediaWiki extension that lets you turn a regular wiki into a collaborative knowledge base. By adding simple #set and #ask markup, you can store structured data (properties and values) directly on wiki pages and query that data across the whole wiki.

Key Concepts

  • Properties: Named attributes (e.g., Has author, Published on) that describe a page.
  • Values: The data attached to a property – can be strings, numbers, dates, coordinates, etc.
  • Queries: Inline queries using #ask or the special page Special:Ask to retrieve pages that match certain criteria.
  • Concepts: Saved query definitions that can be reused like virtual categories.

Why Use SMW?

SMW turns a wiki into a lightweight database without needing a separate DBMS. It enables:

Installation Overview

# Using Composer (recommended)
composer require mediawiki/semantic-media-wiki

# In LocalSettings.php
wfLoadExtension( 'SemanticMediaWiki' );

# Run the update script
php maintenance/update.php --quick

SMW requires MediaWiki 1.43+ and PHP 8.1+. No database schema changes are needed beyond the tables created by the update script.

Essential Configuration

$smwgEnableInlineQueries = true;   // Allow #ask in page content
$smwgNamespacesWithSemanticLinks[NS_MAIN] = true; // Enable semantics on the main namespace
$smwgAutoRefreshOnPurge = true;   // Refresh query results when a page is purged

These settings are a good starting point; most wikis keep the defaults.

Typical Use‑Case Walkthrough

Visualise on a map (requires the Maps extension):

{{#ask: [[Category:Place]]
|?Has coordinates
|format=leaflet}}

Query the data with an inline ask:

{{#ask: [[Category:Book]]
|?Has author
|?Published on
|format=table}}

This renders a live table of all books with their authors and dates.

Create a property on a wiki page:

[[Has author::J. Doe]]
[[Published on::+2023-05-12]]
[[Has ISBN::978‑3‑16‑148410‑0]]

Getting Help

The official documentation lives on the SMW wiki (semantic-mediawiki.org). For community support, use the semwiki-user mailing list and the talk page on mediawiki.org.

This post is a draft – feel free to expand sections, add screenshots, or link to real‑world examples.

Subscribe to MediaWiki Tips and Tricks

Don’t miss out on the latest articles. Sign up now to get access to the library of members-only articles.
jamie@example.com
Subscribe