A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mediawiki.org/wiki/Manual:$wgConf below:

Manual:$wgConf - MediaWiki

Allows you to create a site configuration object. It's not used for much in a default install.

This is used on Wikimedia's mass installation to provide a centralized configuration file for a few hundred wikis, providing defaults per site group and per-wiki overrides.

It is currently needed by Extension:CentralAuth to fetch per-site information, e.g., linking to the proper user pages on each wiki.

Wikis are grouped by the suffix on their database names; on a large installation, there may be, e.g., 'enwiki' and 'enwiktionary' and 'enwikibooks', each in a different suffix group. Suffixes have to be declared in the suffixes member variable of $wgConf if you want to use $wgConf->siteFromDB().

$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):

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).

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):

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

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

The two possibilities can be used together.

Merging happens in the following order:

  1. Database name
  2. Tags (in the order provided to the extraction method, which might very well be randomized at this point)
  3. Wiki suffix
  4. Default

When a key not prefixed with "+" is encountered, the merging will end.

Example with $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 pages (this part
    # will not be merged with 'default' since there are 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,
        ],
    ],
],

# ...

];

The basic syntax is thus:

$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/).

It assumes that $wgDBname is already defined.

In this example,

$wgConf->settings

is declared in

InitialiseSettings.php

, this is not required and can be done in

LocalSettings.php

.

InitialiseSettings.php[edit]
<?php

$wgConf->settings = [

'wgServer' => [
    # If you want to allow the usage of https, 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',
],

];
$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:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4