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 ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) { |
17
|
|
|
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">SemanticBreadcrumbLinks</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' ); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
if ( defined( 'SBL_VERSION' ) ) { |
21
|
|
|
// Do not initialize more than once. |
22
|
|
|
return 1; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
SemanticBreadcrumbLinks::initExtension(); |
26
|
|
|
|
27
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
28
|
|
|
SemanticBreadcrumbLinks::onExtensionFunction(); |
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @codeCoverageIgnore |
33
|
|
|
*/ |
34
|
|
|
class SemanticBreadcrumbLinks { |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @since 1.3 |
38
|
|
|
*/ |
39
|
|
|
public static function initExtension() { |
|
|
|
|
40
|
|
|
|
41
|
|
|
// Load DefaultSettings |
42
|
|
|
require_once __DIR__ . '/DefaultSettings.php'; |
43
|
|
|
|
44
|
|
|
define( 'SBL_VERSION', '1.3.0-alpha' ); |
45
|
|
|
|
46
|
|
|
define( 'SBL_PROP_PARENTPAGE', 'Has parent page' ); |
47
|
|
|
|
48
|
|
|
// Register the extension |
49
|
|
|
$GLOBALS['wgExtensionCredits']['semantic'][ ] = array( |
50
|
|
|
'path' => __DIR__, |
51
|
|
|
'name' => 'Semantic Breadcrumb Links', |
52
|
|
|
'author' => array( 'James Hong Kong' ), |
53
|
|
|
'url' => 'https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/', |
54
|
|
|
'descriptionmsg' => 'sbl-desc', |
55
|
|
|
'version' => SBL_VERSION, |
56
|
|
|
'license-name' => 'GPL-2.0+', |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
// Register message files |
60
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticBreadcrumbLinks'] = __DIR__ . '/i18n'; |
61
|
|
|
|
62
|
|
|
// Register resource files |
63
|
|
|
$GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks'] = array( |
64
|
|
|
'styles' => 'res/sbl.styles.css', |
65
|
|
|
'scripts' => 'res/sbl.tooltip.js', |
66
|
|
|
'localBasePath' => __DIR__ , |
67
|
|
|
'remoteExtPath' => 'SemanticBreadcrumbLinks', |
68
|
|
|
'position' => 'top', |
69
|
|
|
'group' => 'ext.smw', |
70
|
|
|
'dependencies' => array( |
71
|
|
|
'onoi.qtip' |
72
|
|
|
), |
73
|
|
|
'targets' => array( |
74
|
|
|
'mobile', |
75
|
|
|
'desktop' |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @since 1.3 |
82
|
|
|
*/ |
83
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
84
|
|
|
|
85
|
|
|
// Default values are defined at this point to ensure |
86
|
|
|
// NS contants are specified prior |
87
|
|
|
$defaultPropertySearchPatternByNamespace = array( |
88
|
|
|
NS_CATEGORY => array( |
89
|
|
|
'_SUBC', |
90
|
|
|
'_SUBC', |
91
|
|
|
'_SUBC' |
92
|
|
|
), |
93
|
|
|
SMW_NS_PROPERTY => array( |
94
|
|
|
'_SUBP', |
95
|
|
|
'_SUBP', |
96
|
|
|
'_SUBP' |
97
|
|
|
), |
98
|
|
|
NS_MAIN => array( |
99
|
|
|
SBL_PROP_PARENTPAGE, |
100
|
|
|
SBL_PROP_PARENTPAGE, |
101
|
|
|
SBL_PROP_PARENTPAGE |
102
|
|
|
), |
103
|
|
|
NS_HELP => array( |
104
|
|
|
SBL_PROP_PARENTPAGE, |
105
|
|
|
SBL_PROP_PARENTPAGE, |
106
|
|
|
SBL_PROP_PARENTPAGE |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$configuration = array( |
111
|
|
|
'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'], |
112
|
|
|
'breadcrumbTrailStyleClass' => $GLOBALS['egSBLBreadcrumbTrailStyleClass'], |
113
|
|
|
'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'], |
114
|
|
|
'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'], |
115
|
|
|
'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'], |
116
|
|
|
'enabledSubpageParentAnnotation' => $GLOBALS['egSBLEnabledSubpageParentAnnotation'], |
117
|
|
|
'wgNamespacesWithSubpages' => $GLOBALS['wgNamespacesWithSubpages'], |
118
|
|
|
'propertySearchPatternByNamespace' => $GLOBALS['egSBLPropertySearchPatternByNamespace'] + $defaultPropertySearchPatternByNamespace |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$hookRegistry = new HookRegistry( |
122
|
|
|
ApplicationFactory::getInstance()->getStore(), |
123
|
|
|
new Options( $configuration ) |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
$hookRegistry->register(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @since 1.3 |
131
|
|
|
* |
132
|
|
|
* @return string|null |
133
|
|
|
*/ |
134
|
|
|
public static function getVersion() { |
135
|
|
|
return SBL_VERSION; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
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.