Composer (PHP)

From Biowikifarm Metawiki
Jump to: navigation, search

Some extensions of MediWiki are managed by composer, a snmall PHP script. This tool is intended to manage dependencies and needed versions of software components, such as MediaWiki extensions. It needs a basic configuration file (composer.json in the wiki root folder) and installation or removal of extensions is done on the command line.

Documentation:



Step 0: First install of PHP composer tool itself to a local shared bin-directory:

cd ~ # go to personal home directory
sudo curl -sS https://getcomposer.org/installer | php
sudo chown root:mwadmin composer.phar
sudo mv composer.phar /usr/local/bin/


Step 1: Manage your required extensions in file composer.local.json in the root wiki folder and not in composer.json wich is the basic setup shipped by the Mediawiki installation. File composer.json can look like:

{
  "require": {
    "php": ">=5.3.2"
  },
  "suggest": {
    "ext-fileinfo": "More accurate file type detection for uploaded files",
    "ext-mbstring": "Faster unicode handling",
    "ext-wikidiff2": "Faster diff generation",
    "ext-apc": "Speed up MediaWiki with opcode caching (before PHP 5.5)"
  },
  "autoload": {
    "psr-0": {
      "ComposerHookHandler": "includes/composer"
    }
  },
  "scripts": {
    "pre-update-cmd": "ComposerHookHandler::onPreUpdate",
    "pre-install-cmd": "ComposerHookHandler::onPreInstall"
  },
  "config": {
    "optimize-autoloader": true
  }
}

Step 2: add extension


Add an extension

Read the documentation of the extension what kind of version you need and so forth, the extension’s documentation should describe it sufficiently.

It is recommended to manage additional extensions in a separate file, composer.local.json. It can look like:

{
  "require": {
    "mediawiki/semantic-media-wiki": "2.3.1",
    "mediawiki/semantic-forms": "3.5",
    "mediawiki/semantic-result-formats": "2.3",
    "mediawiki/semantic-maps": "3.3",
    "phpoffice/phpexcel": "1.8.1",
    "mediawiki/graph-viz": "1.6.0",
    "mediawiki/sub-page-list": "1.1.2",
    "mediawiki/translate": "2016.01",
    "mustangostang/spyc": "0.5.1",
    "mediawiki/cldr": "2016.01"
  }
}

Step 3: update extensions.

There is also a “require”-command that will update your composer.json as well as install the extension including potential dependencies. But it’s rather recommended to use the extra composer.local.json because the default composer.json shipped by wiki software can get overwritten. To add and install an extensions in this manner to composer.json run

cd /var/www/path/to-wiki-root/
sudo -u www-data php /usr/local/bin/composer.phar require 'mediawiki/semantic-maps' '3.1.3'

Update extensions

cd /var/www/path/to-wiki-root/
# update only a single extension and their dependencies
sudo -u www-data php /usr/local/bin/composer.phar update --no-dev mediawiki/graph-viz
# update all extensions and their dependencies
sudo -u www-data php /usr/local/bin/composer.phar update --no-dev

Remove an extension

See https://getcomposer.org/doc/03-cli.md#remove

cd /var/www/path/to-wiki-root/
sudo -u www-data php /usr/local/bin/composer.phar remove 'mediawiki/semantic-maps'

Self Update of composer

sudo php /usr/local/bin/composer.phar self-update