Completed
Push — master ( 9d6a7e...b029df )
by mw
06:37
created

onExtensionFunction()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 19
nc 3
nop 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 26 and the first side effect is on line 13.

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
use SESP\HookRegistry;
4
5
/**
6
 * Extension SemanticExtraSpecialProperties - Adds some extra special properties to all pages.
7
 *
8
 * @see https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties
9
 *
10
 * @defgroup SemanticExtraSpecialProperties Semantic Extra Special Properties
11
 */
12
if ( !defined( 'MEDIAWIKI' ) ) {
13
	die( 'This file is part of the SemanticExtraSpecialProperties extension, it is not a valid entry point.' );
14
}
15
16
if ( defined( 'SESP_VERSION' ) ) {
17
	// Do not initialize more than once.
18
	return 1;
19
}
20
21
SemanticExtraSpecialProperties::load();
22
23
/**
24
 * @codeCoverageIgnore
25
 */
26
class SemanticExtraSpecialProperties {
27
28
	/**
29
	 * @since 1.4
30
	 *
31
	 * @note It is expected that this function is loaded before LocalSettings.php
32
	 * to ensure that settings and global functions are available by the time
33
	 * the extension is activated.
34
	 */
35
	public static function load() {
36
37
		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
38
			include_once __DIR__ . '/vendor/autoload.php';
39
		}
40
41
		foreach ( include __DIR__ . '/DefaultSettings.php' as $key => $value ) {
42
			if ( !isset( $GLOBALS[$key] ) ) {
43
				$GLOBALS[$key] = $value;
44
			}
45
		}
46
	}
47
48
	/**
49
	 * @since 1.4
50
	 */
51
	public static function initExtension( $credits = array() ) {
52
53
		// See https://phabricator.wikimedia.org/T151136
54
		define( 'SESP_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
55
56
		$GLOBALS['wgMessagesDirs']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n';
57
58
		// Register hooks that require to be listed as soon as possible and preferable
59
		// before the execution of onExtensionFunction
60
		HookRegistry::initExtension( $GLOBALS );
61
	}
62
63
	/**
64
	 * @since 1.4
65
	 */
66
	public static function onExtensionFunction() {
67
68
		if ( !defined( 'SMW_VERSION' ) ) {
69
			if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
70
				die( "\nThe 'Semantic Extra Special Properties' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
0 ignored issues
show
Coding Style Compatibility introduced by
The method onExtensionFunction() 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...
71
			} else {
72
				die( '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties/">Semantic Extra Special Properties</a> extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be installed and enabled.<br />' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method onExtensionFunction() 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...
73
			}
74
		}
75
76
		$config = [
77
			'wgDisableCounters'       => $GLOBALS['wgDisableCounters'],
78
			'sespUseAsFixedTables'    => $GLOBALS['sespUseAsFixedTables'],
79
			'sespSpecialProperties'   => $GLOBALS['sespSpecialProperties'],
80
			'wgSESPExcludeBots'       => $GLOBALS['wgSESPExcludeBots'],
81
			'wgShortUrlPrefix'        => $GLOBALS['wgShortUrlPrefix'],
82
			'sespPropertyDefinitionFile' => $GLOBALS['sespPropertyDefinitionFile'],
83
			'sespLocalPropertyDefinitions' => $GLOBALS['sespLocalPropertyDefinitions'],
84
			'sespLabelCacheVersion' => $GLOBALS['sespLabelCacheVersion'],
85
			'sespPropertyDefinitions' => [],
86
		];
87
88
		$hookRegistry = new HookRegistry(
89
			$config
90
		);
91
92
		$hookRegistry->register();
93
	}
94
95
	/**
96
	 * @since 1.4
97
	 *
98
	 * @return string|null
99
	 */
100
	public static function getVersion() {
101
102
		if ( !defined( 'SESP_VERSION' ) ) {
103
			return null;
104
		}
105
106
		return SESP_VERSION;
107
	}
108
109
}
110