-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
SemanticCite.php
173 lines (148 loc) · 5.22 KB
/
SemanticCite.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
171
172
173
<?php
use SCI\HookRegistry;
use SCI\Options;
use SMW\ApplicationFactory;
/**
* @see https://github.com/SemanticMediaWiki/SemanticCite/
*
* @defgroup SCI Semantic Cite
*/
SemanticCite::load();
/**
* @codeCoverageIgnore
*/
class SemanticCite {
/**
* @since 1.3
*
* @note It is expected that this function is loaded before LocalSettings.php
* to ensure that settings and global functions are available by the time
* the extension is activated.
*/
public static function load() {
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
include_once __DIR__ . '/vendor/autoload.php';
}
// Load DefaultSettings
require_once __DIR__ . '/DefaultSettings.php';
}
/**
* @since 1.1
*/
public static function initExtension( $credits = [] ) {
// See https://phabricator.wikimedia.org/T151136
define( 'SCI_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
// Extend the upgrade key provided by SMW to ensure that an DB
// schema is updated accordingly before using the extension
if ( isset( $GLOBALS['smwgUpgradeKey'] ) ) {
// $GLOBALS['smwgUpgradeKey'] .= ':scite:2018-09';
}
// Register message files
$GLOBALS['wgMessagesDirs']['SemanticCite'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['SemanticCiteMagic'] = __DIR__ . '/i18n/SemanticCite.magic.php';
$GLOBALS['wgExtensionMessagesFiles']['SemanticCiteAlias'] = __DIR__ . '/i18n/SemanticCite.alias.php';
$GLOBALS['wgSpecialPages']['FindCitableMetadata'] = '\SCI\Specials\SpecialFindCitableMetadata';
// Restrict access to the meta search for registered users only
$GLOBALS['wgAvailableRights'][] = 'sci-metadatasearch';
$GLOBALS['wgGroupPermissions']['user']['sci-metadatasearch'] = true;
// Register resource files
$GLOBALS['wgResourceModules']['ext.scite.styles'] = [
'styles' => 'res/scite.styles.css',
'localBasePath' => __DIR__ ,
'remoteExtPath' => 'SemanticCite',
'position' => 'top',
'group' => 'ext.smw',
'targets' => [
'mobile',
'desktop'
]
];
$GLOBALS['wgResourceModules']['ext.scite.metadata'] = [
'scripts' => [
'res/scite.text.selector.js',
'res/scite.page.creator.js'
],
'localBasePath' => __DIR__ ,
'remoteExtPath' => 'SemanticCite',
'position' => 'top',
'group' => 'ext.smw',
'dependencies' => [
'ext.scite.styles',
'mediawiki.api'
],
'targets' => [
'mobile',
'desktop'
]
];
// #71
if ( version_compare( $GLOBALS['wgVersion'], '1.32', '<' ) ) {
$dependencies = [
'onoi.qtip',
'onoi.blobstore',
'ext.scite.styles',
'mediawiki.api.parse'
];
} else {
$dependencies = [
'onoi.qtip',
'onoi.blobstore',
'ext.scite.styles',
'mediawiki.api'
];
}
$GLOBALS['wgResourceModules']['ext.scite.tooltip'] = [
'scripts' => [
'res/scite.tooltip.js'
],
'localBasePath' => __DIR__ ,
'remoteExtPath' => 'SemanticCite',
'dependencies' => $dependencies,
'messages' => [
'sci-tooltip-citation-lookup-failure',
'sci-tooltip-citation-lookup-failure-multiple'
],
'targets' => [
'mobile',
'desktop'
]
];
// Register hooks that require to be listed as soon as possible and preferable
// before the execution of onExtensionFunction
HookRegistry::initExtension();
}
/**
* @since 1.1
*/
public static function onExtensionFunction() {
if ( !defined( 'SMW_VERSION' ) ) {
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
die( "\nThe 'Semantic Cite' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
} else {
die( '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticCite/">Semantic Cite</a> extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be installed and enabled.<br />' );
}
}
// Require a global because MW's Special page is missing an interface
// to inject dependencies
$GLOBALS['scigCachePrefix'] = $GLOBALS['wgCachePrefix'] === false ? WikiMap::getCurrentWikiId() : $GLOBALS['wgCachePrefix'];
$configuration = [
'numberOfReferenceListColumns' => $GLOBALS['scigNumberOfReferenceListColumns'],
'browseLinkToCitationResource' => $GLOBALS['scigBrowseLinkToCitationResource'],
'showTooltipForCitationReference' => $GLOBALS['scigShowTooltipForCitationReference'],
'tooltipRequestCacheTTL' => $GLOBALS['scigTooltipRequestCacheTTLInSeconds'],
'citationReferenceCaptionFormat' => $GLOBALS['scigCitationReferenceCaptionFormat'],
'referenceListType' => $GLOBALS['scigReferenceListType'],
'enabledStrictParserValidation' => $GLOBALS['scigEnabledStrictParserValidation'],
'cachePrefix' => $GLOBALS['scigCachePrefix'],
'enabledCitationTextChangeUpdateJob' => $GLOBALS['scigEnabledCitationTextChangeUpdateJob'],
'responsiveMonoColumnCharacterBoundLength' => $GLOBALS['scigResponsiveMonoColumnCharacterBoundLength']
];
$applicationFactory = ApplicationFactory::getInstance();
$hookRegistry = new HookRegistry(
$applicationFactory->getStore(),
$applicationFactory->newCacheFactory()->newMediaWikiCompositeCache( $GLOBALS['scigReferenceListCacheType'] ),
new Options( $configuration )
);
$hookRegistry->register();
}
}