From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png

Release status:Extension status stable

ImplementationTemplate:Extension#type Parser extension, Special page, Data extraction
DescriptionTemplate:Extension#description Print array or widget with a query Sparql on your Semantic MediaWiki, including a SPARQL Endpoint(optional)
Author(s)Template:Extension#username Karima Rafes (Karima Rafestalk)
Latest versionTemplate:Extension#version 1.21
MediaWikiTemplate:Extension#mediawiki 1.20.* or greater
PHPTemplate:Extension#php 5.3+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license CC BY-NC-SA 3.0
Other version : v1.0.1.2
ExampleTemplate:Extension#example http://daap.eu/wiki/Demo_Wikidata
Hooks usedTemplate:Extension#hook

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

Check usage and version matrix.

The LinkedWiki extension allows to print the Linked Data of Wikidata or another source with a SPARQL query on your Mediawiki.


Mediawiki 1.25 & Master[edit]

Mediawiki 1.24 & 1.25[edit]

Mediawiki 1.22 & 1.23[edit]

Add :

  • Graph flow
  • Special page with Flint Editor

Mediawiki 1.20 & 1.21 (tag : 2.0.0 Alpha 1)[edit]

New version of LinkedWiki is available :

  • without ARC2 lib
  • without dependencies with the extension Semantic MediaWiki
  • You can use the extension without local endpoint
  • very simple installation

Mediawiki 1.16 (tag :[edit]

See the page : LinkedWiki Version_1.0.1.2

What can this extension do?[edit]

So for the moment in this version ALPHA you can :

  • read remote endpoint with SPARQL 1.1 or 1.0
  • help you to build and test a SPARQL query with a special page
  • print the result of your query in a page with a parser function. Example:

Linkedwiki example2.png

  • print the result of your query in a mediawiki widget. Thus, you can build by yourself new widgets for your linked data in your Linked Wiki. Example with the Google maps widget with Worldwide Earthquakes :

Worldwide Earthquakes with LinkedWiki.png

Download instructions[edit]

The extension can be retrieved directly from Git [?]:

  • Browse code
  • Some extensions have tags for stable releases.
  • Each branch is associated with a past MediaWiki release. There is also a "master" branch containing the latest alpha version (might require an alpha version of MediaWiki).

Extract the snapshot and place it in the extensions/LinkedWiki/ directory of your MediaWiki installation.

If you are familiar with git and have shell access to your server, you can also obtain the extension as follows:

cd extensions/
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/LinkedWiki.git


To install this extension, add the following to LocalSettings.php:

require_once( "{$IP}/extensions/LinkedWiki/LinkedWiki.php" );
$wgLinkedWikiConfigDefaultEndpoint="https://query.wikidata.org/bigdata/namespace/wdq/sparql"; //Default endpoint
// $wgLinkedWikiConfigDefaultEndpoint="http://dbpedia.org/sparql"; 
// If you have a proxy
// $wgLinkedWikiConfigProxyHost="";
// #$wgLinkedWikiConfigProxyPort=8888;

If, after the installation, you have errors about CURL in the log, probably you need to install the lib php5-curl in your server.

Example with ubuntu & fedora :
apt-get install php5-curl
yum install php5-curl


Graph visualization[edit]

With the tag name lwgraph, you can build quickly a graph.

Options :

  • type : select your graph
  • height : the height of graph in the page (px or percent).
  • width : the width of graph in the page (px or percent). By default : 100%
  • debug : with debug="true" (for developers)

Type : flow[edit]

Example of graph : LinkedWiki FlowShart.png

With this code :

<lwgraph type="flow"  height="200px" border="1">
[[Ecole Maternelle]]==>[[Ecole Primaire|Primaire]]==>[[Collège]]=[[Brevet des collèges|Brevet]]=>[[Lycée]]=[[Baccalauréat|Bac]]=>[[Université]]
[[Collège]]=[[Brevet des collèges|Brevet]]=>[[Lycée Pro]]=[[Baccalauréat professionnel|Bac PRO]]=>[[IUT]]
[[Lycée Pro]]=[[Baccalauréat professionnel|Bac PRO]]=>[[Université]]

You can click on the page's name in the graph. If the page doesn't exist, the link is red.

Special pages[edit]

Special page: SPARQL editor for Wiki[edit]

This editor can help you to write the wikitext with the magic word #sparql.

Linkedwiki SparqlEditor.png

Special page: SPARQL Flint Editor[edit]

This editor can help you to write quickly your first query on DBpedia.

Linkedwiki FlintEditor.png

Parser functions : SPARQL[edit]

Basic Use: #sparql[edit]

Print a simple Array with the following results:

  • Querying of the default endpoint and all the graphs of this endpoint.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  |endpoint=http://dbpedia.org/sparql}}
  • Querying without the parameter "endpoint" is possible but the variable $wgLinkedWikiConfigDefaultEndpoint has to be in the localsettings (see installation). By default the extension uses the endpoint of Wikidata.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5}}
  • Querying of the default endpoint with one graph.
{{#sparql:select * where { graph <http://mygraph/test> { ?x ?y ?z . } }  LIMIT 5 | endpoint = http://dbpedia.org/sparql  }}
  • Querying the properties of the current page (3 equivalent queries) :
{{#sparql:select * where { <PAGEIRI> ?y ?z . } | endpoint = http://dbpedia.org/sparql }}

Advanced Use: #sparql[edit]

Parameter: headers[edit]
  • Change the headers.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | endpoint = http://dbpedia.org/sparql |headers=name1,name2,name3}}
Parameter: classHeaders[edit]
  • You can hide or change the style of your headers. Here, the first column has no header and is unsortable.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | endpoint = http://dbpedia.org/sparql |headers= &nbsp;,name2,name3 |classHeaders= class="unsortable",, }}


Linkedwiki example2.png

Parameter: templates[edit]

With an example of template like Template:Test1:

<includeonly>{{{x}}}, {{{y}}} and {{{z}}} </includeonly>
  • You can use this template in the following way:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | endpoint = http://dbpedia.org/sparql |headers=Name1 |templates= Test1 }}
  • And you can use a different template for each column:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql  |headers=Name1,Name2 |templates= Test1,Test1 }}
Parameter: cache[edit]
  • Your data may be very volatile and you need accordingly to refresh the result of this query each time. To do so, you can disable the cache with the cache parameter, as follows:
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | endpoint = http://dbpedia.org/sparql |cache=no }}
Parameter: debug[edit]
  • Well, you can add several parameters at the same time but doing so, the wiki text can be very hard to debug. This parameter gives you the result of this parser before the last parsing of mediawiki :
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql  |debug=YES }}
Parameter: footer[edit]
  • you can remove the footer of array :
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5 | endpoint = http://dbpedia.org/sparql  |footer=NO }}
Parameter: templateBare[edit]
  • you can remove the footer and the header. With the value "tableCell", you can catch only the cells.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | endpoint = http://dbpedia.org/sparql |templateBare=tableCell }}

