Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1428250
LocalSettingsLoader.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
LocalSettingsLoader.php
View Options
<?php
namespace
MediaWiki\Settings
;
use
MediaWiki\Settings\Source\SettingsFileUtils
;
/**
* Utility for loading LocalSettings files.
*
* @since 1.38
*/
class
LocalSettingsLoader
{
private
SettingsBuilder
$settingsBuilder
;
private
string
$baseDir
;
public
function
__construct
(
SettingsBuilder
$settingsBuilder
,
string
$baseDir
)
{
$this
->
settingsBuilder
=
$settingsBuilder
;
$this
->
baseDir
=
$baseDir
;
}
/**
* Loads a settings file into the SettingsBuilder provided to the constructor.
*
* This supports JSON and YAML files, PHP files that return a settings array, as well as
* traditional LocalSettings.php files that set variables, for backwards compatibility.
*
* @warning This does not support setting configuration variables that use a prefix other
* than "wg"!
*
* @param string $file
*/
public
function
loadLocalSettingsFile
(
string
$file
)
{
// If $file is not a PHP file, just load it as a data file.
if
(
!
str_ends_with
(
$file
,
'.php'
)
)
{
$this
->
settingsBuilder
->
loadFile
(
$file
);
return
;
}
// Make config settings available in local scope.
$config
=
$this
->
settingsBuilder
->
getConfig
();
foreach
(
$this
->
settingsBuilder
->
getDefinedConfigKeys
()
as
$key
)
{
$var
=
"wg$key"
;
// NOTE: broken for extensions that use prefixes other than "wg"!
$$var
=
$config
->
get
(
$key
);
// XXX: slow?! Can we get the entire array in one go?
}
// make available some non-config globals available
// phpcs:ignore MediaWiki.VariableAnalysis.UnusedGlobalVariables.UnusedGlobal$wgCommandLineMode, MediaWiki.Usage.DeprecatedGlobalVariables
global
$wgCommandLineMode
;
// make additional variables available
// phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgSettings
$wgSettings
=
$this
->
settingsBuilder
;
$IP
=
$this
->
baseDir
;
// pull in the actual settings file
$file
=
SettingsFileUtils
::
resolveRelativeLocation
(
$file
,
$this
->
baseDir
);
$settings
=
require
$file
;
// Capture config variables.
$overrides
=
[];
foreach
(
get_defined_vars
()
as
$name
=>
$value
)
{
if
(
str_starts_with
(
$name
,
'wg'
)
)
{
$key
=
substr
(
$name
,
2
);
$overrides
[
$key
]
=
$value
;
}
}
$this
->
settingsBuilder
->
overrideConfigValues
(
$overrides
);
// If the file returned a settings array, use it.
// This is especially useful for generated PHP files.
if
(
is_array
(
$settings
)
)
{
$this
->
settingsBuilder
->
loadArray
(
$settings
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 15:54 (13 h, 50 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
de/2a/f6f379096b877e0f16ada1f063ed
Default Alt Text
LocalSettingsLoader.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment