Extension:LinkedWiki

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
LinkedWiki

Release status: stable

LogoLinkedWiki.png
Implementation Parser extension, Special page, Data extraction
Description Print array or widget with a query Sparql on your Semantic MediaWiki, including a SPARQL Endpoint(optional)
Author(s) Karima Rafes (Karima Rafestalk)
Latest version 1.21
MediaWiki 1.20.* or greater
PHP 5.3+
Database changes No
License CC BY-NC-SA 3.0
Download
Other version : v1.0.1.2
README
Example http://en.sparql.pro/
Hooks used
ParserFirstCallInit

LanguageGetMagic

Translate the LinkedWiki extension if possible

Check usage and version matrix; code metrics

The LinkedWiki extension allows to print arrays or widgets with a SPARQL query on your Semantic MediaWiki, and optionally includes a SPARQL Endpoint.

Versions[edit | edit source]

Mediawiki Master[edit | edit source]

Mediawiki 1.22 & 1.23[edit | edit source]

Add :

  • Graph flow
  • Special page with Flint Editor

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

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 : 1.0.1.2)[edit | edit source]

See the page : LinkedWiki Version_1.0.1.2

What can this extension do?[edit | edit source]

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 | edit source]

You can download the extension directly from the MediaWiki source code repository (browse code). You can get:

One of the extensions tags

Not all extensions have tags. Some extensions have tags for each release, in which case those tags have the same stability as the release. To download a tag

  • Go to the tags list
  • Click the name of the tag you want to download
  • Click "snapshot"
The latest version of one of the extensions branches

Each extension has a master branch containing the latest code (might be unstable). Extensions can have further branches as well.

  • Go to the branches list
  • Click the branch name
  • Click "snapshot"
A snapshot made during the release of a MediaWiki version.

This might be unstable and is not guaranteed to work with the associated MediaWiki version.

After you've got the code, save it into the extensions/LinkedWiki directory of your wiki.

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

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

Installation[edit | edit source]

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

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

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
or
yum install php5-curl

Usage[edit | edit source]

Graph visualization[edit | edit source]

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 | edit source]

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]]=[[Baccalaureat|Bac]]=>[[Université]]
[[Collège]]=[[Brevet des collèges|Brevet]]=>[[Lycèe Pro]]=[[Baccalaureat professionnel|Bac PRO]]=>[[IUT]]
[[Lycèe Pro]]=[[Baccalaureat professionnel|Bac PRO]]=>[[Université]]
</lwgraph>

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

Special pages[edit | edit source]

Special page: SPARQL editor for Wiki[edit | edit source]

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

Linkedwiki SparqlEditor.png

Special page: SPARQL Flint Editor[edit | edit source]

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

Linkedwiki FlintEditor.png

Parser functions : SPARQL[edit | edit source]

Basic Use: #sparql[edit | edit source]

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).
{{#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 of the default endpoint with the graph of this wiki (define with the variable $wgLinkedWikiGraphWiki).
{{#sparql:select * where { graph <WIKIGRAPH> { ?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 }}
{{#sparql:PREFIX a:<http://yourURIResolver/>  select * where { a:{{PAGENAMEE}} ?y ?z . } | endpoint = http://dbpedia.org/sparql }}
{{#sparql:select * where { <http://yourURIResolver/{{PAGENAMEE}}> ?y ?z . }  | endpoint = http://dbpedia.org/sparql }}
  • Querying with any language.
{{#sparql:PREFIX a:<http://fr.mywiki/Spécial:URIResolver/> select * where { a:Tête_à_claque ?y ?z . }  | endpoint = http://dbpedia.org/sparql }}
{{#sparql:PREFIX a:<http://zh.mywiki/wiki/Spécial:URIResolver/>  select * where { a:秦朝 ?y ?z . }  | endpoint = http://dbpedia.org/sparql }}

Advanced Use: #sparql[edit | edit source]

Parameter: headers[edit | edit source]
  • Change the headers.
{{#sparql:select * where { ?x ?y ?z . } LIMIT 5  | endpoint = http://dbpedia.org/sparql |headers=name1,name2,name3}}
Parameter: classHeaders[edit | edit source]
  • 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",, }}

Example:

Linkedwiki example2.png

Parameter: templates[edit | edit source]

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 | edit source]
  • 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 | edit source]
  • 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 | edit source]
  • 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 | edit source]
  • 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[edit | edit source]

Usage[edit | edit source]

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
|query=
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} 
LIMIT 5 
|endpoint = http://dbpedia.org/sparql 
|defaultcolor=blue
|center=France
|zoom=5
|size=512x512
|maptype=roadmap}}
  • Result of wsparql before the parsing of mediawiki:
{{#widget:Google_Static_Maps
|defaultcolor=blue 
| 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 | edit source]
  1. Install the extension Widgets
  2. Create the page Widget:NAME_OF_YOUR_WIDGET
  3. Insert your code, example with google static maps :
<noinclude>__NOTOC__
This widget allows you to embed 
'''[http://code.google.com/apis/maps/documentation/staticmaps/ Google Static Maps]''' 
on your wiki page.

==== Sample result ====

{{#widget:{{PAGENAME}}
|defaultcolor=blue
|center=France
|zoom=5
|size=512x512
|maptype=roadmap
|sensor=false
|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}}

</noinclude>
<includeonly>
<img 
src="http://maps.google.com/maps/api/staticmap?
center=<!--{$center|default:'France'|escape:'html'}-->
&zoom=<!--{$zoom|default:'5'|escape:'html'}-->
&size=<!--{$size|default:'512x512'|escape:'html'}-->
&maptype=<!--{$maptype|default:'roadmap'|escape:'html'}-->
&sensor=<!--{$sensor|default:'false'|escape:'html'}-->
<!--{if is_array($rows)}-->
         <!--{foreach from=$rows key=myId item=i}-->
              &markers=label:<!--{$myId|escape:'html'}-->
              |color:<!--{$i.color|default:$defaultcolor|escape:'html'}-->
              |<!--{$i.point|escape:'html'}-->
         <!--{/foreach}-->
<!--{/if}-->"/>
</includeonly>

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'}-->
<!--{/foreach}-->

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


Mailing list / Google Group[edit | edit source]

See also[edit | edit source]