With the Widget extension: #wsparql (No tested in the last version)[edit]


You want to use your SPARQL results with Google Maps, Youtube, Flickr, etc. It's very hard if not impossible to develop all the possibilities in a mediawiki extension. So, the wsparql function can pre-format the parameters for a widget.

  • The parameters of the query, endpoint, cache and debug are the same as for #sparql, with a slightly different syntax:
{{#wsparql: WIDGET_NAME |query= SPARQL_QUERY  | endpoint= ENDPOINT  | cache = NO/YES (optional) | debug = NO/YES (optional) | PARAMETERS_OF_WIDGET }}
  • Example with the Google Static Maps widget:
{{#wsparql: Google_Static_Maps
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX cat:<http://fr.test2.daria/wiki/Spécial:URIResolver/Catégorie:> 
PREFIX prop:<http://fr.test2.daria/wiki/Spécial:URIResolver/Attribut:> 
select ?point 
where { ?x rdf:type cat:Ville; prop:Position ?point} 
|endpoint = http://dbpedia.org/sparql 
  • Result of wsparql before the parsing of mediawiki:
| center=France 
| zoom=5 
| size=512x512 
| maptype=roadmap
| rows.0.point=43.30, 5.38 
| rows.1.point=48.83, 2.3 
| rows.2.point=49.93, 2.3}}

And after parsing:

Linkedwiki example3.png

As you can see, the wsparql aggregates the sparql results in one list, with this pattern : rows.NUMBER_LINE.VARIABLE_NAME = VARIABLE_VALUE

  • Like that:
rows.0.point=43.30, 5.38 | rows.1.point=48.83, 2.3 | rows.2.point=49.93, 2.3

You have to find a widget compatible with this syntax or you can create/change a widget of mediawikiwidgets.

Build your widget[edit]
  1. Install the extension Widgets
  2. Create the page Widget:NAME_OF_YOUR_WIDGET
  3. Insert your code, example with google static maps :
This widget allows you to embed 
'''[http://code.google.com/apis/maps/documentation/staticmaps/ Google Static Maps]''' 
on your wiki page.

==== Sample result ====

|rows.0.color= red
|rows.0.point= 43.30,2.3
|rows.1.point= 48.83,2.3
|rows.2.point= 48.73,2.3}}

<!--{if is_array($rows)}-->
         <!--{foreach from=$rows key=myId item=i}-->

And to share your widget in mediawikiwidgets.org.

Now, let's summarize!

  • To read one list like rows.NUMBER_LINE.VARIABLE_NAME = VARIABLE_VALUE, you have to perform a foreach of rows and read keys and items, like that:
<!--{foreach from=$rows key=myId item=i}-->
        <!--{$myId|escape:'html'}--> <!--{$i.point|escape:'html'}-->

It's a bit hard the first time. Use the group google, if you face a problem.

Mailing list / Google Group[edit]

See also[edit]