MediaWiki  master
WikiFarmSettingsLoader.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Settings;
4 
6 
16 
18  private $settingsBuilder;
19 
23  public function __construct( SettingsBuilder $settingsBuilder ) {
24  $this->settingsBuilder = $settingsBuilder;
25  }
26 
40  public function loadWikiFarmSettings() {
41  $config = $this->settingsBuilder->getConfig();
42 
43  $farmDir = $config->get( MainConfigNames::WikiFarmSettingsDirectory );
44  $farmExt = $config->get( MainConfigNames::WikiFarmSettingsExtension );
45 
46  if ( !$farmDir ) {
47  return;
48  }
49 
50  $site = null;
51  $wikiName = $this->getWikiNameConstant();
52  if ( $wikiName !== null ) {
53  // The MW_WIKI_NAME constant is used to control the target wiki when running CLI scripts.
54  // Maintenance.php sets it to the value of the --wiki option.
55  $site = $wikiName;
56  } elseif ( isset( $_SERVER['MW_WIKI_NAME'] ) ) {
57  // The MW_WIKI_NAME environment variable is used to set the target wiki
58  // via web server configuration, e.g. using Apache's SetEnv directive.
59  // For maintenance scripts, it may be set as an environment variable,
60  // or by using the --wiki option.
61  $site = $_SERVER['MW_WIKI_NAME'];
62  } elseif ( isset( $_SERVER['WIKI_NAME'] ) ) {
63  // In 1.38, experimental support for wiki farms was added using the
64  // "WIKI_NAME" server variable. This has been changed to "MW_WIKI_NAME"
65  // in 1.39.
66  $site = $_SERVER['WIKI_NAME'];
67 
68  // NOTE: We can't use wfDeprecatedMsg here, MediaWiki hasn't been initialized yet.
69  trigger_error(
70  'The WIKI_NAME server variable has been deprecated since 1.39, ' .
71  'use MW_WIKI_NAME instead.'
72  );
73  }
74 
75  if ( !$site ) {
76  return;
77  }
78 
79  $path = "$farmDir/$site.$farmExt";
80  if ( $this->settingsBuilder->fileExists( $path ) ) {
81  $this->settingsBuilder->loadFile( $path );
82  }
83  }
84 
90  protected function getWikiNameConstant() {
91  return defined( 'MW_WIKI_NAME' ) ? MW_WIKI_NAME : null;
92  }
93 
94 }
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.