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