1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Static class for hooks handled by the Semantic Result Formats. |
5
|
|
|
* |
6
|
|
|
* @since 1.7 |
7
|
|
|
* |
8
|
|
|
* @licence GNU GPL v2+ |
9
|
|
|
* @author Jeroen De Dauw < [email protected] > |
10
|
|
|
* @author mwjames |
11
|
|
|
*/ |
12
|
|
|
final class SRFHooks { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Hook to add PHPUnit test cases. |
16
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList |
17
|
|
|
* |
18
|
|
|
* @since 1.8 |
19
|
|
|
* |
20
|
|
|
* @param array $files |
21
|
|
|
* |
22
|
|
|
* @return boolean |
23
|
|
|
*/ |
24
|
|
|
public static function registerUnitTests( array &$files ) { |
25
|
|
|
// Keep this in alphabetical order please! |
26
|
|
|
$testFiles = [ |
27
|
|
|
|
28
|
|
|
'Resources', |
29
|
|
|
|
30
|
|
|
// Formats |
31
|
|
|
'formats/Array', |
32
|
|
|
'formats/Dygraphs', |
33
|
|
|
'formats/EventCalendar', |
34
|
|
|
'formats/Gallery', |
35
|
|
|
'formats/Graph', |
36
|
|
|
'formats/Incoming', |
37
|
|
|
'formats/jqPlotChart', |
38
|
|
|
'formats/jqPlotSeries', |
39
|
|
|
'formats/ListWidget', |
40
|
|
|
'formats/Math', |
41
|
|
|
'formats/PageWidget', |
42
|
|
|
'formats/Sparkline', |
43
|
|
|
'formats/TagCloud', |
44
|
|
|
'formats/Timeseries', |
45
|
|
|
'formats/Tree', |
46
|
|
|
'formats/vCard', |
47
|
|
|
'formats/MediaPlayer', |
48
|
|
|
'formats/DataTables', |
49
|
|
|
|
50
|
|
|
// Boilerplate |
51
|
|
|
// Register your testclass |
52
|
|
|
// 'formats/Boilerplate', |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
foreach ( $testFiles as $file ) { |
56
|
|
|
$files[] = dirname( __FILE__ ) . '/tests/phpunit/' . $file . 'Test.php'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Add new JavaScript/QUnit testing modules |
64
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules |
65
|
|
|
* |
66
|
|
|
* @since: 1.9 |
67
|
|
|
* |
68
|
|
|
* @param array $testModules array of JavaScript testing modules |
69
|
|
|
* @param ResourceLoader $resourceLoader object |
70
|
|
|
* |
71
|
|
|
* @return boolean |
72
|
|
|
*/ |
73
|
|
|
public static function registerQUnitTests( array &$testModules, ResourceLoader &$resourceLoader ) { |
|
|
|
|
74
|
|
|
$testModules['qunit']['ext.srf.tests'] = [ |
75
|
|
|
'scripts' => [ |
76
|
|
|
// Base |
77
|
|
|
'tests/qunit/ext.srf.test.js', |
78
|
|
|
'tests/qunit/ext.srf.util.test.js', |
79
|
|
|
|
80
|
|
|
// Formats |
81
|
|
|
'tests/qunit/formats/ext.srf.formats.eventcalendar.tests.js', |
82
|
|
|
'tests/qunit/formats/ext.srf.formats.datatables.test.js', |
83
|
|
|
'tests/qunit/formats/ext.srf.formats.filtered.test.js', |
84
|
|
|
'tests/qunit/formats/ext.srf.formats.gallery.test.js', |
85
|
|
|
'tests/qunit/formats/ext.srf.formats.media.test.js', |
86
|
|
|
'tests/qunit/formats/ext.srf.formats.tagcloud.test.js', |
87
|
|
|
|
88
|
|
|
// Widgets |
89
|
|
|
'tests/qunit/widgets/ext.srf.widgets.eventcalendar.tests.js', |
90
|
|
|
'tests/qunit/widgets/ext.srf.widgets.optionslist.test.js', |
91
|
|
|
'tests/qunit/widgets/ext.srf.widgets.panel.test.js', |
92
|
|
|
'tests/qunit/widgets/ext.srf.widgets.parameters.test.js' |
93
|
|
|
|
94
|
|
|
], |
95
|
|
|
'dependencies' => [ |
96
|
|
|
'ext.srf', |
97
|
|
|
'ext.srf.util', |
98
|
|
|
'ext.srf.eventcalendar', |
99
|
|
|
'ext.srf.datatables', |
100
|
|
|
'ext.srf.widgets', |
101
|
|
|
'ext.srf.gallery.overlay', |
102
|
|
|
'ext.srf.gallery.carousel', |
103
|
|
|
'ext.srf.gallery.slideshow', |
104
|
|
|
'ext.srf.gallery.redirect', |
105
|
|
|
'ext.srf.formats.media', |
106
|
|
|
'ext.srf.formats.tagcloud', |
107
|
|
|
'ext.srf.filtered.value-filter.select', |
108
|
|
|
], |
109
|
|
|
'position' => 'top', |
110
|
|
|
'localBasePath' => __DIR__, |
111
|
|
|
'remoteExtPath' => 'SemanticResultFormats', |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
return true; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Adds a link to Admin Links page. |
119
|
|
|
* |
120
|
|
|
* @since 1.7 |
121
|
|
|
* |
122
|
|
|
* @param ALTree $admin_links_tree |
123
|
|
|
* |
124
|
|
|
* @return boolean |
125
|
|
|
*/ |
126
|
|
|
public static function addToAdminLinks( ALTree &$admin_links_tree ) { |
127
|
|
|
$displaying_data_section = $admin_links_tree->getSection( wfMessage( 'smw_adminlinks_displayingdata' )->text() ); |
128
|
|
|
|
129
|
|
|
// Escape is SMW hasn't added links. |
130
|
|
|
if ( is_null( $displaying_data_section ) ) { |
131
|
|
|
return true; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$smw_docu_row = $displaying_data_section->getRow( 'smw' ); |
135
|
|
|
$srf_docu_label = wfMessage( 'adminlinks_documentation', wfMessage( 'srf-name' )->text() )->text(); |
136
|
|
|
$smw_docu_row->addItem( AlItem::newFromExternalLink( 'https://www.mediawiki.org/wiki/Extension:Semantic_Result_Formats', $srf_docu_label ) ); |
137
|
|
|
|
138
|
|
|
return true; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Hook: ResourceLoaderGetConfigVars called right before |
143
|
|
|
* ResourceLoaderStartUpModule::getConfig returns |
144
|
|
|
* |
145
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars |
146
|
|
|
* |
147
|
|
|
* @param &$vars Array of variables to be added into the output of the startup module. |
148
|
|
|
* |
149
|
|
|
* @return true |
150
|
|
|
*/ |
151
|
|
|
public static function onResourceLoaderGetConfigVars( &$vars ) { |
|
|
|
|
152
|
|
|
|
153
|
|
|
$vars['srf-config'] = [ |
154
|
|
|
'version' => SRF_VERSION, |
155
|
|
|
'settings' => [ |
156
|
|
|
'wgThumbLimits' => $GLOBALS['wgThumbLimits'], |
157
|
|
|
'srfgScriptPath' => $GLOBALS['srfgScriptPath'], |
158
|
|
|
] |
159
|
|
|
]; |
160
|
|
|
|
161
|
|
|
return true; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay |
166
|
|
|
* |
167
|
|
|
* @param OutputPage $outputPage |
168
|
|
|
* @param Skin $skin |
169
|
|
|
* |
170
|
|
|
* @return true |
171
|
|
|
*/ |
172
|
|
|
public static function onBeforePageDisplay ( &$outputPage, &$skin ) { |
|
|
|
|
173
|
|
|
|
174
|
|
|
$outputPage->addModuleStyles( 'ext.srf.styles' ); |
175
|
|
|
|
176
|
|
|
return true; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Hook: GetPreferences adds user preference |
181
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences |
182
|
|
|
* |
183
|
|
|
* @param User $user |
184
|
|
|
* @param array $preferences |
185
|
|
|
* |
186
|
|
|
* @return true |
187
|
|
|
*/ |
188
|
|
|
public static function onGetPreferences( $user, &$preferences ) { |
|
|
|
|
189
|
|
|
|
190
|
|
|
// Intro text, do not escape the message here as it contains |
191
|
|
|
// href links |
192
|
|
|
$preferences['srf-prefs-intro'] = |
193
|
|
|
[ |
194
|
|
|
'type' => 'info', |
195
|
|
|
'label' => ' ', |
196
|
|
|
'default' => Html::rawElement( |
197
|
|
|
'span', |
198
|
|
|
[ 'class' => 'srf-prefs-intro plainlinks' ], |
199
|
|
|
wfMessage( 'srf-prefs-intro-text' )->parseAsBlock() |
200
|
|
|
), |
201
|
|
|
'section' => 'smw/srf', |
202
|
|
|
'raw' => 1, |
203
|
|
|
'rawrow' => 1, |
204
|
|
|
]; |
205
|
|
|
|
206
|
|
|
// Enable auto update during a page refresh |
207
|
|
|
$preferences['srf-prefs-eventcalendar-options-update-default'] = [ |
208
|
|
|
'type' => 'toggle', |
209
|
|
|
'label-message' => 'srf-prefs-eventcalendar-options-update-default', |
210
|
|
|
'section' => 'smw/srf-eventcalendar-options', |
211
|
|
|
]; |
212
|
|
|
|
213
|
|
|
// Enable paneView by default |
214
|
|
|
$preferences['srf-prefs-eventcalendar-options-paneview-default'] = [ |
215
|
|
|
'type' => 'toggle', |
216
|
|
|
'label-message' => 'srf-prefs-eventcalendar-options-paneview-default', |
217
|
|
|
'section' => 'smw/srf-eventcalendar-options', |
218
|
|
|
]; |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
// Enable auto update during a page refresh |
222
|
|
|
$preferences['srf-prefs-datatables-options-update-default'] = [ |
223
|
|
|
'type' => 'toggle', |
224
|
|
|
'label-message' => 'srf-prefs-datatables-options-update-default', |
225
|
|
|
'section' => 'smw/srf-datatables-options', |
226
|
|
|
]; |
227
|
|
|
|
228
|
|
|
// Enable local caching |
229
|
|
|
$preferences['srf-prefs-datatables-options-cache-default'] = [ |
230
|
|
|
'type' => 'toggle', |
231
|
|
|
'label-message' => 'srf-prefs-datatables-options-cache-default', |
232
|
|
|
'section' => 'smw/srf-datatables-options', |
233
|
|
|
]; |
234
|
|
|
|
235
|
|
|
return true; |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.