手册:$wgExtensionFunctions

This page is a translated version of the page Manual:$wgExtensionFunctions and the translation is 58% complete.
Outdated translations are marked like this.
扩展: $wgExtensionFunctions
MediaWiki完全初始化后调用的回调函数列表。
引进版本:1.3.0 (r3583)
移除版本:仍在使用
允许的值:未指定
默认值:[]

详细信息

一般来说,使用此功能是一种非常规手段,表明MediaWiki核心或扩展中的某个地方可能有设计问题。应该避免这种情况。

该变量是存储在大多数MediaWiki初始化完成后要调用的函数的数组。 Extensions can register callbacks to be executed this way using the ExtensionFunctions of extension.json. At the time these callbacks are called, MediaWikiServices and the main RequestContext are fully initialized.

另请注意,某些配置变量此时可能已经被处理,更改它们可能不安全。 Extensions that need to dynamically set configuration should use a registration callback instead.

ExtensionFunction callbacks should be used only for initialization code that need to interact with service objects as a final step.

例如,如果您的扩展在初始化期间需要访问数据库:

function initMyExtension() {
      $dbr = MediaWikiServices::getInstance()
            ->getConnectionProvider->getReplicaDatabase();
      $myExtension = new MyExtension();
      $myExtension->loadSettingsFromDatabase( $dbr );
}

另见