Manual:Configuration for developers/cs


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

Toto je průvodce pro vývojáře jádra a rozšíření o vytváření a přístupu k nastavení konfigurace.



Pro jádro
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 have an  file should set up configuration variables as described in this section.

If your extension is called, in   you'd write:

V PHP, kdykoli chcete své konfigurační hodnoty:

If the prefix for your configuration keys is not the default "wg", you can specify it with the  or   key, depending on the schema version (see docs). Měli byste se ujistit, že nekolidují s žádným existujícím rozšířením.

Důrazně se doporučuje začínat název konfiguračního klíče názvem vašeho rozšíření (jako v příkladu), abyste zajistili, že konfigurační klíč bude jedinečný mezi všemi klíči všech aplikací. Not doing this is a bad idea, and will probably break the use of attributes.



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



Vlastní předpony
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:

If you use extension registration, there is a  or   (depending on the schema version) field you can use instead.

Testování
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 will be produced.

For modifying configuration variables in PhpUnit tests in extensions using manifest version 1 (or in MediaWiki core), you can do the following in test cases that extend :

Programmatically modifying configuration values
The only Config implementation that supports is, which is mostly used in tests.

One way to modify values from the MainConfig service is via the hook, but this is discouraged. Instead, a hook should be used to allow more controlled and explicit modification of the relevant values.

Upgrading from before MediaWiki 1.23
In MediaWiki 1.23 a new  interface was introduced to access configuration options. This allowed us to abstract the backends in which we store 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.