Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
wfDetectLocalSettingsFile | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
wfDetectInstallPath | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
wfIsWindows | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
wfIsCLI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * Functions that need to be available during bootstrapping. |
4 | * Code in this file cannot expect MediaWiki to have been initialized. |
5 | * @file |
6 | */ |
7 | |
8 | /** |
9 | * Decide and remember where to load LocalSettings from. |
10 | * |
11 | * This is used by Setup.php and will (if not already) store the result |
12 | * in the MW_CONFIG_FILE constant. |
13 | * |
14 | * The primary settings file is traditionally LocalSettings.php under the %MediaWiki |
15 | * installation path, but can also be placed differently and specified via the |
16 | * MW_CONFIG_FILE constant (from an entrypoint wrapper) or via a `MW_CONFIG_FILE` |
17 | * environment variable (from the web server). |
18 | * |
19 | * Experimental: The settings file can use the `.yaml` or `.json` extension, which |
20 | * must use the format described on |
21 | * https://www.mediawiki.org/wiki/Manual:YAML_settings_file_format. |
22 | * |
23 | * @internal Only for use by Setup.php and Installer. |
24 | * @since 1.38 |
25 | * @param string|null $installationPath The installation's base path, |
26 | * as returned by wfDetectInstallPath(). |
27 | * |
28 | * @return string The path to the settings file |
29 | */ |
30 | function wfDetectLocalSettingsFile( ?string $installationPath = null ): string { |
31 | if ( defined( 'MW_CONFIG_FILE' ) ) { |
32 | return MW_CONFIG_FILE; |
33 | } |
34 | |
35 | $installationPath ??= wfDetectInstallPath(); |
36 | |
37 | // We could look for LocalSettings.yaml and LocalSettings.json, |
38 | // and use them if they exist. But having them in a web accessible |
39 | // place is dangerous, so better not to encourage that. |
40 | // In order to use LocalSettings.yaml and LocalSettings.json, they |
41 | // will have to be referenced explicitly by MW_CONFIG_FILE. |
42 | $configFile = getenv( 'MW_CONFIG_FILE' ) ?: "LocalSettings.php"; |
43 | // Can't use str_contains because for maintenance scripts (update.php, install.php), |
44 | // this is called *before* Setup.php and vendor (polyfill-php80) are included. |
45 | if ( strpos( $configFile, '/' ) === false ) { |
46 | $configFile = "$installationPath/$configFile"; |
47 | } |
48 | |
49 | define( 'MW_CONFIG_FILE', $configFile ); |
50 | return $configFile; |
51 | } |
52 | |
53 | /** |
54 | * Decide and remember where mediawiki is installed. |
55 | * |
56 | * This is used by Setup.php and will (if not already) store the result |
57 | * in the MW_INSTALL_PATH constant. |
58 | * |
59 | * The install path is detected based on the location of this file, |
60 | * but can be overwritten using the MW_INSTALL_PATH environment variable. |
61 | * |
62 | * @internal Only for use by Setup.php and Installer. |
63 | * @since 1.39 |
64 | * @return string The path to the mediawiki installation |
65 | */ |
66 | function wfDetectInstallPath(): string { |
67 | if ( !defined( 'MW_INSTALL_PATH' ) ) { |
68 | $IP = getenv( 'MW_INSTALL_PATH' ); |
69 | if ( $IP === false ) { |
70 | $IP = dirname( __DIR__ ); |
71 | } |
72 | define( 'MW_INSTALL_PATH', $IP ); |
73 | } |
74 | |
75 | return MW_INSTALL_PATH; |
76 | } |
77 | |
78 | /** |
79 | * Check if the operating system is Windows |
80 | * |
81 | * @return bool True if it's Windows, false otherwise. |
82 | */ |
83 | function wfIsWindows() { |
84 | return PHP_OS_FAMILY === 'Windows'; |
85 | } |
86 | |
87 | /** |
88 | * Check if we are running from the commandline |
89 | * |
90 | * @since 1.31 |
91 | * @return bool |
92 | */ |
93 | function wfIsCLI() { |
94 | return PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg'; |
95 | } |