PHPackages                             professional-wiki/sparql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. professional-wiki/sparql

ActiveMediawiki-extension[Utility &amp; Helpers](/categories/utility)

professional-wiki/sparql
========================

Allows running SPARQL queries via lua

1.0.0(2y ago)52811[1 PRs](https://github.com/ProfessionalWiki/SPARQL/pulls)GPL-2.0-or-laterPHPPHP &gt;=8.1CI passing

Since Nov 24Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/ProfessionalWiki/SPARQL)[ Packagist](https://packagist.org/packages/professional-wiki/sparql)[ Docs](https://github.com/ProfessionalWiki/SPARQL)[ RSS](/packages/professional-wiki-sparql/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (3)Used By (0)

SPARQL
======

[](#sparql)

[![GitHub Workflow Status](https://camo.githubusercontent.com/b72b3ff65a642147d5a3055f120ff9eb7cd091481fbdec2ec5f3a6886dec6ffb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50726f66657373696f6e616c57696b692f53504152514c2f63692e796d6c3f6272616e63683d6d6173746572)](https://github.com/ProfessionalWiki/SPARQL/actions?query=workflow%3ACI)[![Type Coverage](https://camo.githubusercontent.com/62e580d032582791c92e3e7674f0b62b75ad75f28b448e86eb8be3f7b0ecd0f1/68747470733a2f2f73686570686572642e6465762f6769746875622f50726f66657373696f6e616c57696b692f53504152514c2f636f7665726167652e737667)](https://shepherd.dev/github/ProfessionalWiki/SPARQL)[![Psalm level](https://camo.githubusercontent.com/acfb6a0116bee3d5df7eb58acb654cad3cb8ee1436e633281fbf6f7d9c749979/68747470733a2f2f73686570686572642e6465762f6769746875622f50726f66657373696f6e616c57696b692f53504152514c2f6c6576656c2e737667)](psalm.xml)[![Latest Stable Version](https://camo.githubusercontent.com/6e1d2023a106eb7fa71ea985798a43e9452785e2e3825578bd465a74ef9a0bb6/68747470733a2f2f706f7365722e707567782e6f72672f70726f66657373696f6e616c2d77696b692f73706172716c2f762f737461626c65)](https://packagist.org/packages/professional-wiki/sparql)[![Download count](https://camo.githubusercontent.com/57c6fe3ef43d902086e22fd9a6e2d3d593646c552ac2431517ecbe56d77eb3eb/68747470733a2f2f706f7365722e707567782e6f72672f70726f66657373696f6e616c2d77696b692f73706172716c2f646f776e6c6f616473)](https://packagist.org/packages/professional-wiki/sparql)[![License](https://camo.githubusercontent.com/ae82b890006f0f42b6fa08446221f8b9ed3eb78197642273605b66f6ad408a2d/68747470733a2f2f706f7365722e707567782e6f72672f70726f66657373696f6e616c2d77696b692f73706172716c2f6c6963656e7365)](LICENSE)

MediaWiki extension for executing SPARQL queries and templating their results via Lua.

[Professional.Wiki](https://professional.wiki) created and maintains SPARQL. We provide [Wikibase hosting](https://professional.wiki/en/hosting/wikibase), [Wikibase development](https://professional.wiki/en/wikibase-software-development), [MediaWiki development](https://professional.wiki/en/mediawiki-development), and [Wikibase consulting](https://wikibase.consulting/).

**Table of Contents**

- [Usage](#usage-documentation)
- [Installation](#installation)
- [PHP Configuration](#php-configuration)
- [Development](#development)
- [Release notes](#release-notes)

Usage Documentation
-------------------

[](#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](https://www.mediawiki.org/wiki/Extension:Scribunto)'s normal mechanisms from within wikitext. Example:

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

Lua module examples:

- [Show the first value (README example)](demoLua/firstValue.lua)
- [Show everything](demoLua/showEverything.lua)
- [Build an HTML table](demoLua/htmlTable.lua)

Installation
------------

[](#installation)

Platform requirements:

- [PHP](https://www.php.net) 8.1 or later (tested up to 8.5)
- [MediaWiki](https://www.mediawiki.org) 1.43 or later (tested up to 1.45)
- [Scribunto](https://www.mediawiki.org/wiki/Extension:Scribunto) and lua

We also recommend installing the [CodeEditor extension](https://www.mediawiki.org/wiki/Extension:CodeEditor)for a better editing experience of Lua modules.

### Installing The SPARQL Extension

[](#installing-the-sparql-extension)

The recommended way to install the SPARQL extension is using [Composer](https://getcomposer.org) with [MediaWiki's built-in support for Composer](https://professional.wiki/en/articles/installing-mediawiki-extensions-with-composer).

On the commandline, go to your wikis root directory. Then run these two commands:

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

```
composer update professional-wiki/sparql --no-dev -o
```

Then enable the extension by adding the following to the bottom of your wikis [LocalSettings.php](https://www.pro.wiki/help/mediawiki-localsettings-php-guide) file:

```
wfLoadExtension( 'SPARQL' );
```

You can verify the extension was enabled successfully by opening your wikis Special:Version page.

PHP Configuration
-----------------

[](#php-configuration)

Configuration can be changed via [LocalSettings.php](https://www.pro.wiki/help/mediawiki-localsettings-php-guide).

### SPARQL Endpoint URL

[](#sparql-endpoint-url)

Variable: `$wgSPARQLEndpoint`

Required for the extension to function. You can enable the extension without setting this variable without breaking your wiki, but the extension will not work.

Example:

```
$wgSPARQLEndpoint = 'https://query.portal.mardi4nfdi.de/proxy/wdqs/bigdata/namespace/wdq/sparql';
```

Development
-----------

[](#development)

Run `composer install` in `extensions/SPARQL/` to make the code quality tools available.

### Running Tests and CI Checks

[](#running-tests-and-ci-checks)

You can use the `Makefile` by running make commands in the `SPARQL` directory.

- `make ci`: Run everything
- `make test`: Run all tests
- `make phpunit --filter FooBar`: run only PHPUnit tests with FooBar in their name
- `make phpcs`: Run all style checks
- `make cs`: Run all style checks and static analysis

### Updating Baseline Files

[](#updating-baseline-files)

Sometimes Psalm and PHPStan generate errors or warnings we do not wish to fix. These can be ignored by adding them to the respective baseline file. You can update these files with `make stan-baseline` and `make psalm-baseline`.

Release Notes
-------------

[](#release-notes)

### Version 2.0.0 - Under development

[](#version-200---under-development)

- Raised the minimum MediaWiki version from 1.39 to 1.43

### Version 1.0.0 - 2023-11-24

[](#version-100---2023-11-24)

- Lua binding `SPARQL.runQuery` to execute SPARQL queries and return the results as a Lua table
- Compatibility with MediaWiki 1.39, 1.40 and 1.41
- Compatibility with PHP 8.1 and 8.2

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance59

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

952d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

![](https://www.gravatar.com/avatar/5d30e82252731745d5060a641de6e9431e1d5722ede97cb1cc94d2975aa54753?d=identicon)[malberts](/maintainers/malberts)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (19 commits)")[![malberts](https://avatars.githubusercontent.com/u/1428594?v=4)](https://github.com/malberts "malberts (6 commits)")[![waximabbax](https://avatars.githubusercontent.com/u/15813104?v=4)](https://github.com/waximabbax "waximabbax (4 commits)")[![physikerwelt](https://avatars.githubusercontent.com/u/2777736?v=4)](https://github.com/physikerwelt "physikerwelt (2 commits)")[![alistair3149](https://avatars.githubusercontent.com/u/9260542?v=4)](https://github.com/alistair3149 "alistair3149 (1 commits)")[![myousuffazal](https://avatars.githubusercontent.com/u/5208120?v=4)](https://github.com/myousuffazal "myousuffazal (1 commits)")

---

Tags

luamediawikimediawiki-extensionscribuntosparqlsparql-querywikibasewikibase-extensionmediawikisparqlwikibase

###  Code Quality

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/professional-wiki-sparql/health.svg)

```
[![Health](https://phpackages.com/badges/professional-wiki-sparql/health.svg)](https://phpackages.com/packages/professional-wiki-sparql)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.5k10](/packages/helsingborg-stad-municipio)[mediawiki/maps

Adds various mapping features to MediaWiki

84152.3k3](/packages/mediawiki-maps)[starcitizentools/citizen-skin

A beautiful, usable, responsive MediaWiki skin with in-depth extension support. Originally developed for the Star Citizen Wiki.

3376.6k](/packages/starcitizentools-citizen-skin)[mediawiki/chameleon-skin

A highly flexible MediaWiki skin using Bootstrap 5

12585.7k2](/packages/mediawiki-chameleon-skin)[civicrm/civicrm-drupal-8

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

19251.4k3](/packages/civicrm-civicrm-drupal-8)[altis/core

Core module for Altis

19228.0k3](/packages/altis-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
