SparqlResultFormat is a MediaWiki extension that allows you to query SPARQL endpoints and visualize the results in various formats including tables, charts, graphs, and treemaps.
-
Multiple output formats:
- Tables (sortable, with CSV export)
- Bar charts
- Pie charts
- Donut charts
- Bubble charts
- Treemaps (D3.js)
- Network graphs (Cytoscape.js)
- CSV download
-
Parser functions for embedding SPARQL visualizations in wiki pages
-
API module for programmatic SPARQL queries
-
Basic authentication support for protected endpoints
-
Customizable styling and configuration options
| Requirement | Version |
|---|---|
| MediaWiki | >= 1.43 |
| PHP | >= 8.1 |
-
Download and place the
SparqlResultFormatdirectory in your MediaWikiextensionsfolder. -
Add the following to your
LocalSettings.php:
wfLoadExtension( 'SparqlResultFormat' );
// Configure your SPARQL endpoints
$wgSparqlEndpointDefinition = [
'myEndpoint' => [
'url' => 'https://example.org/sparql',
// Optional: basic authentication
'basicAuth' => [
'user' => 'username',
'password' => 'password'
],
// Optional: timeouts
'connectionTimeout' => 10,
'requestTimeout' => 30,
'verifySSLCertificate' => true
]
];- Run
php maintenance/update.phpto update the database (if needed).
{{#sparql2table:
sparqlEndpoint=myEndpoint
|sparql=SELECT ?name ?value WHERE { ?s rdfs:label ?name ; :value ?value }
|tableClass=wikitable sortable
}}
{{#sparql2barchart:
sparqlEndpoint=myEndpoint
|sparql=SELECT ?category ?count WHERE { ... }
|divStyle=width:600px;height:400px;
}}
{{#sparql2graph:
sparqlEndpoint=myEndpoint
|sparql=SELECT ?source ?target WHERE { ?source :relatedTo ?target }
|layout=dagre
}}| Function | Description |
|---|---|
#sparql2table |
Render results as a sortable HTML table |
#sparql2barchart |
Render results as a bar chart |
#sparql2piechart |
Render results as a pie chart |
#sparql2donutchart |
Render results as a donut chart |
#sparql2bubblechart |
Render results as a bubble chart |
#sparql2treemap |
Render results as a D3.js treemap |
#sparql2graph |
Render results as a Cytoscape.js network graph |
#sparql2csv |
Provide a CSV download link |
Full documentation is available on the Special:SparqlResultFormat page after installation.
composer install
composer phpunitcomposer test- Gabriele Cornacchia
- Matteo Busanelli