RDFaInMediaWiki

From Wiki of the E-Business and Web Science Research Group
Jump to: navigation, search
gr_banner_small.png
GoodRelations is a standardized vocabulary for product, price, and company data that can be embedded into existing static and dynamic Web pages.

Project Main Page
Vocabulary
Documentation
Developer's Wiki
GoodRelations Cookbook

Embedding RDFa in MediaWiki


Authors: Andreas Wechselberger and Martin Hepp

It is pretty simple to add rich meta-data in RDFa, e.g. GoodRelations patterns for price and product information or opening hours, to any page in a standard MediaWiki wiki.

Here is what you need to do:

Step 1: Apply Patch to MediaWiki

Apply the patch provided by Toby A Inkster. In detail, you have to modify some MediaWiki source files (Linker.php and Sanitizer.php) in order to enable RDFa support for the MediaWiki software.

Step 2: Change DOCTYPE in Skin

Next you have to change the DOCTYPE of your MediaWiki skin.

Example: Let's assume you want to change the DOCTYPE in the standard MediaWiki skin MonoBook. For that, you have to open the file MonoBook.php ( you will find it under /skins/ ) and go to line 74. There, you have to remove the old DOCTYPE and replace it with the following line:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">

Now all your MediaWiki pages will have this DOCTYPE.

Furthermore we have to replace in the MonoBook.php the line 116

<a name="top" id="top"></a>

with

<a id="top"></a>

and in MonoBook.php line 78 remove the "lang"-tag:
lang="<?php $this->text('lang') ?>"

Step 3: Make sure that you can insert HTML code in your MediaWiki

Furthermore you must have sufficient rights on that MediaWiki so that you can paste HTML code into your MediaWiki pages.

If not, you can enable this by installing the MediaWiki extension Secured HTML.

After installing the extension you are able to paste HTML/XHTML code into MediaWiki pages. This can be done like this:

{{#shtml: INPUT HTML MARKUP HERE }}

Step 4: Insert XHTML+RDFa markup in a MediaWiki page

Now you can paste XHTML+RDFa markup in a MediaWiki page by going to the wikitext mode and enclosing the markup in the very same manner:

{{#shtml: INPUT XHTML+RDFa MARKUP HERE }}


Important: When parsing the wikitext for the first time, MediaWiki sometimes inserts unneccessary spaces and line breaks, which create multiple unintended grey boxed to appear in the rendering and which may corrupt the RDFa meta-data.

If that happens, simply

  • edit the page again,
  • go to the

wikitext mode, and

  • delete all whitespaces and linebreaks in the markup.


Example

For example, you can paste the GoodRelations patterns from http://www.ebusiness-unibw.org/wiki/Rdfa4google into the body of your MediaWiki page.

The result is shown on the page http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct

Inserting RDFa

Simply insert the following code in the wikitext mode at the end of the original page:

{{#shtml:

}}

Extracting RDFa

You can use PyRDFa to extract the RDF rich meta-data from that page.

This brings up the following RDF code:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix gr: <http://purl.org/goodrelations/v1#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix xhv: <http://www.w3.org/1999/xhtml/vocab#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#business> a gr:BusinessEntity ;
     rdfs:label "Hepp Space Ventures Inc."@en ;
     gr:hasPOS <http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#myshop> ;
     gr:legalName "Hepp Space Ventures Inc."@en ;
     gr:offers <http://www.heppnetz.de/rdfa4google/product.html#myoffer> ;
     foaf:page <http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct>, <http://www.heppnetz.de/> ;
     vcard:adr <http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#address> ;
     vcard:fn "Hepp Space Ventures Inc."@en ;
     vcard:geo
         [ vcard:latitude "48.0802626"^^xsd:float ;
             vcard:longitude "11.6407428"^^xsd:float
         ] ;
     vcard:tel "+49-89-6004-0"^^xsd:string ;
     vcard:url <http://www.heppnetz.de/> ;
     foaf:depiction <http://www.heppnetz.de/rdfa4google/logo.png> .

<http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct> xhv:alternate <http://www.ebusiness-unibw.org/w/index.php?title=Special:RecentChanges&feed=atom>, <http://www.ebusiness-unibw.org/w/index.php?title=Special:RecentChanges&feed=rss> ;
     xhv:icon <http://www.ebusiness-unibw.org/favicon.ico> ;
     xhv:stylesheet
         <http://www.ebusiness-unibw.org/w/extensions/CategorySuggest/CategorySuggest.css>,
         <http://www.ebusiness-unibw.org/w/index.php?title=-&action=raw&maxage=18000&gen=css>,
         <http://www.ebusiness-unibw.org/w/index.php?title=MediaWiki:Common.css&usemsgcache=yes&ctype=text%2Fcss&smaxage=18000&action=raw&maxage=18000>,
         <http://www.ebusiness-unibw.org/w/index.php?title=MediaWiki:Monobook.css&usemsgcache=yes&ctype=text%2Fcss&smaxage=18000&action=raw&maxage=18000>,
         <http://www.ebusiness-unibw.org/w/index.php?title=MediaWiki:Print.css&usemsgcache=yes&ctype=text%2Fcss&smaxage=18000&action=raw&maxage=18000>,
         <http://www.ebusiness-unibw.org/w/skins/common/commonPrint.css?207>,
         <http://www.ebusiness-unibw.org/w/skins/common/shared.css?207>,
         <http://www.ebusiness-unibw.org/w/skins/monobook/main.css?207> .

<http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#myshop> a gr:LocationOfSalesOrServiceProvisioning ;
     gr:hasOpeningHoursSpecification <http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#saturdays>, <http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#workdays> ;
     rdfs:comment "Opening Hours: Mon-Fri 10-6, Sat 10-4.30"@en ;
     vcard:adr <http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#address> ;
     vcard:geo
         [ vcard:latitude "48.0802626"^^xsd:float ;
             vcard:longitude "11.6407428"^^xsd:float
         ] .

<http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#saturdays> a gr:OpeningHoursSpecification ;
     gr:closes "16:30:00"^^xsd:time ;
     gr:hasOpeningHoursDayOfWeek gr:Saturday ;
     gr:opens "10:00:00"^^xsd:time .

<http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#workdays> a gr:OpeningHoursSpecification ;
     gr:closes "18:00:00"^^xsd:time ;
     gr:hasOpeningHoursDayOfWeek
         gr:Friday,
         gr:Monday,
         gr:Thursday,
         gr:Tuesday,
         gr:Wednesday ;
     gr:opens "10:00:00"^^xsd:time .

<http://www.ebusiness-unibw.org/wiki/GoodRelationsRDFaInMediaWikiProduct#address> a vcard:Address ;
     vcard:country-name "Germany"@en ;
     vcard:locality "Neubiberg"@en ;
     vcard:postal-code "85577"^^xsd:string ;
     vcard:region "Bavaria"@en ;
     vcard:street-address "1234 Hepp Road"@en .

Resources