6
6
* @author Andreas Gohr <[email protected] >
7
7
*/
8
8
9
- if (!defined ('DOKU_INC ' )) define ('DOKU_INC ' ,dirname (__FILE__ ).'/../../ ' );
9
+ use dokuwiki \Cache \Cache ;
10
+ use dokuwiki \Extension \Event ;
11
+
12
+ if (!defined ('DOKU_INC ' )) define ('DOKU_INC ' , __DIR__ .'/../../ ' );
10
13
if (!defined ('NOSESSION ' )) define ('NOSESSION ' ,true ); // we do not use a session or authentication here (better caching)
11
14
if (!defined ('NL ' )) define ('NL ' ,"\n" );
12
15
if (!defined ('DOKU_DISABLE_GZIP_OUTPUT ' )) define ('DOKU_DISABLE_GZIP_OUTPUT ' ,1 ); // we gzip ourself here
@@ -36,19 +39,9 @@ function js_out(){
36
39
$ tpl = trim (preg_replace ('/[^\w-]+/ ' ,'' ,$ INPUT ->str ('t ' )));
37
40
if (!$ tpl ) $ tpl = $ conf ['template ' ];
38
41
39
- // The generated script depends on some dynamic options
40
- $ cache = new cache ('scripts ' .$ _SERVER ['HTTP_HOST ' ].$ _SERVER ['SERVER_PORT ' ].DOKU_BASE .$ tpl ,'.js ' );
41
- $ cache ->_event = 'JS_CACHE_USE ' ;
42
-
43
- // load minified version for some files
44
- $ min = $ conf ['compress ' ] ? '.min ' : '' ;
45
-
46
42
// array of core files
47
43
$ files = array (
48
- DOKU_INC ."lib/scripts/jquery/jquery $ min.js " ,
49
44
DOKU_INC .'lib/scripts/jquery/jquery.cookie.js ' ,
50
- DOKU_INC ."lib/scripts/jquery/jquery-ui $ min.js " ,
51
- DOKU_INC ."lib/scripts/jquery/jquery-migrate $ min.js " ,
52
45
DOKU_INC .'inc/lang/ ' .$ conf ['lang ' ].'/jquery.ui.datepicker.js ' ,
53
46
DOKU_INC ."lib/scripts/fileuploader.js " ,
54
47
DOKU_INC ."lib/scripts/fileuploaderextended.js " ,
@@ -57,6 +50,7 @@ function js_out(){
57
50
DOKU_INC .'lib/scripts/cookie.js ' ,
58
51
DOKU_INC .'lib/scripts/script.js ' ,
59
52
DOKU_INC .'lib/scripts/qsearch.js ' ,
53
+ DOKU_INC .'lib/scripts/search.js ' ,
60
54
DOKU_INC .'lib/scripts/tree.js ' ,
61
55
DOKU_INC .'lib/scripts/index.js ' ,
62
56
DOKU_INC .'lib/scripts/textselection.js ' ,
@@ -75,12 +69,19 @@ function js_out(){
75
69
76
70
// add possible plugin scripts and userscript
77
71
$ files = array_merge ($ files ,js_pluginscripts ());
78
- if (! empty ($ config_cascade ['userscript ' ]['default ' ])) {
72
+ if (is_array ($ config_cascade ['userscript ' ]['default ' ])) {
79
73
foreach ($ config_cascade ['userscript ' ]['default ' ] as $ userscript ) {
80
74
$ files [] = $ userscript ;
81
75
}
82
76
}
83
77
78
+ // Let plugins decide to either put more scripts here or to remove some
79
+ Event::createAndTrigger ('JS_SCRIPT_LIST ' , $ files );
80
+
81
+ // The generated script depends on some dynamic options
82
+ $ cache = new Cache ('scripts ' .$ _SERVER ['HTTP_HOST ' ].$ _SERVER ['SERVER_PORT ' ].md5 (serialize ($ files )),'.js ' );
83
+ $ cache ->setEvent ('JS_CACHE_USE ' );
84
+
84
85
$ cache_files = array_merge ($ files , getConfigFiles ('main ' ));
85
86
$ cache_files [] = __FILE__ ;
86
87
@@ -92,26 +93,29 @@ function js_out(){
92
93
// start output buffering and build the script
93
94
ob_start ();
94
95
95
- $ json = new JSON ();
96
96
// add some global variables
97
97
print "var DOKU_BASE = ' " .DOKU_BASE ."'; " ;
98
98
print "var DOKU_TPL = ' " .tpl_basedir ($ tpl )."'; " ;
99
- print "var DOKU_COOKIE_PARAM = " . $ json -> encode (
99
+ print "var DOKU_COOKIE_PARAM = " . json_encode (
100
100
array (
101
101
'path ' => empty ($ conf ['cookiedir ' ]) ? DOKU_REL : $ conf ['cookiedir ' ],
102
102
'secure ' => $ conf ['securecookie ' ] && is_ssl ()
103
103
))."; " ;
104
104
// FIXME: Move those to JSINFO
105
- print "var DOKU_UHN = " .((int ) useHeading ('navigation ' ))."; " ;
106
- print "var DOKU_UHC = " .((int ) useHeading ('content ' ))."; " ;
105
+ print "Object.defineProperty(window, 'DOKU_UHN', { get: function() { " .
106
+ "console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead'); " .
107
+ "return JSINFO.useHeadingNavigation; } }); " ;
108
+ print "Object.defineProperty(window, 'DOKU_UHC', { get: function() { " .
109
+ "console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead'); " .
110
+ "return JSINFO.useHeadingContent; } }); " ;
107
111
108
112
// load JS specific translations
109
113
$ lang ['js ' ]['plugins ' ] = js_pluginstrings ();
110
114
$ templatestrings = js_templatestrings ($ tpl );
111
115
if (!empty ($ templatestrings )) {
112
116
$ lang ['js ' ]['template ' ] = $ templatestrings ;
113
117
}
114
- echo 'LANG = ' .$ json -> encode ($ lang ['js ' ])."; \n" ;
118
+ echo 'LANG = ' .json_encode ($ lang ['js ' ])."; \n" ;
115
119
116
120
// load toolbar
117
121
toolbar_JSdefines ('toolbar ' );
@@ -172,15 +176,15 @@ function js_load($file){
172
176
173
177
// is it a include_once?
174
178
if ($ match [1 ]){
175
- $ base = utf8_basename ($ ifile );
179
+ $ base = \ dokuwiki \ Utf8 \PhpString:: basename ($ ifile );
176
180
if (array_key_exists ($ base , $ loaded ) && $ loaded [$ base ] === true ){
177
181
$ data = str_replace ($ match [0 ], '' ,$ data );
178
182
continue ;
179
183
}
180
184
$ loaded [$ base ] = true ;
181
185
}
182
186
183
- if ($ ifile{ 0 } != '/ ' ) $ ifile = dirname ($ file ).'/ ' .$ ifile ;
187
+ if ($ ifile[ 0 ] != '/ ' ) $ ifile = dirname ($ file ).'/ ' .$ ifile ;
184
188
185
189
if (file_exists ($ ifile )){
186
190
$ idata = io_readFile ($ ifile );
@@ -219,18 +223,33 @@ function js_pluginscripts(){
219
223
* @return array
220
224
*/
221
225
function js_pluginstrings () {
222
- global $ conf ;
226
+ global $ conf, $ config_cascade ;
223
227
$ pluginstrings = array ();
224
228
$ plugins = plugin_list ();
225
- foreach ($ plugins as $ p ){
226
- if (isset ($ lang )) unset($ lang );
227
- if (file_exists (DOKU_PLUGIN ."$ p/lang/en/lang.php " )) {
228
- include DOKU_PLUGIN ."$ p/lang/en/lang.php " ;
229
+ foreach ($ plugins as $ p ) {
230
+ $ path = DOKU_PLUGIN . $ p . '/lang/ ' ;
231
+
232
+ if (isset ($ lang )) unset($ lang );
233
+ if (file_exists ($ path . "en/lang.php " )) {
234
+ include $ path . "en/lang.php " ;
229
235
}
230
- if (isset ($ conf ['lang ' ]) && $ conf ['lang ' ]!='en ' && file_exists (DOKU_PLUGIN ."$ p/lang/ " .$ conf ['lang ' ]."/lang.php " )) {
231
- include DOKU_PLUGIN ."$ p/lang/ " .$ conf ['lang ' ]."/lang.php " ;
236
+ foreach ($ config_cascade ['lang ' ]['plugin ' ] as $ config_file ) {
237
+ if (file_exists ($ config_file . $ p . '/en/lang.php ' )) {
238
+ include ($ config_file . $ p . '/en/lang.php ' );
239
+ }
240
+ }
241
+ if (isset ($ conf ['lang ' ]) && $ conf ['lang ' ] != 'en ' ) {
242
+ if (file_exists ($ path . $ conf ['lang ' ] . "/lang.php " )) {
243
+ include ($ path . $ conf ['lang ' ] . '/lang.php ' );
244
+ }
245
+ foreach ($ config_cascade ['lang ' ]['plugin ' ] as $ config_file ) {
246
+ if (file_exists ($ config_file . $ p . '/ ' . $ conf ['lang ' ] . '/lang.php ' )) {
247
+ include ($ config_file . $ p . '/ ' . $ conf ['lang ' ] . '/lang.php ' );
248
+ }
249
+ }
232
250
}
233
- if (isset ($ lang ['js ' ])) {
251
+
252
+ if (isset ($ lang ['js ' ])) {
234
253
$ pluginstrings [$ p ] = $ lang ['js ' ];
235
254
}
236
255
}
@@ -247,15 +266,34 @@ function js_pluginstrings() {
247
266
* @return array
248
267
*/
249
268
function js_templatestrings ($ tpl ) {
250
- global $ conf ;
269
+ global $ conf , $ config_cascade ;
270
+
271
+ $ path = tpl_incdir () . 'lang/ ' ;
272
+
251
273
$ templatestrings = array ();
252
- if (file_exists (tpl_incdir ( $ tpl ). " lang/ en/lang.php " )) {
253
- include tpl_incdir ( $ tpl ). " lang/ en/lang.php " ;
274
+ if (file_exists ($ path . " en/lang.php " )) {
275
+ include $ path . " en/lang.php " ;
254
276
}
255
- if (isset ($ conf ['lang ' ]) && $ conf ['lang ' ]!='en ' && file_exists (tpl_incdir ($ tpl )."lang/ " .$ conf ['lang ' ]."/lang.php " )) {
256
- include tpl_incdir ($ tpl )."lang/ " .$ conf ['lang ' ]."/lang.php " ;
277
+ foreach ($ config_cascade ['lang ' ]['template ' ] as $ config_file ) {
278
+ if (file_exists ($ config_file . $ conf ['template ' ] . '/en/lang.php ' )) {
279
+ include ($ config_file . $ conf ['template ' ] . '/en/lang.php ' );
280
+ }
257
281
}
258
- if (isset ($ lang ['js ' ])) {
282
+ if (isset ($ conf ['lang ' ]) && $ conf ['lang ' ] != 'en ' && file_exists ($ path . $ conf ['lang ' ] . "/lang.php " )) {
283
+ include $ path . $ conf ['lang ' ] . "/lang.php " ;
284
+ }
285
+ if (isset ($ conf ['lang ' ]) && $ conf ['lang ' ] != 'en ' ) {
286
+ if (file_exists ($ path . $ conf ['lang ' ] . "/lang.php " )) {
287
+ include $ path . $ conf ['lang ' ] . "/lang.php " ;
288
+ }
289
+ foreach ($ config_cascade ['lang ' ]['template ' ] as $ config_file ) {
290
+ if (file_exists ($ config_file . $ conf ['template ' ] . '/ ' . $ conf ['lang ' ] . '/lang.php ' )) {
291
+ include ($ config_file . $ conf ['template ' ] . '/ ' . $ conf ['lang ' ] . '/lang.php ' );
292
+ }
293
+ }
294
+ }
295
+
296
+ if (isset ($ lang ['js ' ])) {
259
297
$ templatestrings [$ tpl ] = $ lang ['js ' ];
260
298
}
261
299
return $ templatestrings ;
@@ -324,13 +362,13 @@ function js_compress($s){
324
362
// reserved word (e.g. "for", "else", "if") or a
325
363
// variable/object/method (e.g. "foo.color")
326
364
while ($ i < $ slen && (strpos ($ chars ,$ s [$ i ]) === false ) ){
327
- $ result .= $ s{ $ i } ;
365
+ $ result .= $ s[ $ i ] ;
328
366
$ i = $ i + 1 ;
329
367
}
330
368
331
- $ ch = $ s{ $ i } ;
369
+ $ ch = $ s[ $ i ] ;
332
370
// multiline comments (keeping IE conditionals)
333
- if ($ ch == '/ ' && $ s{ $ i +1 } == '* ' && $ s{ $ i +2 } != '@ ' ){
371
+ if ($ ch == '/ ' && $ s[ $ i +1 ] == '* ' && $ s[ $ i +2 ] != '@ ' ){
334
372
$ endC = strpos ($ s ,'*/ ' ,$ i +2 );
335
373
if ($ endC === false ) trigger_error ('Found invalid /*..*/ comment ' , E_USER_ERROR );
336
374
@@ -349,7 +387,7 @@ function js_compress($s){
349
387
}
350
388
351
389
// singleline
352
- if ($ ch == '/ ' && $ s{ $ i +1 } == '/ ' ){
390
+ if ($ ch == '/ ' && $ s[ $ i +1 ] == '/ ' ){
353
391
$ endC = strpos ($ s ,"\n" ,$ i +2 );
354
392
if ($ endC === false ) trigger_error ('Invalid comment ' , E_USER_ERROR );
355
393
$ i = $ endC ;
@@ -360,15 +398,15 @@ function js_compress($s){
360
398
if ($ ch == '/ ' ){
361
399
// rewind, skip white space
362
400
$ j = 1 ;
363
- while (in_array ($ s{ $ i -$ j} , $ whitespaces_chars )){
401
+ while (in_array ($ s[ $ i -$ j] , $ whitespaces_chars )){
364
402
$ j = $ j + 1 ;
365
403
}
366
- if ( in_array ($ s{ $ i -$ j} , $ regex_starters ) ){
404
+ if ( in_array ($ s[ $ i -$ j] , $ regex_starters ) ){
367
405
// yes, this is an re
368
406
// now move forward and find the end of it
369
407
$ j = 1 ;
370
- while ($ s{ $ i +$ j} != '/ ' ){
371
- if ($ s{ $ i +$ j} == '\\' ) $ j = $ j + 2 ;
408
+ while ($ s[ $ i +$ j] != '/ ' ){
409
+ if ($ s[ $ i +$ j] == '\\' ) $ j = $ j + 2 ;
372
410
else $ j ++;
373
411
}
374
412
$ result .= substr ($ s ,$ i ,$ j +1 );
@@ -380,8 +418,8 @@ function js_compress($s){
380
418
// double quote strings
381
419
if ($ ch == '" ' ){
382
420
$ j = 1 ;
383
- while ( $ s{ $ i +$ j} != '" ' && ($ i +$ j < $ slen )){
384
- if ( $ s{ $ i +$ j} == '\\' && ($ s{ $ i +$ j +1 } == '" ' || $ s{ $ i +$ j +1 } == '\\' ) ){
421
+ while ( $ s[ $ i +$ j] != '" ' && ($ i +$ j < $ slen )){
422
+ if ( $ s[ $ i +$ j] == '\\' && ($ s[ $ i +$ j +1 ] == '" ' || $ s[ $ i +$ j +1 ] == '\\' ) ){
385
423
$ j += 2 ;
386
424
}else {
387
425
$ j += 1 ;
@@ -398,8 +436,8 @@ function js_compress($s){
398
436
// single quote strings
399
437
if ($ ch == "' " ){
400
438
$ j = 1 ;
401
- while ( $ s{ $ i +$ j} != "' " && ($ i +$ j < $ slen )){
402
- if ( $ s{ $ i +$ j} == '\\' && ($ s{ $ i +$ j +1 } == "' " || $ s{ $ i +$ j +1 } == '\\' ) ){
439
+ while ( $ s[ $ i +$ j] != "' " && ($ i +$ j < $ slen )){
440
+ if ( $ s[ $ i +$ j] == '\\' && ($ s[ $ i +$ j +1 ] == "' " || $ s[ $ i +$ j +1 ] == '\\' ) ){
403
441
$ j += 2 ;
404
442
}else {
405
443
$ j += 1 ;
0 commit comments