Jump to content

手册:$wgConf

From mediawiki.org
This page is a translated version of the page Manual:$wgConf and the translation is 48% complete.
全局对象: $wgConf
创建组维基。在一般的安装中并不常用。
引进版本:1.5.0 (r9670)
移除版本:仍在使用
允许的值:未指定
默认值:新的SiteConfiguration对象。

详情

创建组维基。在一般的安装中并不常用。

而是通常使用维基媒体大量安装来为几百个维基提供集中的文件,给每个站组和每个维基提供配置的默认值。

但是,这些配置可能让人感到困惑。 :) 目前被Extension:中央认证 用作获取每个站点的信息,例如链接到每个维基上的正确用户页面。

配置

Wiki在其数据库名称上按后缀分组; 在大型装置上可能存在例如'enwiki'和'enwiktionary'和'enwikibooks',每个都在不同的后缀组中。如果要使用$wgConf->siteFromDB(),必须在$wgConf的suffixes成员变量中声明后缀。

$wgConf->settings is the array of settings. Its format is $wgConf->settings['wgSettingName']['wiki'].

Settings may be assigned to (from the more specific to the less specific, this is the 'wiki' part of $wgConf->settings as mentioned above):

  • a specific DB name.
  • a wiki tag (since 1.12.0)
  • a suffix (eg 'wiki' or 'wiktionary') to affect all in that suffix group (can be determined with $wgConf->siteFromDB())
  • 'default' to affect all wikis

