-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
SemanticBreadcrumbLinks.php
170 lines (144 loc) · 4.75 KB
/
SemanticBreadcrumbLinks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
use SBL\HookRegistry;
use SBL\Options;
use SMW\ApplicationFactory;
/**
* @see https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/
*
* @defgroup SBL Semantic Breadcrumb Links
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is part of the Semantic Breadcrumb Links extension. It is not a valid entry point.' );
}
if ( defined( 'SBL_VERSION' ) ) {
// Do not initialize more than once.
return 1;
}
SemanticBreadcrumbLinks::load();
/**
* @codeCoverageIgnore
*/
class SemanticBreadcrumbLinks {
/**
* @since 1.3
*/
public static function load() {
if ( !defined( 'MEDIAWIKI' ) ) {
return;
}
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
include_once __DIR__ . '/vendor/autoload.php';
}
// #56 Ensure the constant is defined before `LocalSettings.php` is
// loaded in order to make it available for use in `LocalSettings.php`
define( 'SBL_PROP_PARENTPAGE', 'Has parent page' );
// Load DefaultSettings
require_once __DIR__ . '/DefaultSettings.php';
}
/**
* @since 1.3
*/
public static function initExtension( $credits = [] ) {
// See https://phabricator.wikimedia.org/T151136
define( 'SBL_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
// Register message files
$GLOBALS['wgMessagesDirs']['SemanticBreadcrumbLinks'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['SemanticBreadcrumbLinksMagic'] = __DIR__ . '/i18n/SemanticBreadcrumbLinks.magic.php';
// Register resource files
$GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks.styles'] = [
'styles' => 'res/sbl.styles.css',
'localBasePath' => __DIR__ ,
'remoteExtPath' => 'SemanticBreadcrumbLinks',
'position' => 'top',
'group' => 'ext.smw',
'targets' => [
'mobile',
'desktop'
]
];
$GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks'] = [
'scripts' => 'res/sbl.tooltip.js',
'localBasePath' => __DIR__ ,
'remoteExtPath' => 'SemanticBreadcrumbLinks',
'position' => 'top',
'group' => 'ext.smw',
'dependencies' => [
'ext.semanticbreadcrumblinks.styles',
'onoi.qtip'
],
'targets' => [
'mobile',
'desktop'
]
];
}
/**
* @since 1.3
*/
public static function onExtensionFunction() {
if ( !defined( 'SMW_VERSION' ) ) {
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
die( "\nThe 'Semantic Breadcrumb Links' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
} else {
die( '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">Semantic Breadcrumb Links</a> extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be installed and enabled.<br />' );
}
}
// Default values are defined at this point to ensure
// NS contants are specified prior
$defaultPropertySearchPatternByNamespace = [
NS_CATEGORY => [
'_SUBC',
'_SUBC',
'_SUBC'
],
SMW_NS_PROPERTY => [
'_SUBP',
'_SUBP',
'_SUBP'
],
NS_MAIN => [
SBL_PROP_PARENTPAGE,
SBL_PROP_PARENTPAGE,
SBL_PROP_PARENTPAGE
],
NS_HELP => [
SBL_PROP_PARENTPAGE,
SBL_PROP_PARENTPAGE,
SBL_PROP_PARENTPAGE
]
];
// Cover legacy settings
$deprecationNotices = [];
if ( isset( $GLOBALS['egSBLBreadcrumbTrailStyleClass'] ) ) {
$GLOBALS['sblgBreadcrumbTrailStyleClass'] = $GLOBALS['egSBLBreadcrumbTrailStyleClass'];
$deprecationNotices['replacement']['egSBLBreadcrumbTrailStyleClass'] = 'sblgBreadcrumbTrailStyleClass';
}
if ( $deprecationNotices !== [] && !isset( $GLOBALS['smwgDeprecationNotices']['sbl'] ) ) {
$GLOBALS['smwgDeprecationNotices']['sbl'] = [ 'replacement' => $deprecationNotices['replacement'] ];
}
$configuration = [
'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'],
'breadcrumbTrailStyleClass' => $GLOBALS['sblgBreadcrumbTrailStyleClass'],
'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'],
'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'],
'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'],
'enabledSubpageParentAnnotation' => $GLOBALS['egSBLEnabledSubpageParentAnnotation'],
'disableTranslationSubpageAnnotation' => $GLOBALS['egSBLDisableTranslationSubpageAnnotation'],
'wgNamespacesWithSubpages' => $GLOBALS['wgNamespacesWithSubpages'],
'propertySearchPatternByNamespace' => $GLOBALS['egSBLPropertySearchPatternByNamespace'] + $defaultPropertySearchPatternByNamespace
];
$hookRegistry = new HookRegistry(
ApplicationFactory::getInstance()->getStore(),
new Options( $configuration )
);
$hookRegistry->register();
}
/**
* @since 1.3
*
* @return string|null
*/
public static function getVersion() {
return SBL_VERSION;
}
}