Composer/zh

Composer is a dependency manager for PHP libraries. In addition, it can be used to manage the installation of MediaWiki extensions (available since ). Starting with, MediaWiki core's external library dependencies are being managed with Composer.

安装Composer
There are multiple ways to install Composer:

To grab the latest snapshot:

That downloads a snapshot of the current master and will expire in 30 days. There are also phars for the alpha "releases" such as 1.0.0-alpha.

For users on OS X, you can use Homebrew to install composer:

If that doesn't work, or you do not have Homebrew installed, you can try:

Jenkins and the extension distributor use the copy of composer contained in the "integration/composer" git repo.

Once composer is installed, you can run commands via the downloaded phar:

You may want to move the phar into your path so it can be used as a normal executable:

If the mv command fails due to permissions, execute it again with sudo.

MediaWiki核心代码中的使用
MediaWiki 1.25+ depends on some external libraries which are managed with Composer. Composer creates an autoloader at, which is included by.

Composer managed dependencies are bundled into tarball distributions of MediaWiki and extensions so system administrators do not need to use composer directly. When installing MediaWiki using Git, dependencies declared in  can either be installed locally by running   or the   repository can be cloned to provide the same libraries used on the Wikimedia production cluster.

Using composer-merge-plugin
MediaWiki core "owns"  and will change the contents of that file in both tarball and Git managed updates. In order to allow local installs to use Composer to load optional libraries and/or manage extensions with Composer, a special plugin for Composer named composer-merge-plugin was developed. This plugin and the MediaWiki core  configuration allow a local deployment to add required extensions and libraries to a file   inside the root MediaWiki directory.

can also be used to install Composer managed libraries that are needed by extensions that are not installed using Composer themselves. This is only needed when the extensions are not installed from tarballs generated by Extension Distributor.

To enable Composer to discover and process the  files that may be included in any and all of your locally installed extensions, add something like this to  :

资源

 * - must be used for MediaWiki ≤ 1.21.x to install extensions with Composer
 * List of extensions that can or must be installed with Composer
 * List of extensions that can or must be installed with Composer