index.php ➔ wfInstallerMain()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 45
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 28
nc 8
nop 0
dl 0
loc 45
rs 8.439
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 26.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * New version of MediaWiki web-based config/installation
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 * http://www.gnu.org/copyleft/gpl.html
19
 *
20
 * @file
21
 */
22
23
// Bail on old versions of PHP, or if composer has not been run yet to install
24
// dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+.
25
// @codingStandardsIgnoreStart MediaWiki.Usage.DirUsage.FunctionFound
26
require_once dirname( __FILE__ ) . '/../includes/PHPVersionCheck.php';
27
// @codingStandardsIgnoreEnd
28
wfEntryPointCheck( 'mw-config/index.php' );
29
30
define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
31
define( 'MEDIAWIKI_INSTALL', true );
32
33
// Resolve relative to regular MediaWiki root
34
// instead of mw-config subdirectory.
35
chdir( dirname( __DIR__ ) );
36
require dirname( __DIR__ ) . '/includes/WebStart.php';
37
38
wfInstallerMain();
39
40
function wfInstallerMain() {
0 ignored issues
show
Coding Style introduced by
wfInstallerMain uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
41
	global $wgRequest, $wgLang, $wgMetaNamespace, $wgCanonicalNamespaceNames;
42
43
	$installer = InstallerOverrides::getWebInstaller( $wgRequest );
44
45
	if ( !$installer->startSession() ) {
46
47
		if ( $installer->request->getVal( "css" ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $installer->request->getVal('css') of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
48
			// Do not display errors on css pages
49
			$installer->outputCss();
50
			exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function wfInstallerMain() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
51
		}
52
53
		$errors = $installer->getPhpErrors();
54
		$installer->showError( 'config-session-error', $errors[0] );
55
		$installer->finish();
56
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function wfInstallerMain() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
57
	}
58
59
	$fingerprint = $installer->getFingerprint();
60
	if ( isset( $_SESSION['installData'][$fingerprint] ) ) {
61
		$session = $_SESSION['installData'][$fingerprint];
62
	} else {
63
		$session = [];
64
	}
65
66
	if ( !is_null( $wgRequest->getVal( 'uselang' ) ) ) {
67
		$langCode = $wgRequest->getVal( 'uselang' );
68
	} elseif ( isset( $session['settings']['_UserLang'] ) ) {
69
		$langCode = $session['settings']['_UserLang'];
70
	} else {
71
		$langCode = 'en';
72
	}
73
	$wgLang = Language::factory( $langCode );
74
	RequestContext::getMain()->setLanguage( $wgLang );
75
76
	$installer->setParserLanguage( $wgLang );
77
78
	$wgMetaNamespace = $wgCanonicalNamespaceNames[NS_PROJECT];
79
80
	$session = $installer->execute( $session );
81
82
	$_SESSION['installData'][$fingerprint] = $session;
83
84
}
85