Help:Semantic MediaWiki

Semantic MediaWiki, or SMW, is, without fear of hyperbole, one of the coolest things ever to be added to the basic MediaWiki software.

It transforms the wiki into a truly relational database, with which you can actually use the data that the wiki has been collecting. SMW lets you actually ask questions of the wiki.

With it, you can get answers to questions like:
 * "Which Tenth Doctor story was dedicated to Verity Lambert?"
 * "Which BBC Wales story thanked Marc Platt?"
 * "Which BBC Wales Dalek stories were not produced by Phil Collinson?"
 * "Which issue of DWM reviewed The Eleventh Hour but previewed The Hungry Earth?"
 * "Which issues of DWA gave away a Silurian mask?"
 * "Which comic stories feature the Second Doctor, Jamie McCrimmon and Cybermen?
 * "Of the cast members who worked in the James Bond and Star Wars franchises, which did not also work in the Hitchhiker's Guide franchise?"

The questions you can ask are mostly limited by your imagination, and the infrastructure you're willing to add to the wiki.

Moreover all of SMW's output is dynamic. Thus, if you asked the system to tell you which stories were directed by Euros Lyn, it would automatically update Euros Lyn's page if he ever directed more episodes.

In short, SMW gives us the power to convert this wiki into a real database, but also to easily "futureproof" the accuracy of our articles.

A basic example
Let's imagine that you wanted to know the names of the stories on which Stephan Pehrsson was the director of photography. In the past, your only real hope was going to Stephan's page and hoping that another editor had maintained the list of Stephan's contributions. Now, however you can type this simple command: To break this down, you're ing the database, within the category, Doctor Who (2005) television stories, in which did the property called "DOP" have a value of "Stephan Pehrsson"?

The answer?

Now, that'll get you your answer, but it's not very pretty. So let's quickly throw it into a more tabular form. The code  creates a new column into which the property DOP is placed.

And that's a lot more readable. Not pretty, of course, but readable. We can then dress it up in all sorts of ways. But that involves knowing something about coding tables, which is a little off-topic for us now.

One thing that's easy to spot is that we've created a redlink. We haven't created the property DOP yet, so therefore we get a redlink. For the moment, we can sort of "paper over the crack" by simply unlinking the title. Let's also add in a header for the first column.

Making the  plain and adding a   of "Episode name" results in this:

Truth is, though, you probably wouldn't want a table for something like this, because you really only have one variable — the name of the episode. If you wanted to put this dynamic list on the page Stephan Pehrsson, a simple list would do. If we simply define, we'll get a bulleted list.

If we simply define, we'll get a bulleted list. Cool, huh? But there's still one unsatisfactory element. Our dab terms are showing. So how do we get rid of them so that we're just looking at pure titles? Easy. We force the output to run through, our dab term stripper. Note here that we also have to set  simply because  outputs a linked version of a raw name. So if you give it  it will give you. Stripping the links before you pass the data to is necessary, or you'd end up with.

The final result then is precisely what we want: a list that looks like any other list on any other page about a crew member. It's simple, bulleted, respects both and.

Best of all, if he comes back and does a new episode, we won't have to update the page. It'll be done for us. Automatically. Simple, perpetual accuracy.

How it works
Before we go on to more advanced (read: fun) queries, let's stop for a moment to consider how this all works. What voodoo magic allows us to ask the wiki anything and expect an answer?

Basically, in order to get useful data back from the page, you have to change the way you link things. Imagine we add the following to a page: DOP::Stephan Persson This will mark that page as having the property of DOP equalling Stephan Pehrsson. So any time I look for that property value, that page will pop up.

Note, too, that there is no cosmetic difference between these two things: Stephan Pehrsson, the traditional link and DOP::Stephan Persson, the SMW link Both of these look the same way to anyone reading the page, even down to the mouseover. Stephan Pehrsson (normal) DOP::Stephan Pehrsson (SMW). See?

This doesn't mean that we have to go around to every page and start changing these links. To be fair, there are some times when manual editing might be required. But most of this can be handled easily by modifying a single template.

In this case, — which appears on every BBC Wales-made programme — is hugely helpful. We can simply change the to output something like this: producer::{{{producer}}, director::, DOP:: This globally converts all those links in the crew sections of BBC Wales pages from a sea of hundreds of tiny links into something you can really use.