From MediaWiki.org
(Redirected from Extension:RDF)
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png

Release status:Extension status unknown

ImplementationTemplate:Extension#type Tag, Special page
DescriptionTemplate:Extension#description Flexible framework that goes beyond the ability of the code described at RDF metadata
Author(s)Template:Extension#username Evan Prodromou
MediaWikiTemplate:Extension#mediawiki 1.6, 1.17
LicenseTemplate:Extension#license No license specified
Download http://svn.wikimedia.org/svnroot/mediawiki/tags/REL1_17_2/extensions/Rdf/
ExampleTemplate:Extension#example WikiTravel:Wikitravel:RDF


Hooks usedTemplate:Extension#hook

Translate the Rdf extension if it is available at translatewiki.net

Check usage and version matrix.

This page is about an effort to provide an extensive RDF interface for MediaWiki. The idea is to create a flexible framework that goes beyond the ability of the code described at RDF metadata. There's an implementation by Evan Prodromou (see infobox), which is in production on Wikitravel (see WikiTravel:Wikitravel:RDF). The design arose from some discussions in 2005, mainly between Evan Prodromou and User:Duesentrieb.


  1. Download the files from SVN
  2. Place the downloaded files under extensions folder in your MediaWiki installation
  3. Add
    into your wiki's LocalSettings.php
  4. The extension should be active now.

NOTE: Below is a copy of the original conceptual draft, it may not accurately describe the actual implementation by Evan!


The idea is to provide a way to query different kinds of information about a wiki page in RDF format. This may include

  • basic metadata as defined by the Dublin Core standard and/or the Creative Commons project.
  • List of all authors
  • List of all links to and from a page
  • List of keywords (Categories for a page)
  • List of members of a category
  • ...and a plugin interface for more.

Also, the RDF could be delivered in different notations, like

  • N-Triple
  • Turtle
  • ..and maybe others.

This will probably implemented as an extension that provides a special page which, wehn called without parameters, would present a form where the user can specify what data is wanted in what format.

Another possible feature would be to allow users to add custom RDF information on any page, in Turtle format, in a <rdf>...</rdf> block


The implementation will probably be based on the RAP framework [1].


The core function will take a list of "models", i.e. datasets wanted, and return a RAP model which can then be serialized to create the actual output.

Here is the code for that function, as suggested by Evan:

 function getRdf($article, $modelNames=$wgDefaultModelNames) {
   global $wgModelFunctions;

   #empty model

   $fullModel = new RAP::Model();

   for ($modelNames as $modelName) {
        $modelFunction = $wgModelFunctions[$modelName];
        if ($modelFunction == null) {
             #print error
        $model = $modelFunction($article);

   return $fullModel;

$wgModelFunctions may be changed to contain a human readable description of the data set in addition to the function name. This would be displayed on the query form where the user can choose the data sets.

some example functions[edit]

Here's an example function for creating Dublin Core base data (code suggested by Evan):

 function DublinCoreModel($article) {
    global $DC_creator, $DC_date; # available from RAP system

    $model = new Model();

    $resource = getArticleResource($article); # Gets a RAP resource for the article; we'll have some utilities like this
    $user = getUserResource($article->getUser()); # another utility

    $model->add(new Statement($resource, $DC_creator, $user));
    $model->add(new Statement($resource, $DC_date, new Literal($article->getDate()));

    # etc.

    return $model;

Example function for listing all links from a page (also suggested by User:Evan):

 function LinkingModel($article) {
    global $DCMES, $DCTERM, $DCMI_types;
    $model = new Model();
    $resource = getArticleResource($article); # here's that utility again
    $linkFromTitles = $article->links(); # actually, I'm pretty sure this doesn't exist, but it should. B-)
    for ($linkFromTitles as $linkFromTitle) {
        $model->add(new Statement($resource, $DCTERM['References'], titleToResource($linkFromTitle));
    $linkToTitles = $article->whatLinksHere(); # another function that never was
    for ($linkToTitles as $linkToTitle) {
        $model->add(new Statement($resource, $DCTERM['isReferencedBy'], titleToResource($linkToTitle));
    # ... more for Image links, etc.
    return $model;

It may however be better to have a more generic function that allows to build such a list directly from an SQL query. This would make it very easy to add new datasets.

custom RDF[edit]

Function for building a model from custum RDF stuff on the wiki page:

 function InTextTurtleModel($article) {

    $text = $article->getText();

    $turtleBits = preg_match("<rdf>.*?</rdf>"); # Get stuff between <rdf> tags

    $turtle = string_join($turtleBits); # ...and join it into one big string

    $turtleParser = new N3Parser(); # RAP's "N3" parser is really a Turtle parser

    $model = $turtleParser->parse2model($turtle); # FIXME: handle errors here

    return $model; #  # That's it!

the code on the wiki page would use Turtle notation. The example below says that some of the text of the page was copied from another Wikipedia article, and that another part of the page was copied from some other random URL.

    <> dc:source <http://www.example.com/some/upstream/document.txt>, Wikipedia:AnotherArticle .

      a cc:Work;
      dc:creator "Anne Example-Person", "Anne Uther-Person";
      dc:contributor "Yadda Nudda Person";
      dc:dateCopyrighted "14 Mar 2005";
      cc:License cc:by-sa-1.0.


See also[edit]