Composer

For a long time we had an issue resolving extensions dependencies. The composer/packagist system might be of some help. This article explain you how to prepare your MediaWiki extension to take advantage of the Composer dependency manager.

Composer is available at http://getcomposer.org/, it is a package manager for PHP. The biggest repository is http://packagist.org/ which let you upload your packages by simply pasting a git URL. All you need is to drop in a composer.json file at the root of your extension directory. My example will be with setting up a MediaWiki installation and install the Translate and TranslationNotification extensions.

Short way to add an extension
If the extension is in composer:

composer init -n composer require mediawiki/ :dev
 * 1) create an empty composer.json
 * 1) add extension using the default 'dev' version

Resulting composer.json: {    "require": { "mediawiki/translate": "dev" } }

install composer
On Mac OS X with homebrew, it is as easy as `brew install composer`. Other users can have a look at the Composer installation page.

composer.json
At first we create the composer.json files in the Translate extension:

Similarly for the TranslationNotification extension:

Publish extension in packagist
Then send that in the git repository of your choice. Antoine "hashar" Musso used his GitHub project to hold them:
 * https://github.com/hashar/mwext-Translate.git
 * https://github.com/hashar/mwext-TranslationNotifications.git

We then go to the http://packagist.org/ repository and submit the package. You will need to create an account then fill in the GIT repository URL. The packagist website will fetch the composer.json from your repository and happily add the package to the repository.

Preparing MediaWiki
Reuse your MediaWiki installation, in the root directory fill in a composer.json file:

The "require" statement will instruct composer that you want to install the TranslationNotifications extensions. It will take care of resolving the Translate dependency.

Validate your composer.json file:

$ composer validate ./composer.json is valid

resolve dependencies
In your MediaWiki directory, run the composer installer, instructing it to honor any unstable dependencies (aka development packages): $ composer install --verbose Loading composer repositories with package information Installing dependencies - Installing composer/installers (dev-master v1.0.1) Cloning v1.0.1 Cloning into '/srv/trunk/vendor/composer/installers'...

- Installing mediawiki/translate (dev-master 3fadb6b) Cloning 3fadb6bf19fe86226e4e6d35fddd5ebe597be035 Cloning into 'extensions/Translate'... /srv/trunk/extensions/Translate

- Installing mediawiki/translation-notifications (dev-master 440c597) Cloning 440c597a8b01ff2137850b1ef0d28b8ffa365fd9 Cloning into 'extensions/TranslationNotifications'... /srv/trunk/extensions/TranslationNotifications

Writing lock file Generating autoload files $

Extensions have been installed:

$ ls -l ./extensions/ Translate TranslationNotifications $

To have extensions installed in the proper directory, we have crafted https://github.com/composer/installers/pull/37 which makes Composer support MediaWiki extensions (and have them installed in extensions directory).

Our own repository
Create a json representing your repository:

Install satis and create a repo:

create-project composer/satis --stability=dev php bin/satis build  

Scanning packages Reading composer.json of mediawiki/translate (2012.11) Skipped tag 2012.11, no composer file Reading composer.json of mediawiki/translate (2012.12) Skipped tag 2012.12, no composer file Reading composer.json of mediawiki/translate Skipped tag, invalid tag name Reading composer.json of mediawiki/translate (REL1_19) Skipped branch REL1_19, no composer file Reading composer.json of mediawiki/translate (REL1_20) Skipped branch REL1_20, no composer file Reading composer.json of mediawiki/translate (composer) Skipped branch composer, no composer file Reading composer.json of mediawiki/translate (master) Importing branch master (dev-master) Reading composer.json of mediawiki/translate (translatesvg) Skipped branch translatesvg, no composer file Reading composer.json of mediawiki/translate (wmf/1.20wmf10) Skipped branch wmf/1.20wmf10, no composer file Reading composer.json of mediawiki/translate (wmf/1.20wmf8) Skipped branch wmf/1.20wmf8, no composer file Reading composer.json of mediawiki/translate (wmf/1.21wmf1) Skipped branch wmf/1.21wmf1, no composer file Reading composer.json of mediawiki/translate (wmf/1.21wmf7) Skipped branch wmf/1.21wmf7, no composer file Selected mediawiki/translate (dev-master) Reading composer.json of mediawiki/translation-notifications (REL1_20) Skipped branch REL1_20, no composer file Reading composer.json of mediawiki/translation-notifications (composer) Skipped branch composer, no composer file Reading composer.json of mediawiki/translation-notifications (master) Importing branch master (dev-master) Selected mediawiki/translation-notifications (dev-master) Writing packages.json Writing web view

Result is under 

$ ls  total 16 -rw-rw-r-- 1 root root 9836 Jan 29 14:50 index.html -rw-rw-r-- 1 root root 2094 Jan 29 14:50 packages.json $

The index.html is for human consumption. Composer itself will fetch the packagages.json file. Browsing the site gives out: