This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSemanticDrilldown.php
274 lines (235 loc) · 9.07 KB
/
SemanticDrilldown.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
/**
* Semantic Drilldown extension
*
* Defines a drill-down interface for data stored with the Semantic MediaWiki
* extension, via the page Special:BrowseData.
*
* @file
* @defgroup SD Semantic Drilldown
* @ingroup SD
* @author Yaron Koren
*/
// Ensure that the script cannot be executed outside of MediaWiki
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This is an extension to MediaWiki and cannot be run standalone.' );
}
// Define extension's version
define( 'SD_VERSION', '2.0.1' );
// Display extension's information on "Special:Version"
$wgExtensionCredits['semantic'][] = array(
'path' => __FILE__,
'name' => 'Semantic Drilldown',
'version' => SD_VERSION,
'author' => array( 'Yaron Koren', '...' ),
'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Drilldown',
'descriptionmsg' => 'semanticdrilldown-desc',
'license-name' => 'GPL-2.0+'
);
// Constants for special properties - these are all deprecated
// as of version 2.0.
define( 'SD_SP_HAS_FILTER', 1 );
define( 'SD_SP_COVERS_PROPERTY', 2 );
//define( 'SD_SP_HAS_VALUE', 3 );
define( 'SD_SP_GETS_VALUES_FROM_CATEGORY', 4 );
//define( 'SD_SP_USES_TIME_PERIOD', 5 );
define( 'SD_SP_REQUIRES_FILTER', 6 );
define( 'SD_SP_HAS_LABEL', 7 );
define( 'SD_SP_HAS_DRILLDOWN_TITLE', 8 );
//define( 'SD_SP_HAS_INPUT_TYPE', 9 );
define( 'SD_SP_HAS_DISPLAY_PARAMETERS', 10 );
$sdgIP = dirname( __FILE__ );
require_once( $sdgIP . '/languages/SD_Language.php' );
$wgMessagesDirs['SemanticDrilldown'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['SemanticDrilldown'] = $sdgIP . '/languages/SD_Messages.php';
$wgExtensionMessagesFiles['SemanticDrilldownAlias'] = $sdgIP . '/languages/SD_Aliases.php';
$wgExtensionMessagesFiles['SemanticDrilldownMagic'] = $sdgIP . '/languages/SemanticDrilldown.i18n.magic.php';
$wgAutoloadClasses['SDBrowseData'] = $sdgIP . '/specials/SD_BrowseData.php';
$wgAutoloadClasses['SDBrowseDataPage'] = $sdgIP . '/specials/SD_BrowseData.php';
$wgAutoloadClasses['SDUtils'] = $sdgIP . '/includes/SD_Utils.php';
$wgAutoloadClasses['SDFilter'] = $sdgIP . '/includes/SD_Filter.php';
$wgAutoloadClasses['SDFilterValue'] = $sdgIP . '/includes/SD_FilterValue.php';
$wgAutoloadClasses['SDAppliedFilter'] = $sdgIP . '/includes/SD_AppliedFilter.php';
$wgAutoloadClasses['SDPageSchemas'] = $sdgIP . '/includes/SD_PageSchemas.php';
$wgAutoloadClasses['SDParserFunctions'] = $sdgIP . '/includes/SD_ParserFunctions.php';
// register all special pages and other classes
$wgSpecialPages['BrowseData'] = 'SDBrowseData';
$wgHooks['smwInitProperties'][] = 'sdfInitProperties';
$wgHooks['AdminLinks'][] = 'SDUtils::addToAdminLinks';
$wgHooks['MagicWordwgVariableIDs'][] = 'SDUtils::addMagicWordVariableIDs';
$wgHooks['MakeGlobalVariablesScript'][] = 'SDUtils::setGlobalJSVariables';
$wgHooks['ParserBeforeTidy'][] = 'SDUtils::handleShowAndHide';
$wgHooks['PageSchemasRegisterHandlers'][] = 'SDPageSchemas::registerClass';
$wgHooks['ParserFirstCallInit'][] = 'SDParserFunctions::registerFunctions';
# ##
# This is the path to your installation of Semantic Drilldown as
# seen from the web. Change it if required ($wgScriptPath is the
# path to the base directory of your wiki). No final slash.
# # TODO: fix hardcoded path
$sdgScriptPath = $wgScriptPath . '/extensions/SemanticDrilldown';
# #
# ##
# If you already have custom namespaces on your site, insert
# $sdgNamespaceIndex = ???;
# into your LocalSettings.php *before* including this file.
# The number ??? must be the smallest even namespace number
# that is not in use yet. However, it should not be smaller
# than 170.
# #
if ( !isset( $sdgNamespaceIndex ) ) {
sdfInitNamespaces( 170 );
} else {
sdfInitNamespaces();
}
# ##
# # Variables for display
# ##
// Set to true to have Special:BrowseData show only categories that have
// __SHOWINDRILLDOWN__ set.
$sdgHideCategoriesByDefault = false;
$sdgNumResultsPerPage = 250;
// set these to a positive value to trigger the "tag cloud" display
$sdgFiltersSmallestFontSize = - 1;
$sdgFiltersLargestFontSize = - 1;
// print categories list as tabs
$sdgShowCategoriesAsTabs = false;
// other display settings
$sdgMinValuesForComboBox = 40;
$sdgNumRangesForNumberFilters = 6;
/**********************************************/
/***** Global functions *****/
/**********************************************/
/**
* Init the additional namespaces used by Semantic Drilldown.
*/
function sdfInitNamespaces() {
global $sdgNamespaceIndex, $wgExtraNamespaces, $wgNamespaceAliases, $wgNamespacesWithSubpages, $smwgNamespacesWithSemanticLinks;
global $wgLanguageCode, $sdgContLang;
if ( !isset( $sdgNamespaceIndex ) ) {
$sdgNamespaceIndex = 170;
}
define( 'SD_NS_FILTER', $sdgNamespaceIndex );
define( 'SD_NS_FILTER_TALK', $sdgNamespaceIndex + 1 );
sdfInitContentLanguage( $wgLanguageCode );
// Register namespace identifiers
$wgExtraNamespaces = $wgExtraNamespaces + $sdgContLang->getNamespaces();
$wgNamespaceAliases = $wgNamespaceAliases + $sdgContLang->getNamespaceAliases();
// Support subpages only for talk pages by default
$wgNamespacesWithSubpages = array_merge( $wgNamespacesWithSubpages, array(
SD_NS_FILTER_TALK => true
) );
// Enable semantic links on filter pages
$smwgNamespacesWithSemanticLinks = array_merge( $smwgNamespacesWithSemanticLinks, array(
SD_NS_FILTER => true,
SD_NS_FILTER_TALK => false
) );
}
/**********************************************/
/***** language settings *****/
/**********************************************/
/**
* Initialize a global language object for content language. This
* must happen early on, even before user language is known, to
* determine labels for additional namespaces. In contrast, messages
* can be initialized much later when they are actually needed.
*/
function sdfInitContentLanguage( $langcode ) {
global $sdgIP, $sdgContLang;
if ( !empty( $sdgContLang ) ) {
return;
}
$sdContLangClass = 'SD_Language' . str_replace( '-', '_', ucfirst( $langcode ) );
if ( file_exists( $sdgIP . '/languages/' . $sdContLangClass . '.php' ) ) {
include_once( $sdgIP . '/languages/' . $sdContLangClass . '.php' );
}
// fallback if language not supported
if ( !class_exists( $sdContLangClass ) ) {
include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
$sdContLangClass = 'SD_LanguageEn';
}
$sdgContLang = new $sdContLangClass();
}
/**
* Initialize the global language object for user language. This
* must happen after the content language was initialized, since
* this language is used as a fallback.
*/
function sdfInitUserLanguage( $langcode ) {
global $sdgIP, $sdgLang;
if ( !empty( $sdgLang ) ) {
return;
}
$sdLangClass = 'SD_Language' . str_replace( '-', '_', ucfirst( $langcode ) );
if ( file_exists( $sdgIP . '/languages/' . $sdLangClass . '.php' ) ) {
include_once( $sdgIP . '/languages/' . $sdLangClass . '.php' );
}
// fallback if language not supported
if ( !class_exists( $sdLangClass ) ) {
include_once( $sdgIP . '/languages/SD_LanguageEn.php' );
$sdLangClass = 'SD_LanguageEn';
}
$sdgLang = new $sdLangClass();
}
function sdfInitProperties() {
global $sdgContLang, $wgLanguageCode;
$sd_property_vals = array(
SD_SP_HAS_FILTER => array( '_SD_F', '_wpg' ),
SD_SP_COVERS_PROPERTY => array( '_SD_CP', '_wpp' ),
//SD_SP_HAS_VALUE => array( '_SD_V', '_str' ),
SD_SP_GETS_VALUES_FROM_CATEGORY => array( '_SD_VC', '_wpc' ),
//SD_SP_USES_TIME_PERIOD => array( '_SD_TP', '_str' ),
//SD_SP_HAS_INPUT_TYPE => array( '_SD_IT', '_str' ),
SD_SP_REQUIRES_FILTER => array( '_SD_RF', '_wpg' ),
SD_SP_HAS_LABEL => array( '_SD_L', '_str' ),
SD_SP_HAS_DRILLDOWN_TITLE => array( '_SD_DT', '_str' ),
SD_SP_HAS_DISPLAY_PARAMETERS => array( '_SD_DP', '_str' ),
);
// register main property labels
$sd_prop_labels = $sdgContLang->getPropertyLabels();
foreach ( $sd_prop_labels as $prop_id => $prop_alias ) {
$prop_vals = $sd_property_vals[$prop_id];
if ( class_exists( 'SMWDIProperty' ) ) {
SMWDIProperty::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
} else {
SMWPropertyValue::registerProperty( $prop_vals[0], $prop_vals[1], $prop_alias, true );
}
}
// if it's not English, add the English-language aliases as well
if ( $wgLanguageCode != 'en' ) {
$sd_prop_aliases = $sdgContLang->getPropertyAliases();
foreach ( $sd_prop_aliases as $prop_alias => $prop_id ) {
$prop_vals = $sd_property_vals[$prop_id];
if ( class_exists( 'SMWDIProperty' ) ) {
SMWDIProperty::registerPropertyAlias( $prop_vals[0], $prop_alias );
} else {
SMWPropertyValue::registerPropertyAlias( $prop_vals[0], $prop_alias );
}
}
}
return true;
}
$sdgResourceTemplate = array(
'localBasePath' => $sdgIP,
'remoteExtPath' => 'SemanticDrilldown'
);
$wgResourceModules += array(
'ext.semanticdrilldown.main' => $sdgResourceTemplate + array(
'styles' => array(
'skins/SD_main.css',
'skins/SD_jquery_ui_overrides.css',
),
'scripts' => array(
'libs/SemanticDrilldown.js',
),
'dependencies' => array(
'jquery.ui.autocomplete',
'jquery.ui.button',
),
'position' => 'top',
),
'ext.semanticdrilldown.info' => $sdgResourceTemplate + array(
'styles' => array(
'skins/SD_info.css',
),
),
);