Manual:Configuration for developers


 * For documentation about configuring MediaWiki, see Manual:Configuration.

This is a guide for core and extension developers about creating and accessing configuration settings.

For core
To access a configuration variable such as :

If you don't have access to any ContextSources, you can get a Config object with

This should not be used to fetch global variable objects such as or.

Configuration using (recommended)
Extensions that are should set up configuration variables as described in this section. The  should be unique to the extension; if it's not the full extension name (e.g. is an abbreviation) then you should make sure it doesn't collide with any existing extension.

When calling, MediaWiki will call your provided  and use it. This way the extension gets its own prefixed configuration.

Configuration using globals
If you can, use the  file for configuration (see above). If you can't, use this snippet (only works with  prefixed variables):

Custom prefixes
In the past, some extensions used "eg" instead of "wg". We want to move away from prefixes, but you can still continue to use them:

Testing
When debugging, you use the following to test that you are accessing the right Config instance. You should do this in place of the $wgConfigRegistry shown in the for extensions section above.

If you are accessing the wrong Config instance, a ConfigException will be produced.

For modifying configuration variables in PhpUnit tests in core, you can use

Upgrading from before MediaWiki 1.23
Starting with MediaWiki 1.23, there a new  interface was introduced to access configuration options. This allowed us to abstract the backend in which we stored configuration options.

Pre-1.23 code would look like:

1.23+ code should look like this:

You'll notice a few changes here:
 * We use  to get the default   object. Most contexts implement.
 * Rather than checking for "wgFoo", you ask the Config object for "Foo", without any wg prefix.