Developing extensions


Our Github repositories generally follow the guideline explained on this page.

Specifying a dependency[edit]

It is a recommended guideline of this project that an extension specifies its dependency to ensure it is tested and usable for the Semantic MediaWiki release it was intended for by maintaining a composer.json. For example, see SemanticResultFormats extension.

"require": {
	"php": ">=5.3.2",
	"composer/installers": "^1.0.12",
	"mediawiki/semantic-media-wiki": "~2.3"


"autoload": {
	"files" : [
	"psr-4": {
		"SFOO\\": "src/"

Furthermore, using Help:Using Composer also ensures that classes are autoloaded (PSR-4) without the need to maintain a list of class names.

It is not always easy to minimize direct access to GLOBALS and when a reference is necessary, using $GLOBALS is the recommended convention.

Writing code[edit]

It has been good practice to structure the code base around the following:

 |- ...

Code quality should be considered when writing an extension in order for fellow developers to be able to understand, read, and review the code.

Some guidelines are:

Writing tests[edit]

It is suggested that an extension provides tests so that referenced API's (interfaces, classes etc.) used with either MediaWiki or Semantic MediaWiki can be tested and are verifiable (and in case those were modified can be caught before deployment).

Continuous integration[edit]

wp:Continuous integration can help increase the quality of a deployable extension. Most repositories are using Travis-CI which is fairly easy to setup and integrable with SMW.

To ease execution and usage, the following can be added to your composer.json which allows to run a test suite via composer phpunit.

"config": {
	"process-timeout": 0
"scripts": {
	"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"

To minimize the chance of a potential breakage, we

To finalize the setup, the following should be added:

  • A .travis.yml to describe the environment tests are expected be executed
  • Copy several scripts (examples here can be mostly copied with minor adaptation), to direct the download and setup of the environment

Having followed above steps, the output of composer phpunit (from an extension base directory) should be similar to:

composer phpunit
php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist

Semantic Result Formats: 2.3

Semantic MediaWiki: 2.4-alpha (SMWSQLStore3, mysql)
MediaWiki:          1.25.1 (MediaWiki vendor autoloader)

Execution time:     2016-01-26 06:01
Xdebug:             2.3.3 (enabled)

PHPUnit 3.7.38 by Sebastian Bergmann.
Configuration read from

Time: 194 ms, Memory: 21.00Mb

OK (46 tests, 46 assertions)

See also[edit]