1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use SCI\HookRegistry; |
4
|
|
|
use SCI\Options; |
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticCite/ |
9
|
|
|
* |
10
|
|
|
* @defgroup SCI Semantic Citation |
11
|
|
|
*/ |
12
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
13
|
|
|
die( 'This file is part of the SemanticCite extension, it is not a valid entry point.' ); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.24', 'lt' ) ) { |
17
|
|
|
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticCite/">SemanticCite</a> is only compatible with MediaWiki 1.24 or above. You need to upgrade MediaWiki first.' ); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
if ( defined( 'SCI_VERSION' ) ) { |
21
|
|
|
// Do not initialize more than once. |
22
|
|
|
return 1; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
SemanticCite::initExtension(); |
26
|
|
|
|
27
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
28
|
|
|
SemanticCite::onExtensionFunction(); |
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @codeCoverageIgnore |
33
|
|
|
*/ |
34
|
|
|
class SemanticCite { |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @since 1.1 |
38
|
|
|
*/ |
39
|
|
|
public static function initExtension() { |
|
|
|
|
40
|
|
|
|
41
|
|
|
// Load DefaultSettings |
42
|
|
|
require_once __DIR__ . '/DefaultSettings.php'; |
43
|
|
|
|
44
|
|
|
define( 'SCI_VERSION', '1.1.0-alpha' ); |
45
|
|
|
|
46
|
|
|
// Register the extension |
47
|
|
|
$GLOBALS['wgExtensionCredits']['semantic'][ ] = array( |
48
|
|
|
'path' => __DIR__, |
49
|
|
|
'name' => 'Semantic Cite', |
50
|
|
|
'author' => array( 'James Hong Kong' ), |
51
|
|
|
'url' => 'https://github.com/SemanticMediaWiki/SemanticCite/', |
52
|
|
|
'descriptionmsg' => 'sci-desc', |
53
|
|
|
'version' => SCI_VERSION, |
54
|
|
|
'license-name' => 'GPL-2.0+', |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
// Register message files |
58
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticCite'] = __DIR__ . '/i18n'; |
59
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticCiteMagic'] = __DIR__ . '/i18n/SemanticCite.magic.php'; |
60
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticCiteAlias'] = __DIR__ . '/i18n/SemanticCite.alias.php'; |
61
|
|
|
|
62
|
|
|
$GLOBALS['wgSpecialPages']['FindCitableMetadata'] = '\SCI\Specials\SpecialFindCitableMetadata'; |
63
|
|
|
|
64
|
|
|
// Restrict access to the meta search for registered users only |
65
|
|
|
$GLOBALS['wgAvailableRights'][] = 'sci-metadatasearch'; |
66
|
|
|
$GLOBALS['wgGroupPermissions']['user']['sci-metadatasearch'] = true; |
67
|
|
|
|
68
|
|
|
// Register resource files |
69
|
|
|
$GLOBALS['wgResourceModules']['ext.scite.styles'] = array( |
70
|
|
|
'styles' => 'res/scite.styles.css', |
71
|
|
|
'localBasePath' => __DIR__ , |
72
|
|
|
'remoteExtPath' => 'SemanticCite', |
73
|
|
|
'position' => 'top', |
74
|
|
|
'group' => 'ext.smw', |
75
|
|
|
'targets' => array( |
76
|
|
|
'mobile', |
77
|
|
|
'desktop' |
78
|
|
|
) |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$GLOBALS['wgResourceModules']['ext.scite.metadata'] = array( |
82
|
|
|
'scripts' => array( |
83
|
|
|
'res/scite.text.selector.js', |
84
|
|
|
'res/scite.page.creator.js' |
85
|
|
|
), |
86
|
|
|
'localBasePath' => __DIR__ , |
87
|
|
|
'remoteExtPath' => 'SemanticCite', |
88
|
|
|
'position' => 'top', |
89
|
|
|
'group' => 'ext.smw', |
90
|
|
|
'dependencies' => array( |
91
|
|
|
'ext.scite.styles', |
92
|
|
|
'mediawiki.api' |
93
|
|
|
), |
94
|
|
|
'targets' => array( |
95
|
|
|
'mobile', |
96
|
|
|
'desktop' |
97
|
|
|
) |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$GLOBALS['wgResourceModules']['ext.scite.tooltip'] = array( |
101
|
|
|
'scripts' => array( |
102
|
|
|
'res/scite.tooltip.js' |
103
|
|
|
), |
104
|
|
|
'localBasePath' => __DIR__ , |
105
|
|
|
'remoteExtPath' => 'SemanticCite', |
106
|
|
|
'dependencies' => array( |
107
|
|
|
'onoi.qtip', |
108
|
|
|
'onoi.blobstore', |
109
|
|
|
'onoi.util', |
110
|
|
|
'ext.scite.styles', |
111
|
|
|
'mediawiki.api.parse' |
112
|
|
|
), |
113
|
|
|
'messages' => array( |
114
|
|
|
'sci-tooltip-citation-lookup-failure', |
115
|
|
|
'sci-tooltip-citation-lookup-failure-multiple' |
116
|
|
|
), |
117
|
|
|
'targets' => array( |
118
|
|
|
'mobile', |
119
|
|
|
'desktop' |
120
|
|
|
) |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @since 1.1 |
126
|
|
|
*/ |
127
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
128
|
|
|
|
129
|
|
|
// Require a global because MW's Special page is missing an interface |
130
|
|
|
// to inject dependencies |
131
|
|
|
$GLOBALS['scigCachePrefix'] = $GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix']; |
132
|
|
|
|
133
|
|
|
$configuration = array( |
134
|
|
|
'numberOfReferenceListColumns' => $GLOBALS['scigNumberOfReferenceListColumns'], |
135
|
|
|
'browseLinkToCitationResource' => $GLOBALS['scigBrowseLinkToCitationResource'], |
136
|
|
|
'showTooltipForCitationReference' => $GLOBALS['scigShowTooltipForCitationReference'], |
137
|
|
|
'tooltipRequestCacheTTL' => $GLOBALS['scigTooltipRequestCacheTTLInSeconds'], |
138
|
|
|
'citationReferenceCaptionFormat' => $GLOBALS['scigCitationReferenceCaptionFormat'], |
139
|
|
|
'referenceListType' => $GLOBALS['scigReferenceListType'], |
140
|
|
|
'strictParserValidationEnabled' => $GLOBALS['scigStrictParserValidationEnabled'], |
141
|
|
|
'cachePrefix' => $GLOBALS['scigCachePrefix'], |
142
|
|
|
'enabledCitationTextChangeUpdateJob' => $GLOBALS['scigEnabledCitationTextChangeUpdateJob'] |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$applicationFactory = ApplicationFactory::getInstance(); |
146
|
|
|
|
147
|
|
|
$hookRegistry = new HookRegistry( |
148
|
|
|
$applicationFactory->getStore(), |
149
|
|
|
$applicationFactory->newCacheFactory()->newMediaWikiCompositeCache( $GLOBALS['scigReferenceListCacheType'] ), |
150
|
|
|
new Options( $configuration ) |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
$hookRegistry->register(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @since 1.1 |
158
|
|
|
* |
159
|
|
|
* @return string|null |
160
|
|
|
*/ |
161
|
|
|
public static function getVersion() { |
162
|
|
|
return SCI_VERSION; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
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.