Completed
Push — master ( 65a2de...91e3d3 )
by mw
11:17
created

SemanticWatchlist::initExtension()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 105
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 105
rs 8.2857
c 0
b 0
f 0
cc 2
eloc 75
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 24 and the first side effect is on line 11.

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 SWL\HookRegistry;
4
5
/**
6
 * @see https://github.com/SemanticMediaWiki/SemanticWatchlist/
7
 *
8
 * @defgroup SWL Semantic Watchlist
9
 */
10
if ( !defined( 'MEDIAWIKI' ) ) {
11
	die( 'This file is part of the SemanticWatchlist extension, it is not a valid entry point.' );
12
}
13
14
if ( defined( 'SWL_VERSION' ) ) {
15
	// Do not initialize more than once.
16
	return 1;
17
}
18
19
SemanticWatchlist::load();
20
21
/**
22
 * @codeCoverageIgnore
23
 */
24
class SemanticWatchlist {
25
26
	/**
27
	 * @since 1.2
28
	 *
29
	 * @note It is expected that this function is loaded before LocalSettings.php
30
	 * to ensure that settings and global functions are available by the time
31
	 * the extension is activated.
32
	 */
33
	public static function load() {
34
35
		if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
36
			include_once __DIR__ . '/vendor/autoload.php';
37
		}
38
39
		// Load DefaultSettings
40
		require_once __DIR__ . '/DefaultSettings.php';
41
42
		/**
43
		 * In case extension.json is being used, the succeeding steps are
44
		 * expected to be handled by the ExtensionRegistry aka extension.json
45
		 * ...
46
		 *
47
		 * 	"callback": "SemanticWatchlist::initExtension",
48
		 * 	"ExtensionFunctions": [
49
		 * 		"SemanticWatchlist::onExtensionFunction"
50
		 * 	],
51
		 */
52
		self::initExtension();
53
54
		$GLOBALS['wgExtensionFunctions'][] = function() {
55
			SemanticWatchlist::onExtensionFunction();
56
		};
57
	}
58
59
	/**
60
	 * @since 1.2
61
	 */