For string settings, you can define parameters that will be replaced when extracting the settings. It can be useful when the setting has the same format for all wikis. The format is $name. Be careful to use single quotes (') or to escape the $ (\$) or it will be replaced with the PHP variable (that can be not defined at that time).

1.13或更早的版本

MediaWiki版本:
1.13

When extracting global settings, the object will search first the more specific level (the first one in the list above) and if it doesn't find the setting, it will search in less specific levels. When it finds one, if won't search for less specific ones. This means that you have to pay attention for some specific settings, such as $wgGroupPermissions , because it doesn't merge the setting with less specific levels, nor the default value (the one in DefaultSettings.php), you'll need to do it by yourself.

要提取全局变量中的设置,可以使用$wgConf->extractAllGlobals( $wiki, $suffix, $params, $wikiTags );

Parameters are:

  • $wiki - Wiki's database name (generally $wgDBname ). You have to define it yourself.
  • $suffix - Wiki's suffix, used to to get the suffix level.
  • $params - array of parameters mapping its name to its value.
  • $wikiTags - (在版本1.12.0引入) array of wiki tags.

1.14或更新的版本

MediaWiki版本:
1.14

1.14.0中添加了一些新功能。1.13和更早版本部分仍然可以使用。

回调函数

Since 1.14, a callback has been introduced to be able to modify the parameters passed to SiteConfiguration::get() and related function. It might be used to change parameters when such functions are called after LocalSettings.php (this is the case with CentralAuth). You can define it in $wgConf->siteParamsCallback. The callback function will receive the SiteConfiguration object in the first argument and the wiki name in the second one. It has to return an array with the following keys (all optional):

  • suffix: site's suffix (corresponding to $suffix paramater of SiteConfiguration::get() and similar)
  • lang: site's lang
  • tags: array of wiki tags (corresponding to $wikiTags parameter)
  • params: array of parameters to be replaced (corresponding to $params parameter)

They'll be merged with the parameters passed to SiteConfiguration::get() and similar functions. If the suffix and lang are filled, the they'll be used to override the default behaviour of $wgConf->siteFromDB().

设置合并

Arrays can now be merged. This might be useful for $wgGroupPermissions . To use it, you have to prefix the keys with a "+" for the settings you want to merge.

  • To merge your customized version of the setting with the one in DefaultSettings.php, prefix the setting's name with "+" (such as '+wgGroupPermissions')
  • To merge a more specific level with a less-specific one, prefix the level with a "+".

The two possibilities can be used together.

合并按以下顺序进行:

  1. 数据库名称
  2. Tags (in the order provided to the extraction method, which might very well be randomized at this point)
  3. 维基后缀
  4. 默认

当遇到没有前缀“+”的键时,合并将结束。

$wgGroupPermissions 的示例:

$wgConf->settings = [

# ...

# '+' triggers a merge with this and the value of $wgGroupPermissions defined
#  in DefaultSettings.php
'+wgGroupPermissions' => [

    # Allow bureaucrats to change status on remote wikis
    #  and allow anonymous users to create page (this part
    #  will not be merged with 'default' since there's no
    #  "+" in front of 'centralwiki')
    'centralwiki' => [
        'bureaucrat' => [
            'userrights-interwiki' => true,
        ],
    ],

    # A wiki with rollback right given to logged-in users
    #  the 'default' part will be merged with this value
    #  (i.e. anonymous users won't be able to create pages)
    '+somewiki' => [
        'user' => [
            'rollback' => true,
        ],
    ],

    # Disallow anonymous users to create pages.
    # Note: the 'default' key should never have a "+" in front of it
    'default' => [
        '*' => [
            'createpage' => false,
            'createtalk' => false,
        ],
    ],
],

# ...

];

因此基本语法是:

$wgConf->settings = [
'wgConfigurationSetting' => [
    'default' => 'defaultvalue',
    'wikidatabasename1' => 'value that overrides default for this wiki',
],
# To merge the settings you set here with those in DefaultSettings.php:
'+wgConfigurationSetting' => [
# Note: This and DefaultSettings.php are NOT the same! The default specified here
#        overrides that in DefaultSettings.php, and becomes the new default for all
#        your wikis unless you choose to override it for a particular wiki,
#        like for wikidatabasename1 here.
    'default' => 'defaultvalue',
    'wikidatabasename1' => 'value that overrides default for this wiki',
],
];

示例

This example uses 3 wikis: dewiki, enwiki and frwiki. They are located at http://localhost/$wgDBname/ (i.e. http://localhost/dewiki/, http://localhost/enwiki/ and http://localhost/frwiki/).

它假定已经定义了$wgDBname

In this example, $wgConf->settings is declared in InitialiseSettings.php , this is not required and can be done in LocalSettings.php.

InitialiseSettings.php

<?php

$wgConf->settings = [

'wgServer' => [
    # If you want to allow also usage of https, just use '//localhost'
    #  and set 'http://localhost' at 'wgCanonicalServer'
    'default' => 'http://localhost',
],

'wgCanonicalServer' => [
    'default' => 'http://localhost',
],

'wgScriptPath' => [
    'default' => '/$wiki',
],

'wgArticlePath' => [
    'default' => '/$wiki/index.php/$1',
],

'wgSitename' => [
    'default' => 'Wikipedia',
    'frwiki' => 'Wikipédia', # accent in French
],

'wgLanguageCode' => [
    'default' => '$lang',
],

'wgLocalInterwiki' => [
    'default' => '$lang',
],

];

LocalSettings.php

1.13或更早的版本

MediaWiki版本:
1.13
$wgLocalDatabases = [
    'dewiki',
    'enwiki',
    'frwiki',
];

$wgConf->wikis = $wgLocalDatabases;
$wgConf->suffixes = [ 'wiki' ];
$wgConf->localVHosts = [ 'localhost' ];

require_once "$IP/InitialiseSettings.php";

list( $site, $lang ) = $wgConf->siteFromDB( $wgDBname );
$params = [
    'site' => $site,
    'lang' => $lang,
    'wiki' => $wgDBname,
];
$wgConf->extractAllGlobals( $wgDBname, $site, $params, [] );

1.14或更新的版本

MediaWiki版本:
1.14
$wgLocalDatabases = [
    'dewiki',
    'enwiki',
    'frwiki',
];

$wgConf->wikis = $wgLocalDatabases;
$wgConf->suffixes = [ 'wiki' ];
$wgConf->localVHosts = [ 'localhost' ];

require_once "$IP/InitialiseSettings.php";

function efGetSiteParams( $conf, $wiki ) {
    $site = null;
    $lang = null;
    foreach( $conf->suffixes as $suffix ) {
        if ( substr( $wiki, -strlen( $suffix ) ) === $suffix ) {
            $site = $suffix;
            $lang = substr( $wiki, 0, -strlen( $suffix ) );
            break;
        }
    }
    return [
        'suffix' => $site,
        'lang' => $lang,
        'params' => [
            'lang' => $lang,
            'site' => $site,
            'wiki' => $wiki,
        ],
        'tags' => [],
    ];
}

$wgConf->suffixes = $wgLocalDatabases;
$wgConf->siteParamsCallback = 'efGetSiteParams';
$wgConf->extractAllGlobals( $wgDBname );

项目配置

To see how Wikimedia uses $wgConf to configure its wikis see:

参见

  • The includes/SiteConfiguration.php file (or view it on GitHub), which gives a guide on how $wgConf works which might be easier to understand than this page.