SPARQL

Run SPARQL queries and template their results via Lua

On this page

External links

SPARQL for MediaWiki

Executing SPARQL queries and templating their results via Lua.

Professional Wiki created SPARQL. We are MediaWiki developers that provide professional MediaWiki services.

We thank Freie Universität Berlin for funding initial development.

Usage documentation

Define a Lua module that requires the SPARQL binding and uses its runQuery method.

Example:

Create page Module:MySPARQL

local sparql = require('SPARQL') -- Load the SPARQL binding

local p = {}

function p.showFirstValue(frame)
  local sparqlQuery = frame.args[1]
  local queryResults = sparql.runQuery(sparqlQuery) -- Use the runQuery method

  local firstColName = queryResults['head']['vars'][0]
  return queryResults['results']['bindings'][0][firstColName]['value']
end

return p

Which can then be invoked via Scribunto's normal mechanisms from within wikitext.

Example:

{{#invoke:MySPARQL|showFirstValue|your SPARQL query here}}

Lua module Examples:

Installation

Requirements

  • PHP 8.1 or later
  • MediaWiki 1.39 or later
  • Scribunto

Load and enable

Load the extension using Composer:

COMPOSER=composer.local.json composer require --no-update professional-wiki/sparql:~1.0

Enable the extension by adding the following to your LocalSettings.php:

wfLoadExtension( 'SPARQL' );

You can verify the installation by checking your wiki's Special:Version page.

More MediaWiki Extensions

View all our extensions

Professional MediaWiki Services

MediaWiki services by the authors of SPARQL

Software Development icon
Software Development

Get superior results from the best MediaWiki developers with a proven track record of creating MediaWiki extensions & integrations.

Theme Development icon
Theme Development

Make your wiki look great! Use a time-tested responsive MediaWiki theme, or have us create a custom MediaWiki skin for you.

MediaWiki Hosting icon
MediaWiki Hosting

Let us take care of your wiki. We are MediaWiki hosting experts and provide cloud hosting, dedicated hosting, and on-premise hosting.

MediaWiki Consulting icon
MediaWiki Consulting

Bring your wiki to the next level by leveraging our MediaWiki expertise. From strategic planning to wikitext, we have you covered.

MediaWiki Migration icon
MediaWiki Migration

Migrate your wiki with confidence. We move your MediaWiki to a new home, or we help you migrate from another system to MediaWiki.

MediaWiki Upgrades icon
MediaWiki Upgrades

Keep your MediaWiki up-to-date and secure. We offer MediaWiki maintenance services to keep your wiki running smoothly.