1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use SBL\HookRegistry; |
4
|
|
|
use SBL\Options; |
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/ |
9
|
|
|
* |
10
|
|
|
* @defgroup SBL Semantic Breadcrumb Links |
11
|
|
|
*/ |
12
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
13
|
|
|
die( 'This file is part of the SemanticBreadcrumbLinks extension, it is not a valid entry point.' ); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
if ( defined( 'SBL_VERSION' ) ) { |
17
|
|
|
// Do not initialize more than once. |
18
|
|
|
return 1; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
SemanticBreadcrumbLinks::load(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @codeCoverageIgnore |
25
|
|
|
*/ |
26
|
|
|
class SemanticBreadcrumbLinks { |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @since 1.3 |
30
|
|
|
*/ |
31
|
|
|
public static function load() { |
|
|
|
|
32
|
|
|
|
33
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
34
|
|
|
include_once __DIR__ . '/vendor/autoload.php'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// Load DefaultSettings |
38
|
|
|
require_once __DIR__ . '/DefaultSettings.php'; |
39
|
|
|
|
40
|
|
|
// In case extension.json is being used, the the succeeding steps will |
41
|
|
|
// be handled by the ExtensionRegistry |
42
|
|
|
self::initExtension(); |
43
|
|
|
|
44
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
45
|
|
|
self::onExtensionFunction(); |
46
|
|
|
}; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @since 1.3 |
51
|
|
|
*/ |
52
|
|
|
public static function initExtension() { |
|
|
|
|
53
|
|
|
|
54
|
|
|
define( 'SBL_VERSION', '1.3.1-alpha' ); |
55
|
|
|
define( 'SBL_PROP_PARENTPAGE', 'Has parent page' ); |
56
|
|
|
|
57
|
|
|
// Register the extension |
58
|
|
|
$GLOBALS['wgExtensionCredits']['semantic'][ ] = array( |
59
|
|
|
'path' => __FILE__, |
60
|
|
|
'name' => 'Semantic Breadcrumb Links', |
61
|
|
|
'author' => array( 'James Hong Kong' ), |
62
|
|
|
'url' => 'https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/', |
63
|
|
|
'descriptionmsg' => 'sbl-desc', |
64
|
|
|
'version' => SBL_VERSION, |
65
|
|
|
'license-name' => 'GPL-2.0+', |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
// Register message files |
69
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticBreadcrumbLinks'] = __DIR__ . '/i18n'; |
70
|
|
|
|
71
|
|
|
// Register resource files |
72
|
|
|
$GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks.styles'] = array( |
73
|
|
|
'styles' => 'res/sbl.styles.css', |
74
|
|
|
'localBasePath' => __DIR__ , |
75
|
|
|
'remoteExtPath' => 'SemanticBreadcrumbLinks', |
76
|
|
|
'position' => 'top', |
77
|
|
|
'group' => 'ext.smw', |
78
|
|
|
'targets' => array( |
79
|
|
|
'mobile', |
80
|
|
|
'desktop' |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks'] = array( |
85
|
|
|
'scripts' => 'res/sbl.tooltip.js', |
86
|
|
|
'localBasePath' => __DIR__ , |
87
|
|
|
'remoteExtPath' => 'SemanticBreadcrumbLinks', |
88
|
|
|
'position' => 'top', |
89
|
|
|
'group' => 'ext.smw', |
90
|
|
|
'dependencies' => array( |
91
|
|
|
'ext.semanticbreadcrumblinks.styles', |
92
|
|
|
'onoi.qtip' |
93
|
|
|
), |
94
|
|
|
'targets' => array( |
95
|
|
|
'mobile', |
96
|
|
|
'desktop' |
97
|
|
|
) |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @since 1.3 |
103
|
|
|
*/ |
104
|
|
|
public static function checkRequirements() { |
|
|
|
|
105
|
|
|
|
106
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) { |
107
|
|
|
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' ); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
111
|
|
|
die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> requires <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a>, please enable or install the extension first.' ); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @since 1.3 |
117
|
|
|
*/ |
118
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
119
|
|
|
|
120
|
|
|
// Check requirements after LocalSetting.php has been processed |
121
|
|
|
self::checkRequirements(); |
122
|
|
|
|
123
|
|
|
// Default values are defined at this point to ensure |
124
|
|
|
// NS contants are specified prior |
125
|
|
|
$defaultPropertySearchPatternByNamespace = array( |
126
|
|
|
NS_CATEGORY => array( |
127
|
|
|
'_SUBC', |
128
|
|
|
'_SUBC', |
129
|
|
|
'_SUBC' |
130
|
|
|
), |
131
|
|
|
SMW_NS_PROPERTY => array( |
132
|
|
|
'_SUBP', |
133
|
|
|
'_SUBP', |
134
|
|
|
'_SUBP' |
135
|
|
|
), |
136
|
|
|
NS_MAIN => array( |
137
|
|
|
SBL_PROP_PARENTPAGE, |
138
|
|
|
SBL_PROP_PARENTPAGE, |
139
|
|
|
SBL_PROP_PARENTPAGE |
140
|
|
|
), |
141
|
|
|
NS_HELP => array( |
142
|
|
|
SBL_PROP_PARENTPAGE, |
143
|
|
|
SBL_PROP_PARENTPAGE, |
144
|
|
|
SBL_PROP_PARENTPAGE |
145
|
|
|
) |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
$configuration = array( |
149
|
|
|
'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'], |
150
|
|
|
'breadcrumbTrailStyleClass' => $GLOBALS['egSBLBreadcrumbTrailStyleClass'], |
151
|
|
|
'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'], |
152
|
|
|
'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'], |
153
|
|
|
'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'], |
154
|
|
|
'enabledSubpageParentAnnotation' => $GLOBALS['egSBLEnabledSubpageParentAnnotation'], |
155
|
|
|
'wgNamespacesWithSubpages' => $GLOBALS['wgNamespacesWithSubpages'], |
156
|
|
|
'propertySearchPatternByNamespace' => $GLOBALS['egSBLPropertySearchPatternByNamespace'] + $defaultPropertySearchPatternByNamespace |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
$hookRegistry = new HookRegistry( |
160
|
|
|
ApplicationFactory::getInstance()->getStore(), |
161
|
|
|
new Options( $configuration ) |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
$hookRegistry->register(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @since 1.3 |
169
|
|
|
* |
170
|
|
|
* @return string|null |
171
|
|
|
*/ |
172
|
|
|
public static function getVersion() { |
173
|
|
|
return SBL_VERSION; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
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.