Руководство:$wgExtensionFunctions

This page is a translated version of the page Manual:$wgExtensionFunctions and the translation is 33% complete.
Расширения: $wgExtensionFunctions
Список callback-функций, которые вызываются один раз когда Mediawiki полностью инициализирована.
Введено в версии:1.3.0 (r3583)
Удалено в версии:всё ещё используется
Допустимые значения:не определено
Значение по умолчанию:[]

Подробнее

In general, using this functionality is a hack that suggests that something is going wrong somewhere, whether in MediaWiki core or in the extension. It should be avoided.

Эта переменная - массив функций, которые вызываются когда инициализация MediaWiki почти завершена. Note however that at this point the RequestContext is not yet fully set up, so attempting to use it (or equivalent globals such as $wgUser or $wgTitle ) is liable to fail in odd ways. If you need to use the RequestContext, consider the BeforeInitialize and ApiBeforeMain hooks instead.

Note also that certain config variables might have been processed already at this point and changing them might be unsafe. While there is currently no dedicated place for changing configuration, the MediaWikiServices hook is a better option than extension functions.

This variable should be used for final step of initialization of extension setup code that needs to perform advanced things, like using global functions and instantiating autoloaded classes. Typically each extension has one setup function associated with it. The array element concerned is typically defined in the extension file itself, with a statement of the form compatible with call_user_func() PHP function:

$wgExtensionFunctions[] = "functionName";
$wgExtensionFunctions[] = array( $classInstance, 'functionName' );
$wgExtensionFunctions[] = array( 'ClassName', 'staticFunctionName' );
$wgExtensionFunctions[] = 'ClassName::staticFunctionName';

Each setup function is then called from /includes/Setup.php .

For example, if your extension needs to access database during its initialization:

function initMyExtension() {
      $dbr = wfGetDB( DB_REPLICA );
      $myExtension = new MyExtension();
      $myExtension->loadSettingsFromDatabase( $dbr );
}

См. также