62
	public static function initExtension() {
63
64
		define( 'SWL_VERSION', '1.2.0-alpha' );
65
66
		// Register the extension
67
		$GLOBALS['wgExtensionCredits']['semantic'][] = array(
68
			'path' => __FILE__,
69
			'name' => 'Semantic Watchlist',
70
			'version' => SWL_VERSION,
71
			'author' => array(
72
				'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw] for [http://www.wikiworks.com/ WikiWorks]',
73
				'...'
74
			),
75
			'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Watchlist',
76
			'descriptionmsg' => 'semanticwatchlist-desc',
77
			'license-name'   => 'GPL-3.0+'
78
		);
79
80
		$GLOBALS['egSwlSqlDatabaseSchemaPath'] = __DIR__ . '/src/swl-table-schema.sql';
81
82
		// Register message files
83
		$GLOBALS['wgMessagesDirs']['SemanticWatchlist'] = __DIR__ . '/i18n';
84
		$GLOBALS['wgExtensionMessagesFiles']['SemanticWatchlistAlias'] = __DIR__ . '/SemanticWatchlist.i18n.alias.php';
85
86
		$GLOBALS['egSWLScriptPath'] = $GLOBALS['wgExtensionAssetsPath'] === false ? $GLOBALS['wgScriptPath'] . '/extensions/SemanticWatchlist' : $GLOBALS['wgExtensionAssetsPath'] . '/SemanticWatchlist';
87
88
		// wgAutoloadClasses
89
		$GLOBALS['wgAutoloadClasses']['SWLHooks'] = __DIR__ . '/SemanticWatchlist.hooks.php';
90
91
		$GLOBALS['wgAutoloadClasses']['ApiAddWatchlistGroup'] = __DIR__ . '/api/ApiAddWatchlistGroup.php';
92
		$GLOBALS['wgAutoloadClasses']['ApiDeleteWatchlistGroup'] = __DIR__ . '/api/ApiDeleteWatchlistGroup.php';
93
		$GLOBALS['wgAutoloadClasses']['ApiEditWatchlistGroup'] = __DIR__ . '/api/ApiEditWatchlistGroup.php';
94
		$GLOBALS['wgAutoloadClasses']['ApiQuerySemanticWatchlist'] = __DIR__ . '/api/ApiQuerySemanticWatchlist.php';
95
96
		$GLOBALS['wgAutoloadClasses']['SWLChangeSet'] = __DIR__ . '/includes/SWL_ChangeSet.php';
97
		$GLOBALS['wgAutoloadClasses']['SWLEdit'] = __DIR__ . '/includes/SWL_Edit.php';
98
		$GLOBALS['wgAutoloadClasses']['SWLEmailer'] = __DIR__ . '/includes/SWL_Emailer.php';
99
		$GLOBALS['wgAutoloadClasses']['SWLGroup'] = __DIR__ . '/includes/SWL_Group.php';
100
		$GLOBALS['wgAutoloadClasses']['SWLGroups'] = __DIR__ . '/includes/SWL_Groups.php';
101
		$GLOBALS['wgAutoloadClasses']['SWLPropertyChange'] = __DIR__ . '/includes/SWL_PropertyChange.php';
102
		$GLOBALS['wgAutoloadClasses']['SWLPropertyChanges'] = __DIR__ . '/includes/SWL_PropertyChanges.php';
103
		$GLOBALS['wgAutoloadClasses']['SWLCustomTexts'] = __DIR__ . '/includes/SWL_CustomTexts.php';
104
105
		$GLOBALS['wgAutoloadClasses']['SpecialSemanticWatchlist'] = __DIR__ . '/specials/SpecialSemanticWatchlist.php';
106
		$GLOBALS['wgAutoloadClasses']['SpecialWatchlistConditions'] = __DIR__ . '/specials/SpecialWatchlistConditions.php';
107
108
		// wgSpecialPages
109
		$GLOBALS['wgSpecialPages']['SemanticWatchlist'] = 'SpecialSemanticWatchlist';
110
		$GLOBALS['wgSpecialPageGroups']['SemanticWatchlist'] = 'changes';
111
112
		$GLOBALS['wgSpecialPages']['WatchlistConditions'] = 'SpecialWatchlistConditions';
113
		$GLOBALS['wgSpecialPageGroups']['WatchlistConditions'] = 'changes';
114
115
		// wgAPIModules
116
		$GLOBALS['wgAPIModules']['addswlgroup'] = 'ApiAddWatchlistGroup';
117
		$GLOBALS['wgAPIModules']['deleteswlgroup'] = 'ApiDeleteWatchlistGroup';
118
		$GLOBALS['wgAPIModules']['editswlgroup'] = 'ApiEditWatchlistGroup';
119
		$GLOBALS['wgAPIListModules']['semanticwatchlist'] = 'ApiQuerySemanticWatchlist';
120
121
		// wgAvailableRights
122
		$GLOBALS['wgAvailableRights'][] = 'semanticwatch';
123
		$GLOBALS['wgAvailableRights'][] = 'semanticwatchgroups';
124
125
		$moduleTemplate = array(
126
			'localBasePath' => __DIR__,
127
			'remoteBasePath' => $GLOBALS['egSWLScriptPath']
128
		);
129
130
		$GLOBALS['wgResourceModules']['ext.swl.watchlist'] = $moduleTemplate + array(
131
			'styles' => array( 'specials/ext.swl.watchlist.css' ),
132
			'scripts' => array(),
133
			'dependencies' => array(),
134
			'messages' => array()
135
		);
136
137
		$GLOBALS['wgResourceModules']['ext.swl.watchlistconditions'] = $moduleTemplate + array(
138
			'styles' => array( 'specials/ext.swl.watchlistconditions.css' ),
139
			'scripts' => array(
140
				'specials/jquery.watchlistcondition.js',
141
				'specials/ext.swl.watchlistconditions.js'
142
			),
143
			'dependencies' => array(),
144
			'messages' => array(
145
				'swl-group-name',
146
				'swl-group-legend',
147
				'swl-group-properties',
148
				'swl-properties-list',
149
				'swl-group-remove-property',
150
				'swl-group-add-property',
151
				'swl-group-page-selection',
152
				'swl-group-save',
153
				'swl-group-saved',
154
				'swl-group-saving',
155
				'swl-group-remove',
156
				'swl-group-category',
157
				'swl-group-namespace',
158
				'swl-group-concept',
159
				'swl-group-confirm-remove',
160
				'swl-custom-legend',
161
				'swl-custom-remove-property',
162
				'swl-custom-text-add',
163
				'swl-custom-input',
164
			)
165
		);
166
	}
167
168
	/**
169
	 * @since 1.2
170
	 */
171
	public static function checkRequirements() {
172
173
		if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) {
174
			die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticWatchlist/">Semantic Watchlist</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkRequirements() 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...
175
		}
176
177
		if ( !defined( 'SMW_VERSION' ) ) {
178
			die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticWatchlist/">Semantic Watchlist</a> requires the <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> extension, please enable or install the extension first.' );
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkRequirements() 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...
179
		}
180
	}
181
182
	/**
183
	 * @since 1.2
184
	 */
185
	public static function onExtensionFunction() {
186
187
		// Check requirements after LocalSetting.php has been processed, thid has
188
		// be done here to ensure SMW is loaded in case
189
		// wfLoadExtension( 'SemanticMediaWiki' ) is used
190
		self::checkRequirements();
191
192
		$configuration = array(
193
			'egSWLEnableTopLink'         => $GLOBALS['egSWLEnableTopLink'],
194
			'egSWLEnableEmailNotify'     => $GLOBALS['egSWLEnableEmailNotify'],
195
			'egSwlSqlDatabaseSchemaPath' => $GLOBALS['egSwlSqlDatabaseSchemaPath']
196
		);
197
198
		$hookRegistry = new HookRegistry(
199
			$configuration
200
		);
201
202
		$hookRegistry->register( $GLOBALS['wgHooks'] );
203
	}
204
205
	/**
206
	 * @since 1.2
207
	 *
208
	 * @return string|null
209
	 */
210
	public static function getVersion() {
211
		return SWL_VERSION;
212
	}
213
214
}
215