MediaWiki REL1_39
LocalSettingsLoader.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Settings;
4
6
13
15 private $settingsBuilder;
16
18 private $baseDir;
19
24 public function __construct( SettingsBuilder $settingsBuilder, string $baseDir ) {
25 $this->settingsBuilder = $settingsBuilder;
26 $this->baseDir = $baseDir;
27 }
28
40 public function loadLocalSettingsFile( string $file ) {
41 // If $file is not a PHP file, just load it as a data file.
42 if ( !str_ends_with( $file, '.php' ) ) {
43 $this->settingsBuilder->loadFile( $file );
44 return;
45 }
46
47 // Make config settings available in local scope.
48 $config = $this->settingsBuilder->getConfig();
49 foreach ( $this->settingsBuilder->getDefinedConfigKeys() as $key ) {
50 $var = "wg$key"; // NOTE: broken for extensions that use prefixes other than "wg"!
51 $$var = $config->get( $key ); // XXX: slow?! Can we get the entire array in one go?
52 }
53
54 // make available some non-config globals available
55 // phpcs:ignore MediaWiki.VariableAnalysis.UnusedGlobalVariables.UnusedGlobal$wgCommandLineMode
56 global $wgCommandLineMode;
57
58 // make additional variables available
59 // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgSettings
60 $wgSettings = $this->settingsBuilder;
61 $IP = $this->baseDir;
62
63 // pull in the actual settings file
64 $file = SettingsFileUtils::resolveRelativeLocation( $file, $this->baseDir );
65 $settings = require $file;
66
67 // Capture config variables.
68 $overrides = [];
69 foreach ( get_defined_vars() as $name => $value ) {
70 if ( str_starts_with( $name, 'wg' ) ) {
71 $key = substr( $name, 2 );
72 $overrides[$key] = $value;
73 }
74 }
75
76 $this->settingsBuilder->overrideConfigValues( $overrides );
77
78 // If the file returned a settings array, use it.
79 // This is especially useful for generated PHP files.
80 if ( is_array( $settings ) ) {
81 $this->settingsBuilder->loadArray( $settings );
82 }
83 }
84}
global $wgCommandLineMode
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:91
$wgSettings
Definition Setup.php:143
Utility for loading LocalSettings files.
__construct(SettingsBuilder $settingsBuilder, string $baseDir)
loadLocalSettingsFile(string $file)
Loads a settings file into the SettingsBuilder provided to the constructor.
Utility for loading settings files.
A collection of static utility methods for use with settings files.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42