Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 4
CRAP
n/a
0 / 0
wfDetectLocalSettingsFile
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
30
wfDetectInstallPath
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
wfIsWindows
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
wfIsCLI
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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 */
30function wfDetectLocalSettingsFile( ?string $installationPath = null ): string {
31    if ( defined( 'MW_CONFIG_FILE' ) ) {
32        return MW_CONFIG_FILE;
33    }
34
35    if ( $installationPath === null ) {
36        $installationPath = wfDetectInstallPath();
37    }
38
39    // We could look for LocalSettings.yaml and LocalSettings.json,
40    // and use them if they exist. But having them in a web accessible
41    // place is dangerous, so better not to encourage that.
42    // In order to use LocalSettings.yaml and LocalSettings.json, they
43    // will have to be referenced explicitly by MW_CONFIG_FILE.
44    $configFile = getenv( 'MW_CONFIG_FILE' ) ?: "LocalSettings.php";
45    // Can't use str_contains because for maintenance scripts (update.php, install.php),
46    // this is called *before* Setup.php and vendor (polyfill-php80) are included.
47    if ( strpos( $configFile, '/' ) === false ) {
48        $configFile = "$installationPath/$configFile";
49    }
50
51    define( 'MW_CONFIG_FILE', $configFile );
52    return $configFile;
53}
54
55/**
56 * Decide and remember where mediawiki is installed.
57 *
58 * This is used by Setup.php and will (if not already) store the result
59 * in the MW_INSTALL_PATH constant.
60 *
61 * The install path is detected based on the location of this file,
62 * but can be overwritten using the MW_INSTALL_PATH environment variable.
63 *
64 * @internal Only for use by Setup.php and Installer.
65 * @since 1.39
66 * @return string The path to the mediawiki installation
67 */
68function wfDetectInstallPath(): string {
69    if ( !defined( 'MW_INSTALL_PATH' ) ) {
70        $IP = getenv( 'MW_INSTALL_PATH' );
71        if ( $IP === false ) {
72            $IP = dirname( __DIR__ );
73        }
74        define( 'MW_INSTALL_PATH', $IP );
75    }
76
77    return MW_INSTALL_PATH;
78}
79
80/**
81 * Check if the operating system is Windows
82 *
83 * @return bool True if it's Windows, false otherwise.
84 */
85function wfIsWindows() {
86    return PHP_OS_FAMILY === 'Windows';
87}
88
89/**
90 * Check if we are running from the commandline
91 *
92 * @since 1.31
93 * @return bool
94 */
95function wfIsCLI() {
96    return PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg';
97}