MediaWiki master
WikiFarmSettingsLoader.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Settings;
4
6
16
17 private SettingsBuilder $settingsBuilder;
18
22 public function __construct( SettingsBuilder $settingsBuilder ) {
23 $this->settingsBuilder = $settingsBuilder;
24 }
25
39 public function loadWikiFarmSettings() {
40 $config = $this->settingsBuilder->getConfig();
41
42 $farmDir = $config->get( MainConfigNames::WikiFarmSettingsDirectory );
43 $farmExt = $config->get( MainConfigNames::WikiFarmSettingsExtension );
44
45 if ( !$farmDir ) {
46 return;
47 }
48
49 $site = null;
50 $wikiName = $this->getWikiNameConstant();
51 if ( $wikiName !== null ) {
52 // The MW_WIKI_NAME constant is used to control the target wiki when running CLI scripts.
53 // Maintenance.php sets it to the value of the --wiki option.
54 $site = $wikiName;
55 } elseif ( isset( $_SERVER['MW_WIKI_NAME'] ) ) {
56 // The MW_WIKI_NAME environment variable is used to set the target wiki
57 // via web server configuration, e.g. using Apache's SetEnv directive.
58 // For maintenance scripts, it may be set as an environment variable,
59 // or by using the --wiki option.
60 $site = $_SERVER['MW_WIKI_NAME'];
61 } elseif ( isset( $_SERVER['WIKI_NAME'] ) ) {
62 // In 1.38, experimental support for wiki farms was added using the
63 // "WIKI_NAME" server variable. This has been changed to "MW_WIKI_NAME"
64 // in 1.39.
65 $site = $_SERVER['WIKI_NAME'];
66
67 // NOTE: We can't use wfDeprecatedMsg here, MediaWiki hasn't been initialized yet.
68 trigger_error(
69 'The WIKI_NAME server variable has been deprecated since 1.39, ' .
70 'use MW_WIKI_NAME instead.'
71 );
72 }
73
74 if ( !$site ) {
75 return;
76 }
77
78 $path = "$farmDir/$site.$farmExt";
79 if ( $this->settingsBuilder->fileExists( $path ) ) {
80 $this->settingsBuilder->loadFile( $path );
81 }
82 }
83
89 protected function getWikiNameConstant() {
90 return defined( 'MW_WIKI_NAME' ) ? MW_WIKI_NAME : null;
91 }
92
93}
A class containing constants representing the names of configuration variables.
const WikiFarmSettingsExtension
Name constant for the WikiFarmSettingsExtension setting, for use with Config::get()
const WikiFarmSettingsDirectory
Name constant for the WikiFarmSettingsDirectory setting, for use with Config::get()
Builder class for constructing a Config object from a set of sources during bootstrap.
Utility for loading site-specific settings in a multi-tenancy ("wiki farm" or "wiki family") environm...
__construct(SettingsBuilder $settingsBuilder)
getWikiNameConstant()
Access MW_WIKI_NAME in a way that can be overridden by tests.
loadWikiFarmSettings()
Loads any site-specific settings in a multi-tenant (wiki-farm) environment.