Manual:$wgConf

This page is a translated version of the page Manual:$wgConf and the translation is 36% complete.
Outdated translations are marked like this.
Objetos globais: $wgConf
Cria um objeto de configuração do site. Não é muito usado em uma instalação padrão.
Introduzido na versão:1.5.0 (r9670)
Removido na versão:ainda em uso
Valores permitidos:Indefinido
Valor padrão:novo objeto SiteConfiguration.

Detalhes

Cria um objeto de configuração do site. Não é muito usado em uma instalação padrão.

Isto é usado na instalação em massa do Wikimedia para fornecer um arquivo de configuração centralizada para algumas centenas de wikis, fornecendo padrões por grupo de sites e substituições por wiki.

Pode ser um pouco confuso, no entanto. :) Atualmente necessário pela extensão Extensão:CentralAuth para buscar informações por site, por exemplo, links para as páginas de usuário apropriados em cada wiki.

Configuração

Wikis são agrupadas pelo sufixo em seus nomes do banco de dados; em uma grande instalação pode ser, por exemplo, 'ptwiki' e 'ptwiktionary' e 'ptwikibooks', cada um em um grupo de sufixo diferente. Sufixos precisam ser declarados na suffixes variável-membro de $wgConf se você quiser usar $wgConf->siteFromDB().

$wgConf->settings é o array de configurações. Seu formato é $wgConf->settings['wgSettingName']['wiki'].
As definições podem ser atribuídas (do mais específico para o menos específico, esta é a parte 'wiki' de $wgConf->settings conforme mencionado acima):

  • um nome de banco de dados específico.
  • uma wiki tag (desde aversão 1.12.0)
  • um sufixo (p.ex. 'wiki' or 'wiktionary') para afetar todos nesse grupo de sufixos (pode ser determinado com $wgConf->siteFromDB())
  • 'default' para afetar todas as wikis

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

Para as configurações de strings, você pode definir parâmetros que serão substituídos ao extrair as definições. Pode ser útil quando o ajuste tem o mesmo formato para todas as wikis. O formato é $name. Tenha cuidado ao usar aspas simples (') ou tirar o $ (\$) ou ela será substituída pela variável PHP (que não pode ser definida no momento). 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).

Versão 1.13 e anteriores

Versão 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.

To extract the settings in global variables, you can use $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 - (introduzido na 1.12.0) array of wiki tags.

Versão 1.14 e mais recentes

Versão MediaWiki:
1.14

Alguns novos recursos foram adicionados na versão 1.14.0. A versão 1.13 e anteriores ainda podem ser usadas​​, no entanto.

Função de retorno

Desde a versão 1.14, uma chamada de retorno foi introduzida para poder modificar os parâmetros passados ​​para SiteConfiguration::get() e funções relacionadas. Ele pode ser usado para alterar os parâmetros quando essas funções são chamadas após o arquivo LocalSettings.php (este é o caso com CentralAuth). Você pode defini-lo em $wgConf->siteParamsCallback. A função de retorno de chamada tht-e receberá o objeto SiteConfiguration no primeiro argumento e o nome da wiki no segundo. Ela tem que retornar um array com as seguintes chaves (todas opcionais): 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: sufixo do site (correspondente ao parâmetro $suffix de SiteConfiguration::get() e similar)
  • lang: idioma do site
  • tags: array de tags wiki (correspondente ao parâmetro $wikiTags)
  • params: array de parâmetros a serem substituídos (correspondente ao parâmetro $params)

Eles vão ser mesclados com os parâmetros passados ​​para SiteConfiguration::get() e funções similares. Se suffix e lang estão preenchidos, eles podem ser usados ​​para substituir o comportamento padrão de $wgConf->siteFromDB().

Fusão de definições

Arrays podem agora ser mesclados. Isso pode ser útil para o $wgGroupPermissions . Para usá-lo, você tem que anteceder as teclas com um sinal de mais "+" para as definições que deseja mesclar.

  • Para mesclar sua versão personalizada da definição com a do DefaultSettings.php, prefixar o nome da definição com "+" (tal como '+wgGroupPermissions')
  • Para mesclar um nível mais específico com um menos específico, prefixar o nível com um "+".

As duas possibilidades podem ser utilizadas em conjunto.

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

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 is encountered that is not prefixed with "+", the merging will end.

Exemplo com $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,
        ],
    ],
],

# ...

];

A sintaxe básica é da seguinte forma:

$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',
],
];

Exemplo

Este exemplo usa 3 wikis: dewiki, enwiki e frwiki. Elas estão localizadas em http://localhost/$wgDBname/ (ou seja, http://localhost/dewiki/, http://localhost/enwiki/ and http://localhost/frwiki/).

Ele assume que $wgDBname já está definido.

Neste exemplo, $wgConf->settings é declarado em InitialiseSettings.php, isto não é necessário e pode ser feito em 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

para versão 1.13 e anteriores

Versão 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, [] );

para versão 1.14 e mais recentes

Versão 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 );

Configuração da Wikimedia

Para ver como a Wikimedia usa $wgConf para configurar suas wikis consulte:

  • [$common-set CommonSettings.php] (A versão da Wikimedia do LocalSettings.php)
  • [$init-set InitialiseSettings.php] (para $wgConf->settings)
  • [$wgconf wgConf.php] (utilizado pelo CommonSettings.php para inicializar $wgConf)

See also

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