Completed
Push — refact-v2 ( 0317e0 )
by mw
04:47
created

SemanticExtraSpecialProperties.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
		// In case extension.json is being used, the the succeeding steps will
48
		// be handled by the ExtensionRegistry
49
		self::initExtension();
50
51
		$GLOBALS['wgExtensionFunctions'][] = function() {
52
			self::onExtensionFunction();
53
		};
54
	}
55
56
	/**
57
	 * @since 1.4
58
	 */
59
	public static function initExtension() {
60
61
		define( 'SESP_VERSION', '2.0.0-alpha' );
62
63
		// Register extension info
64
		$GLOBALS['wgExtensionCredits']['semantic'][] = array(
65
			'path'           => __FILE__,
66
			'name'           => 'Semantic Extra Special Properties',
67
			'author'         => array(
68
				'[https://www.semantic-mediawiki.org/wiki/User:MWJames James Hong Kong]',
69
				'...'
70
			),
71
			'version'        => SESP_VERSION,
72
			'url'            => 'https://www.mediawiki.org/wiki/Extension:SemanticExtraSpecialProperties',
73
			'descriptionmsg' => 'sesp-desc',
74
			'license-name'   => 'GPL-2.0+'
75
		);
76
77
		$GLOBALS['wgMessagesDirs']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n';
78
		$GLOBALS['wgExtensionMessagesFiles']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n/SemanticExtraSpecialProperties.i18n.php';
79
80
		self::onBeforeExtensionFunction();
81
	}
82
83
	/**
84
	 * Register hooks that require to be listed as soon as possible and preferable
85
	 * before the execution of onExtensionFunction
86
	 *
87
	 * @since 1.4
88
	 */
89
	public static function onBeforeExtensionFunction() {
90
		$GLOBALS['wgHooks']['SMW::Config::BeforeCompletion'][] = '\SESP\HookRegistry::onBeforeConfigCompletion';
91
	}
92
93
	/**
94
	 * @since 2.0
95
	 */
96
	public static function doCheckRequirements() {
97
98
		if ( version_compare( $GLOBALS['wgVersion'], '1.25', '<' ) ) {
99
			die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties/">Semantic Extra Special Properties</a> requires MediaWiki 1.25 or above.' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method doCheckRequirements() 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...
100
		}
101
102
		if ( !defined( 'SMW_VERSION' ) ) {
103
			die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties/">Semantic Extra Special Properties</a> requires <a href="http://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> installed.<br />' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method doCheckRequirements() 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...
104
		}
105
	}
106
107
	/**
108
	 * @since 1.4
109
	 */
110
	public static function onExtensionFunction() {
111
112
		// Check requirements after LocalSetting.php has been processed
113
		self::doCheckRequirements();
114
115
		$configuration = array(
116
			'wgDisableCounters'       => $GLOBALS['wgDisableCounters'],
117
			'sespUseAsFixedTables'    => $GLOBALS['sespUseAsFixedTables'],
118
			'sespSpecialProperties'   => $GLOBALS['sespSpecialProperties'],
119
			'wgSESPExcludeBots'       => $GLOBALS['wgSESPExcludeBots'],
120
			'wgShortUrlPrefix'        => $GLOBALS['wgShortUrlPrefix'],
121
			'sespPropertyDefinitionFile' => $GLOBALS['sespPropertyDefinitionFile'],
122
			'sespLocalPropertyDefinitions' => $GLOBALS['sespLocalPropertyDefinitions'],
123
			'sespPropertyDefinitions' => array()
124
		);
125
126
		$hookRegistry = new HookRegistry(
127
			$configuration
128
		);
129
130
		$hookRegistry->register();
131
	}
132
133
	/**
134
	 * @since 1.4
135
	 *
136
	 * @return string|null
137
	 */
138
	public static function getVersion() {
139
		return SESP_VERSION;
140
	}
141
142
}
143