Jump to: navigation, search
This page is a translated version of the page Manual:$wgExtensionFunctions and the translation is 19% complete.

Other languages:
Deutsch • ‎English • ‎español • ‎日本語 • ‎Nederlands • ‎polski • ‎русский
Extensions: $wgExtensionFunctions
A list of callback functions which are called once MediaWiki is fully initialised.
導入されたバージョン: 1.3.0 (r3583)
除去されたバージョン: 使用中
既定値: array()
他の設定: アルファベット順 | 機能順


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.

This variable is an array that stores functions to be called after most of MediaWiki initialization is complete. Note however that at this point the RequestContext is not yet fully set up, so attempting to use it (or equivalent globals such as $wgUserManual:$wgUser or $wgTitleManual:$wgTitle) is liable to fail in odd ways. If you need to use the RequestContext, consider the BeforeInitializeManual:Hooks/BeforeInitialize and ApiBeforeMainManual:Hooks/ApiBeforeMain hooks instead.

Note also that certain config variables might have been processed already at this point and changing them might be unsafe. For extensions which use 拡張機能の登録Manual:Extension registration, the callback is a better option for changing the configuration. For other extensions, SetupAfterCacheManual:Hooks/SetupAfterCache is probably the best bet.

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.phpManual:Setup.php.

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

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