Completed
Push — authpdo ( 7f89f0...388201 )
by Andreas
18:44 queued 12:59
created

html.php ➔ html_revisions()   F

Complexity

Conditions 43
Paths > 20000

Size

Total Lines 247
Code Lines 180

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 43
eloc 180
c 1
b 0
f 0
nc 587928000
nop 2
dl 0
loc 247
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * HTML output functions
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Andreas Gohr <[email protected]>
7
 */
8
9
if(!defined('DOKU_INC')) die('meh.');
10
if(!defined('NL')) define('NL',"\n");
11
12
/**
13
 * Convenience function to quickly build a wikilink
14
 *
15
 * @author Andreas Gohr <[email protected]>
16
 * @param string  $id      id of the target page
17
 * @param string  $name    the name of the link, i.e. the text that is displayed
18
 * @param string|array  $search  search string(s) that shall be highlighted in the target page
19
 * @return string the HTML code of the link
20
 */
21
function html_wikilink($id,$name=null,$search=''){
22
    /** @var Doku_Renderer_xhtml $xhtml_renderer */
23
    static $xhtml_renderer = null;
24
    if(is_null($xhtml_renderer)){
25
        $xhtml_renderer = p_get_renderer('xhtml');
26
    }
27
28
    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
29
}
30
31
/**
32
 * The loginform
33
 *
34
 * @author   Andreas Gohr <[email protected]>
35
 */
36
function html_login(){
37
    global $lang;
38
    global $conf;
39
    global $ID;
40
    global $INPUT;
41
42
    print p_locale_xhtml('login');
43
    print '<div class="centeralign">'.NL;
44
    $form = new Doku_Form(array('id' => 'dw__login'));
45
    $form->startFieldset($lang['btn_login']);
46
    $form->addHidden('id', $ID);
47
    $form->addHidden('do', 'login');
48
    $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block'));
49
    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
50
    if($conf['rememberme']) {
51
        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
52
    }
53
    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
54
    $form->endFieldset();
55
56
    if(actionOK('register')){
57
        $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>');
58
    }
59
60
    if (actionOK('resendpwd')) {
61
        $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>');
62
    }
63
64
    html_form('login', $form);
65
    print '</div>'.NL;
66
}
67
68
69
/**
70
 * Denied page content
71
 *
72
 * @return string html
73
 */
74
function html_denied() {
75
    print p_locale_xhtml('denied');
76
77
    if(empty($_SERVER['REMOTE_USER'])){
78
        html_login();
79
    }
80
}
81
82
/**
83
 * inserts section edit buttons if wanted or removes the markers
84
 *
85
 * @author Andreas Gohr <[email protected]>
86
 *
87
 * @param string $text
88
 * @param bool   $show show section edit buttons?
89
 * @return string
90
 */
91
function html_secedit($text,$show=true){
92
    global $INFO;
93
94
    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
95
96
    if(!$INFO['writable'] || !$show || $INFO['rev']){
97
        return preg_replace($regexp,'',$text);
98
    }
99
100
    return preg_replace_callback($regexp,
101
                'html_secedit_button', $text);
102
}
103
104
/**
105
 * prepares section edit button data for event triggering
106
 * used as a callback in html_secedit
107
 *
108
 * @author Andreas Gohr <[email protected]>
109
 *
110
 * @param array $matches matches with regexp
111
 * @return string
112
 * @triggers HTML_SECEDIT_BUTTON
113
 */
114
function html_secedit_button($matches){
115
    $data = array('secid'  => $matches[1],
116
                  'target' => strtolower($matches[2]),
117
                  'range'  => $matches[count($matches) - 1]);
118
    if (count($matches) === 5) {
119
        $data['name'] = $matches[3];
120
    }
121
122
    return trigger_event('HTML_SECEDIT_BUTTON', $data,
123
                         'html_secedit_get_button');
124
}
125
126
/**
127
 * prints a section editing button
128
 * used as default action form HTML_SECEDIT_BUTTON
129
 *
130
 * @author Adrian Lang <[email protected]>
131
 *
132
 * @param array $data name, section id and target
133
 * @return string html
134
 */
135
function html_secedit_get_button($data) {
136
    global $ID;
137
    global $INFO;
138
139
    if (!isset($data['name']) || $data['name'] === '') return '';
140
141
    $name = $data['name'];
142
    unset($data['name']);
143
144
    $secid = $data['secid'];
145
    unset($data['secid']);
146
147
    return "<div class='secedit editbutton_" . $data['target'] .
148
                       " editbutton_" . $secid . "'>" .
149
           html_btn('secedit', $ID, '',
150
                    array_merge(array('do'  => 'edit',
151
                                      'rev' => $INFO['lastmod'],
152
                                      'summary' => '['.$name.'] '), $data),
153
                    'post', $name) . '</div>';
154
}
155
156
/**
157
 * Just the back to top button (in its own form)
158
 *
159
 * @author Andreas Gohr <[email protected]>
160
 *
161
 * @return string html
162
 */
163
function html_topbtn(){
164
    global $lang;
165
166
    $ret  = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>';
167
168
    return $ret;
169
}
170
171
/**
172
 * Displays a button (using its own form)
173
 * If tooltip exists, the access key tooltip is replaced.
174
 *
175
 * @author Andreas Gohr <[email protected]>
176
 *
177
 * @param string         $name
178
 * @param string         $id
179
 * @param string         $akey   access key
180
 * @param string[] $params key-value pairs added as hidden inputs
181
 * @param string         $method
182
 * @param string         $tooltip
183
 * @param bool|string    $label  label text, false: lookup btn_$name in localization
184
 * @return string
185
 */
186
function html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false){
187
    global $conf;
188
    global $lang;
189
190
    if (!$label)
191
        $label = $lang['btn_'.$name];
192
193
    $ret = '';
194
195
    //filter id (without urlencoding)
196
    $id = idfilter($id,false);
197
198
    //make nice URLs even for buttons
199
    if($conf['userewrite'] == 2){
200
        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
201
    }elseif($conf['userewrite']){
202
        $script = DOKU_BASE.$id;
203
    }else{
204
        $script = DOKU_BASE.DOKU_SCRIPT;
205
        $params['id'] = $id;
206
    }
207
208
    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
209
210
    if(is_array($params)){
211
        reset($params);
212
        while (list($key, $val) = each($params)) {
213
            $ret .= '<input type="hidden" name="'.$key.'" ';
214
            $ret .= 'value="'.htmlspecialchars($val).'" />';
215
        }
216
    }
217
218
    if ($tooltip!='') {
219
        $tip = htmlspecialchars($tooltip);
220
    }else{
221
        $tip = htmlspecialchars($label);
222
    }
223
224
    $ret .= '<button type="submit" ';
225
    if($akey){
226
        $tip .= ' ['.strtoupper($akey).']';
227
        $ret .= 'accesskey="'.$akey.'" ';
228
    }
229
    $ret .= 'title="'.$tip.'">';
230
    $ret .= hsc($label);
231
    $ret .= '</button>';
232
    $ret .= '</div></form>';
233
234
    return $ret;
235
}
236
/**
237
 * show a revision warning
238
 *
239
 * @author Szymon Olewniczak <[email protected]>
240
 */
241
function html_showrev() {
242
    print p_locale_xhtml('showrev');
243
}
244
245
/**
246
 * Show a wiki page
247
 *
248
 * @author Andreas Gohr <[email protected]>
249
 *
250
 * @param null|string $txt wiki text or null for showing $ID
251
 */
252
function html_show($txt=null){
253
    global $ID;
254
    global $REV;
255
    global $HIGH;
256
    global $INFO;
257
    global $DATE_AT;
258
    //disable section editing for old revisions or in preview
259
    if($txt || $REV){
0 ignored issues
show
Bug Best Practice introduced by
The expression $txt of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
260
        $secedit = false;
261
    }else{
262
        $secedit = true;
263
    }
264
265
    if (!is_null($txt)){
266
        //PreviewHeader
267
        echo '<br id="scroll__here" />';
268
        echo p_locale_xhtml('preview');
269
        echo '<div class="preview"><div class="pad">';
270
        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
271
        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
272
        echo $html;
273
        echo '<div class="clearer"></div>';
274
        echo '</div></div>';
275
276
    }else{
277
        if ($REV||$DATE_AT){
278
            $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
279
            trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
280
        }
281
        $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
282
        $html = html_secedit($html,$secedit);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type boolean or null; however, html_secedit() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
283
        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
284
        $html = html_hilight($html,$HIGH);
285
        echo $html;
286
    }
287
}
288
289
/**
290
 * ask the user about how to handle an exisiting draft
291
 *
292
 * @author Andreas Gohr <[email protected]>
293
 */
294
function html_draft(){
295
    global $INFO;
296
    global $ID;
297
    global $lang;
298
    $draft = unserialize(io_readFile($INFO['draft'],false));
299
    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
300
301
    print p_locale_xhtml('draft');
302
    $form = new Doku_Form(array('id' => 'dw__editform'));
303
    $form->addHidden('id', $ID);
304
    $form->addHidden('date', $draft['date']);
305
    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
306
    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
307
    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
308
    $form->addElement(form_makeCloseTag('div'));
309
    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
310
    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
311
    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
312
    html_form('draft', $form);
313
}
314
315
/**
316
 * Highlights searchqueries in HTML code
317
 *
318
 * @author Andreas Gohr <[email protected]>
319
 * @author Harry Fuecks <[email protected]>
320
 *
321
 * @param string $html
322
 * @param array|string $phrases
323
 * @return string html
324
 */
325
function html_hilight($html,$phrases){
326
    $phrases = (array) $phrases;
327
    $phrases = array_map('preg_quote_cb', $phrases);
328
    $phrases = array_map('ft_snippet_re_preprocess', $phrases);
329
    $phrases = array_filter($phrases);
330
    $regex = join('|',$phrases);
331
332
    if ($regex === '') return $html;
333
    if (!utf8_check($regex)) return $html;
334
    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
335
    return $html;
336
}
337
338
/**
339
 * Callback used by html_hilight()
340
 *
341
 * @author Harry Fuecks <[email protected]>
342
 *
343
 * @param array $m matches
344
 * @return string html
345
 */
346
function html_hilight_callback($m) {
347
    $hlight = unslash($m[0]);
348
    if ( !isset($m[2])) {
349
        $hlight = '<span class="search_hit">'.$hlight.'</span>';
350
    }
351
    return $hlight;
352
}
353
354
/**
355
 * Run a search and display the result
356
 *
357
 * @author Andreas Gohr <[email protected]>
358
 */
359
function html_search(){
360
    global $QUERY, $ID;
361
    global $lang;
362
363
    $intro = p_locale_xhtml('searchpage');
364
    // allow use of placeholder in search intro
365
    $pagecreateinfo = (auth_quickaclcheck($ID) >= AUTH_CREATE) ? $lang['searchcreatepage'] : '';
366
    $intro = str_replace(
367
        array('@QUERY@', '@SEARCH@', '@CREATEPAGEINFO@'),
368
        array(hsc(rawurlencode($QUERY)), hsc($QUERY), $pagecreateinfo),
369
        $intro
370
    );
371
    echo $intro;
372
    flush();
373
374
    //show progressbar
375
    print '<div id="dw__loading">'.NL;
376
    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
377
    print 'showLoadBar();'.NL;
378
    print '/*!]]>*/</script>'.NL;
379
    print '</div>'.NL;
380
    flush();
381
382
    //do quick pagesearch
383
    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
384
    if(count($data)){
385
        print '<div class="search_quickresult">';
386
        print '<h3>'.$lang['quickhits'].':</h3>';
387
        print '<ul class="search_quickhits">';
388
        foreach($data as $id => $title){
389
            print '<li> ';
390
            if (useHeading('navigation')) {
391
                $name = $title;
392
            }else{
393
                $ns = getNS($id);
394
                if($ns){
0 ignored issues
show
Bug Best Practice introduced by
The expression $ns of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
395
                    $name = shorten(noNS($id), ' ('.$ns.')',30);
396
                }else{
397
                    $name = $id;
398
                }
399
            }
400
            print html_wikilink(':'.$id,$name);
401
            print '</li> ';
402
        }
403
        print '</ul> ';
404
        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
405
        print '<div class="clearer"></div>';
406
        print '</div>';
407
    }
408
    flush();
409
410
    //do fulltext search
411
    $data = ft_pageSearch($QUERY,$regex);
412
    if(count($data)){
413
        print '<dl class="search_results">';
414
        $num = 1;
415
        foreach($data as $id => $cnt){
416
            print '<dt>';
417
            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
418
            if($cnt !== 0){
419
                print ': '.$cnt.' '.$lang['hits'].'';
420
            }
421
            print '</dt>';
422
            if($cnt !== 0){
423
                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
424
                    print '<dd>'.ft_snippet($id,$regex).'</dd>';
425
                }
426
                $num++;
427
            }
428
            flush();
429
        }
430
        print '</dl>';
431
    }else{
432
        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
433
    }
434
435
    //hide progressbar
436
    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
437
    print 'hideLoadBar("dw__loading");'.NL;
438
    print '/*!]]>*/</script>'.NL;
439
    flush();
440
}
441
442
/**
443
 * Display error on locked pages
444
 *
445
 * @author Andreas Gohr <[email protected]>
446
 */
447
function html_locked(){
448
    global $ID;
449
    global $conf;
450
    global $lang;
451
    global $INFO;
452
453
    $locktime = filemtime(wikiLockFN($ID));
454
    $expire = dformat($locktime + $conf['locktime']);
455
    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
456
457
    print p_locale_xhtml('locked');
458
    print '<ul>';
459
    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
460
    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
461
    print '</ul>';
462
}
463
464
/**
465
 * list old revisions
466
 *
467
 * @author Andreas Gohr <[email protected]>
468
 * @author Ben Coburn <[email protected]>
469
 * @author Kate Arzamastseva <[email protected]>
470
 *
471
 * @param int $first skip the first n changelog lines
472
 * @param bool|string $media_id id of media, or false for current page
473
 */
474
function html_revisions($first=0, $media_id = false){
475
    global $ID;
476
    global $INFO;
477
    global $conf;
478
    global $lang;
479
    $id = $ID;
480
    if ($media_id) {
481
        $id = $media_id;
482
        $changelog = new MediaChangeLog($id);
483
    } else {
484
        $changelog = new PageChangeLog($id);
485
    }
486
487
    /* we need to get one additional log entry to be able to
488
     * decide if this is the last page or is there another one.
489
     * see html_recent()
490
     */
491
492
    $revisions = $changelog->getRevisions($first, $conf['recent']+1);
493
494
    if(count($revisions)==0 && $first!=0){
495
        $first=0;
496
        $revisions = $changelog->getRevisions($first, $conf['recent']+1);
497
    }
498
    $hasNext = false;
499
    if (count($revisions)>$conf['recent']) {
500
        $hasNext = true;
501
        array_pop($revisions); // remove extra log entry
502
    }
503
504
    if (!$media_id) print p_locale_xhtml('revisions');
505
506
    $params = array('id' => 'page__revisions', 'class' => 'changes');
507
    if($media_id) {
508
        $params['action'] = media_managerURL(array('image' => $media_id), '&');
509
    }
510
511
    if(!$media_id) {
512
        $exists = $INFO['exists'];
513
        $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
514
        if(!$display_name) {
515
            $display_name = $id;
516
        }
517
    } else {
518
        $exists = file_exists(mediaFN($id));
519
        $display_name = $id;
520
    }
521
522
    $form = new Doku_Form($params);
523
    $form->addElement(form_makeOpenTag('ul'));
524
525
    if($exists && $first == 0) {
526
        $minor = false;
527
        if($media_id) {
528
            $date = dformat(@filemtime(mediaFN($id)));
529
            $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
530
531
            $changelog->setChunkSize(1024);
532
            $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
533
534
            $summary = $revinfo['sum'];
535
            if($revinfo['user']) {
536
                $editor = $revinfo['user'];
537
            } else {
538
                $editor = $revinfo['ip'];
539
            }
540
            $sizechange = $revinfo['sizechange'];
541
        } else {
542
            $date = dformat($INFO['lastmod']);
543
            if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) {
544
                if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
545
                    $minor = true;
546
                }
547
                if(isset($INFO['meta']['last_change']['sizechange'])) {
548
                    $sizechange = $INFO['meta']['last_change']['sizechange'];
549
                } else {
550
                    $sizechange = null;
551
                }
552
            }
553
            $href = wl($id);
554
            $summary = $INFO['sum'];
555
            $editor = $INFO['editor'];
556
        }
557
558
        $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : ''))));
559
        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
560
        $form->addElement(form_makeTag('input', array(
561
                        'type' => 'checkbox',
562
                        'name' => 'rev2[]',
563
                        'value' => 'current')));
564
565
        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
566
        $form->addElement($date);
567
        $form->addElement(form_makeCloseTag('span'));
568
569
        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
570
571
        $form->addElement(form_makeOpenTag('a', array(
572
                        'class' => 'wikilink1',
573
                        'href'  => $href)));
574
        $form->addElement($display_name);
575
        $form->addElement(form_makeCloseTag('a'));
576
577
        if ($media_id) $form->addElement(form_makeOpenTag('div'));
578
579
        if($summary) {
580
            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
581
            if(!$media_id) $form->addElement(' – ');
582
            $form->addElement('<bdi>' . htmlspecialchars($summary) . '</bdi>');
583
            $form->addElement(form_makeCloseTag('span'));
584
        }
585
586
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
587
        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>');
588
        $form->addElement(form_makeCloseTag('span'));
589
590
        html_sizechange($sizechange, $form);
0 ignored issues
show
Bug introduced by
The variable $sizechange does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
591
592
        $form->addElement('('.$lang['current'].')');
593
594
        if ($media_id) $form->addElement(form_makeCloseTag('div'));
595
596
        $form->addElement(form_makeCloseTag('div'));
597
        $form->addElement(form_makeCloseTag('li'));
598
    }
599
600
    foreach($revisions as $rev) {
601
        $date = dformat($rev);
602
        $info = $changelog->getRevisionInfo($rev);
603
        if($media_id) {
604
            $exists = file_exists(mediaFN($id, $rev));
605
        } else {
606
            $exists = page_exists($id, $rev);
607
        }
608
609
        $class = '';
610
        if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
611
            $class = 'minor';
612
        }
613
        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
614
        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
615
        if($exists){
616
            $form->addElement(form_makeTag('input', array(
617
                            'type' => 'checkbox',
618
                            'name' => 'rev2[]',
619
                            'value' => $rev)));
620
        }else{
621
            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
622
        }
623
624
        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
625
        $form->addElement($date);
626
        $form->addElement(form_makeCloseTag('span'));
627
628
        if($exists){
629
            if (!$media_id) {
630
                $href = wl($id,"rev=$rev,do=diff", false, '&');
631
            } else {
632
                $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
633
            }
634
            $form->addElement(form_makeOpenTag('a', array(
635
                            'class' => 'diff_link',
636
                            'href' => $href)));
637
            $form->addElement(form_makeTag('img', array(
638
                            'src'    => DOKU_BASE.'lib/images/diff.png',
639
                            'width'  => 15,
640
                            'height' => 11,
641
                            'title'  => $lang['diff'],
642
                            'alt'    => $lang['diff'])));
643
            $form->addElement(form_makeCloseTag('a'));
644
645
            if (!$media_id) {
646
                $href = wl($id,"rev=$rev",false,'&');
647
            } else {
648
                $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
649
            }
650
            $form->addElement(form_makeOpenTag('a', array(
651
                            'class' => 'wikilink1',
652
                            'href' => $href)));
653
            $form->addElement($display_name);
654
            $form->addElement(form_makeCloseTag('a'));
655
        }else{
656
            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
657
            $form->addElement($display_name);
658
        }
659
660
        if ($media_id) $form->addElement(form_makeOpenTag('div'));
661
662
        if ($info['sum']) {
663
            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
664
            if(!$media_id) $form->addElement(' – ');
665
            $form->addElement('<bdi>'.htmlspecialchars($info['sum']).'</bdi>');
666
            $form->addElement(form_makeCloseTag('span'));
667
        }
668
669
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
670
        if($info['user']){
671
            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
672
            if(auth_ismanager()){
673
                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
674
            }
675
        }else{
676
            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
677
        }
678
        $form->addElement(form_makeCloseTag('span'));
679
680
        html_sizechange($info['sizechange'], $form);
681
682
        if ($media_id) $form->addElement(form_makeCloseTag('div'));
683
684
        $form->addElement(form_makeCloseTag('div'));
685
        $form->addElement(form_makeCloseTag('li'));
686
    }
687
    $form->addElement(form_makeCloseTag('ul'));
688
    if (!$media_id) {
689
        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
690
    } else {
691
        $form->addHidden('mediado', 'diff');
692
        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
693
    }
694
    html_form('revisions', $form);
695
696
    print '<div class="pagenav">';
697
    $last = $first + $conf['recent'];
698
    if ($first > 0) {
699
        $first -= $conf['recent'];
700
        if ($first < 0) $first = 0;
701
        print '<div class="pagenav-prev">';
702
        if ($media_id) {
703
            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
704
        } else {
705
            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
706
        }
707
        print '</div>';
708
    }
709
    if ($hasNext) {
710
        print '<div class="pagenav-next">';
711
        if ($media_id) {
712
            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
713
        } else {
714
            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
715
        }
716
        print '</div>';
717
    }
718
    print '</div>';
719
720
}
721
722
/**
723
 * display recent changes
724
 *
725
 * @author Andreas Gohr <[email protected]>
726
 * @author Matthias Grimm <[email protected]>
727
 * @author Ben Coburn <[email protected]>
728
 * @author Kate Arzamastseva <[email protected]>
729
 *
730
 * @param int $first
731
 * @param string $show_changes
732
 */
733
function html_recent($first = 0, $show_changes = 'both') {
734
    global $conf;
735
    global $lang;
736
    global $ID;
737
    /* we need to get one additionally log entry to be able to
738
     * decide if this is the last page or is there another one.
739
     * This is the cheapest solution to get this information.
740
     */
741
    $flags = 0;
742
    if($show_changes == 'mediafiles' && $conf['mediarevisions']) {
743
        $flags = RECENTS_MEDIA_CHANGES;
744
    } elseif($show_changes == 'pages') {
745
        $flags = 0;
746
    } elseif($conf['mediarevisions']) {
747
        $show_changes = 'both';
748
        $flags = RECENTS_MEDIA_PAGES_MIXED;
749
    }
750
751
    $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
0 ignored issues
show
Security Bug introduced by
It seems like getNS($ID) targeting getNS() can also be of type false; however, getRecents() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
752
    if(count($recents) == 0 && $first != 0) {
753
        $first = 0;
754
        $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
0 ignored issues
show
Security Bug introduced by
It seems like getNS($ID) targeting getNS() can also be of type false; however, getRecents() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
755
    }
756
    $hasNext = false;
757
    if(count($recents) > $conf['recent']) {
758
        $hasNext = true;
759
        array_pop($recents); // remove extra log entry
760
    }
761
762
    print p_locale_xhtml('recent');
763
764
    if(getNS($ID) != '') {
765
        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
766
    }
767
768
    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
769
    $form->addHidden('sectok', null);
770
    $form->addHidden('do', 'recent');
771
    $form->addHidden('id', $ID);
772
773
    if($conf['mediarevisions']) {
774
        $form->addElement('<div class="changeType">');
775
        $form->addElement(form_makeListboxField(
776
                    'show_changes',
777
                    array(
778
                        'pages'      => $lang['pages_changes'],
779
                        'mediafiles' => $lang['media_changes'],
780
                        'both'       => $lang['both_changes']
781
                    ),
782
                    $show_changes,
783
                    $lang['changes_type'],
784
                    '', '',
785
                    array('class' => 'quickselect')));
786
787
        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
788
        $form->addElement('</div>');
789
    }
790
791
    $form->addElement(form_makeOpenTag('ul'));
792
793
    foreach($recents as $recent) {
794
        $date = dformat($recent['date']);
795
796
        $class = '';
797
        if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
798
            $class = 'minor';
799
        }
800
        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
801
        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
802
803
        if(!empty($recent['media'])) {
804
            $form->addElement(media_printicon($recent['id']));
805
        } else {
806
            $icon = DOKU_BASE . 'lib/images/fileicons/file.png';
807
            $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />');
808
        }
809
810
        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
811
        $form->addElement($date);
812
        $form->addElement(form_makeCloseTag('span'));
813
814
        $diff = false;
815
        $href = '';
816
817
        if(!empty($recent['media'])) {
818
            $changelog = new MediaChangeLog($recent['id']);
819
            $revs = $changelog->getRevisions(0, 1);
820
            $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
821
            if($diff) {
822
                $href = media_managerURL(array(
823
                                            'tab_details' => 'history',
824
                                            'mediado' => 'diff',
825
                                            'image' => $recent['id'],
826
                                            'ns' => getNS($recent['id'])
827
                                        ), '&');
828
            }
829
        } else {
830
            $href = wl($recent['id'], "do=diff", false, '&');
831
        }
832
833
        if(!empty($recent['media']) && !$diff) {
834
            $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
835
        } else {
836
            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
837
            $form->addElement(form_makeTag('img', array(
838
                            'src'    => DOKU_BASE . 'lib/images/diff.png',
839
                            'width'  => 15,
840
                            'height' => 11,
841
                            'title'  => $lang['diff'],
842
                            'alt'    => $lang['diff']
843
                        )));
844
            $form->addElement(form_makeCloseTag('a'));
845
        }
846
847
        if(!empty($recent['media'])) {
848
            $href = media_managerURL(array('tab_details' => 'history', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
849
        } else {
850
            $href = wl($recent['id'], "do=revisions", false, '&');
851
        }
852
        $form->addElement(form_makeOpenTag('a', array(
853
                        'class' => 'revisions_link',
854
                        'href'  => $href)));
855
        $form->addElement(form_makeTag('img', array(
856
                        'src'    => DOKU_BASE . 'lib/images/history.png',
857
                        'width'  => 12,
858
                        'height' => 14,
859
                        'title'  => $lang['btn_revs'],
860
                        'alt'    => $lang['btn_revs']
861
                    )));
862
        $form->addElement(form_makeCloseTag('a'));
863
864
        if(!empty($recent['media'])) {
865
            $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
866
            $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2';
867
            $form->addElement(form_makeOpenTag('a', array(
868
                        'class' => $class,
869
                        'href'  => $href)));
870
            $form->addElement($recent['id']);
871
            $form->addElement(form_makeCloseTag('a'));
872
        } else {
873
            $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id']));
874
        }
875
        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
876
        $form->addElement(' – ' . htmlspecialchars($recent['sum']));
877
        $form->addElement(form_makeCloseTag('span'));
878
879
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
880
        if($recent['user']) {
881
            $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>');
882
            if(auth_ismanager()) {
883
                $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>');
884
            }
885
        } else {
886
            $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>');
887
        }
888
        $form->addElement(form_makeCloseTag('span'));
889
890
        html_sizechange($recent['sizechange'], $form);
891
892
        $form->addElement(form_makeCloseTag('div'));
893
        $form->addElement(form_makeCloseTag('li'));
894
    }
895
    $form->addElement(form_makeCloseTag('ul'));
896
897
    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
898
    $last = $first + $conf['recent'];
899
    if($first > 0) {
900
        $first -= $conf['recent'];
901
        if($first < 0) $first = 0;
902
        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
903
        $form->addElement(form_makeOpenTag('button', array(
904
                        'type'      => 'submit',
905
                        'name'      => 'first[' . $first . ']',
906
                        'accesskey' => 'n',
907
                        'title'     => $lang['btn_newer'] . ' [N]',
908
                        'class'     => 'button show'
909
                    )));
910
        $form->addElement($lang['btn_newer']);
911
        $form->addElement(form_makeCloseTag('button'));
912
        $form->addElement(form_makeCloseTag('div'));
913
    }
914
    if($hasNext) {
915
        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
916
        $form->addElement(form_makeOpenTag('button', array(
917
                        'type'      => 'submit',
918
                        'name'      => 'first[' . $last . ']',
919
                        'accesskey' => 'p',
920
                        'title'     => $lang['btn_older'] . ' [P]',
921
                        'class'     => 'button show'
922
                    )));
923
        $form->addElement($lang['btn_older']);
924
        $form->addElement(form_makeCloseTag('button'));
925
        $form->addElement(form_makeCloseTag('div'));
926
    }
927
    $form->addElement(form_makeCloseTag('div'));
928
    html_form('recent', $form);
929
}
930
931
/**
932
 * Display page index
933
 *
934
 * @author Andreas Gohr <[email protected]>
935
 *
936
 * @param string $ns
937
 */
938
function html_index($ns){
939
    global $conf;
940
    global $ID;
941
    $ns  = cleanID($ns);
942
    if(empty($ns)){
943
        $ns = getNS($ID);
944
        if($ns === false) $ns ='';
945
    }
946
    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
947
948
    echo p_locale_xhtml('index');
949
    echo '<div id="index__tree">';
950
951
    $data = array();
952
    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
953
    echo html_buildlist($data,'idx','html_list_index','html_li_index');
954
955
    echo '</div>';
956
}
957
958
/**
959
 * Index item formatter
960
 *
961
 * User function for html_buildlist()
962
 *
963
 * @author Andreas Gohr <[email protected]>
964
 *
965
 * @param array $item
966
 * @return string
967
 */
968
function html_list_index($item){
969
    global $ID, $conf;
970
971
    // prevent searchbots needlessly following links
972
    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : '';
973
974
    $ret = '';
975
    $base = ':'.$item['id'];
976
    $base = substr($base,strrpos($base,':')+1);
977
    if($item['type']=='d'){
978
        // FS#2766, no need for search bots to follow namespace links in the index
979
        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>';
980
        $ret .= $base;
981
        $ret .= '</strong></a>';
982
    }else{
983
        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
984
        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
985
    }
986
    return $ret;
987
}
988
989
/**
990
 * Index List item
991
 *
992
 * This user function is used in html_buildlist to build the
993
 * <li> tags for namespaces when displaying the page index
994
 * it gives different classes to opened or closed "folders"
995
 *
996
 * @author Andreas Gohr <[email protected]>
997
 *
998
 * @param array $item
999
 * @return string html
1000
 */
1001
function html_li_index($item){
1002
    global $INFO;
1003
    global $ACT;
1004
1005
    $class = '';
1006
    $id = '';
1007
1008
    if($item['type'] == "f"){
1009
        // scroll to the current item
1010
        if($item['id'] == $INFO['id'] && $ACT == 'index') {
1011
            $id = ' id="scroll__here"';
1012
            $class = ' bounce';
1013
        }
1014
        return '<li class="level'.$item['level'].$class.'" '.$id.'>';
1015
    }elseif($item['open']){
1016
        return '<li class="open">';
1017
    }else{
1018
        return '<li class="closed">';
1019
    }
1020
}
1021
1022
/**
1023
 * Default List item
1024
 *
1025
 * @author Andreas Gohr <[email protected]>
1026
 *
1027
 * @param array $item
1028
 * @return string html
1029
 */
1030
function html_li_default($item){
1031
    return '<li class="level'.$item['level'].'">';
1032
}
1033
1034
/**
1035
 * Build an unordered list
1036
 *
1037
 * Build an unordered list from the given $data array
1038
 * Each item in the array has to have a 'level' property
1039
 * the item itself gets printed by the given $func user
1040
 * function. The second and optional function is used to
1041
 * print the <li> tag. Both user function need to accept
1042
 * a single item.
1043
 *
1044
 * Both user functions can be given as array to point to
1045
 * a member of an object.
1046
 *
1047
 * @author Andreas Gohr <[email protected]>
1048
 *
1049
 * @param array    $data  array with item arrays
1050
 * @param string   $class class of ul wrapper
1051
 * @param callable $func  callback to print an list item
1052
 * @param callable $lifunc callback to the opening li tag
1053
 * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
1054
 *                               0 (we have a root object) or 1 (just the root content)
1055
 * @return string html of an unordered list
1056
 */
1057
function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1058
    if (count($data) === 0) {
1059
        return '';
1060
    }
1061
1062
    $start_level = $data[0]['level'];
1063
    $level = $start_level;
1064
    $ret   = '';
1065
    $open  = 0;
1066
1067
    foreach ($data as $item){
1068
1069
        if( $item['level'] > $level ){
1070
            //open new list
1071
            for($i=0; $i<($item['level'] - $level); $i++){
1072
                if ($i) $ret .= "<li class=\"clear\">";
1073
                $ret .= "\n<ul class=\"$class\">\n";
1074
                $open++;
1075
            }
1076
            $level = $item['level'];
1077
1078
        }elseif( $item['level'] < $level ){
1079
            //close last item
1080
            $ret .= "</li>\n";
1081
            while( $level > $item['level'] && $open > 0 ){
1082
                //close higher lists
1083
                $ret .= "</ul>\n</li>\n";
1084
                $level--;
1085
                $open--;
1086
            }
1087
        } elseif ($ret !== '') {
1088
            //close previous item
1089
            $ret .= "</li>\n";
1090
        }
1091
1092
        //print item
1093
        $ret .= call_user_func($lifunc,$item);
1094
        $ret .= '<div class="li">';
1095
1096
        $ret .= call_user_func($func,$item);
1097
        $ret .= '</div>';
1098
    }
1099
1100
    //close remaining items and lists
1101
    $ret .= "</li>\n";
1102
    while($open-- > 0) {
1103
        $ret .= "</ul></li>\n";
1104
    }
1105
1106
    if ($forcewrapper || $start_level < 2) {
1107
        // Trigger building a wrapper ul if the first level is
1108
        // 0 (we have a root object) or 1 (just the root content)
1109
        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1110
    }
1111
1112
    return $ret;
1113
}
1114
1115
/**
1116
 * display backlinks
1117
 *
1118
 * @author Andreas Gohr <[email protected]>
1119
 * @author Michael Klier <[email protected]>
1120
 */
1121
function html_backlinks(){
1122
    global $ID;
1123
    global $lang;
1124
1125
    print p_locale_xhtml('backlinks');
1126
1127
    $data = ft_backlinks($ID);
1128
1129
    if(!empty($data)) {
1130
        print '<ul class="idx">';
1131
        foreach($data as $blink){
1132
            print '<li><div class="li">';
1133
            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
1134
            print '</div></li>';
1135
        }
1136
        print '</ul>';
1137
    } else {
1138
        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1139
    }
1140
}
1141
1142
/**
1143
 * Get header of diff HTML
1144
 *
1145
 * @param string $l_rev   Left revisions
1146
 * @param string $r_rev   Right revision
1147
 * @param string $id      Page id, if null $ID is used
1148
 * @param bool   $media   If it is for media files
1149
 * @param bool   $inline  Return the header on a single line
1150
 * @return string[] HTML snippets for diff header
1151
 */
1152
function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1153
    global $lang;
1154
    if ($id === null) {
1155
        global $ID;
1156
        $id = $ID;
1157
    }
1158
    $head_separator = $inline ? ' ' : '<br />';
1159
    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1160
    $ml_or_wl = $media ? 'ml' : 'wl';
1161
    $l_minor = $r_minor = '';
1162
1163
    if($media) {
1164
        $changelog = new MediaChangeLog($id);
1165
    } else {
1166
        $changelog = new PageChangeLog($id);
1167
    }
1168
    if(!$l_rev){
1169
        $l_head = '&mdash;';
1170
    }else{
1171
        $l_info   = $changelog->getRevisionInfo($l_rev);
1172
        if($l_info['user']){
1173
            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1174
            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1175
        } else {
1176
            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1177
        }
1178
        $l_user  = '<span class="user">'.$l_user.'</span>';
1179
        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1180
        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1181
1182
        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1183
        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1184
        $l_head_title.'</a></bdi>'.
1185
        $head_separator.$l_user.' '.$l_sum;
1186
    }
1187
1188
    if($r_rev){
1189
        $r_info   = $changelog->getRevisionInfo($r_rev);
1190
        if($r_info['user']){
1191
            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1192
            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1193
        } else {
1194
            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1195
        }
1196
        $r_user = '<span class="user">'.$r_user.'</span>';
1197
        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1198
        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1199
1200
        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1201
        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1202
        $r_head_title.'</a></bdi>'.
1203
        $head_separator.$r_user.' '.$r_sum;
1204
    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1205
        $_info   = $changelog->getRevisionInfo($_rev);
1206
        if($_info['user']){
1207
            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1208
            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1209
        } else {
1210
            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1211
        }
1212
        $_user = '<span class="user">'.$_user.'</span>';
1213
        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1214
        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1215
1216
        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1217
        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1218
        $r_head_title.'</a></bdi> '.
1219
        '('.$lang['current'].')'.
1220
        $head_separator.$_user.' '.$_sum;
1221
    }else{
1222
        $r_head = '&mdash; ('.$lang['current'].')';
1223
    }
1224
1225
    return array($l_head, $r_head, $l_minor, $r_minor);
1226
}
1227
1228
/**
1229
 * Show diff
1230
 * between current page version and provided $text
1231
 * or between the revisions provided via GET or POST
1232
 *
1233
 * @author Andreas Gohr <[email protected]>
1234
 * @param  string $text  when non-empty: compare with this text with most current version
1235
 * @param  bool   $intro display the intro text
1236
 * @param  string $type  type of the diff (inline or sidebyside)
1237
 */
1238
function html_diff($text = '', $intro = true, $type = null) {
1239
    global $ID;
1240
    global $REV;
1241
    global $lang;
1242
    global $INPUT;
1243
    global $INFO;
1244
    $pagelog = new PageChangeLog($ID);
1245
1246
    /*
1247
     * Determine diff type
1248
     */
1249
    if(!$type) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $type of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1250
        $type = $INPUT->str('difftype');
1251
        if(empty($type)) {
1252
            $type = get_doku_pref('difftype', $type);
1253
            if(empty($type) && $INFO['ismobile']) {
1254
                $type = 'inline';
1255
            }
1256
        }
1257
    }
1258
    if($type != 'inline') $type = 'sidebyside';
1259
1260
    /*
1261
     * Determine requested revision(s)
1262
     */
1263
    // we're trying to be clever here, revisions to compare can be either
1264
    // given as rev and rev2 parameters, with rev2 being optional. Or in an
1265
    // array in rev2.
1266
    $rev1 = $REV;
1267
1268
    $rev2 = $INPUT->ref('rev2');
1269
    if(is_array($rev2)) {
1270
        $rev1 = (int) $rev2[0];
1271
        $rev2 = (int) $rev2[1];
1272
1273
        if(!$rev1) {
1274
            $rev1 = $rev2;
1275
            unset($rev2);
1276
        }
1277
    } else {
1278
        $rev2 = $INPUT->int('rev2');
1279
    }
1280
1281
    /*
1282
     * Determine left and right revision, its texts and the header
1283
     */
1284
    $r_minor = '';
1285
    $l_minor = '';
1286
1287
    if($text) { // compare text to the most current revision
1288
        $l_rev = '';
1289
        $l_text = rawWiki($ID, '');
1290
        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1291
            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
1292
            $lang['current'];
1293
1294
        $r_rev = '';
1295
        $r_text = cleanText($text);
1296
        $r_head = $lang['yours'];
1297
    } else {
1298
        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
1299
            // make sure order is correct (older on the left)
1300
            if($rev1 < $rev2) {
1301
                $l_rev = $rev1;
1302
                $r_rev = $rev2;
1303
            } else {
1304
                $l_rev = $rev2;
1305
                $r_rev = $rev1;
1306
            }
1307
        } elseif($rev1) { // single revision given, compare to current
1308
            $r_rev = '';
1309
            $l_rev = $rev1;
1310
        } else { // no revision was given, compare previous to current
1311
            $r_rev = '';
1312
            $revs = $pagelog->getRevisions(0, 1);
1313
            $l_rev = $revs[0];
1314
            $REV = $l_rev; // store revision back in $REV
1315
        }
1316
1317
        // when both revisions are empty then the page was created just now
1318
        if(!$l_rev && !$r_rev) {
1319
            $l_text = '';
1320
        } else {
1321
            $l_text = rawWiki($ID, $l_rev);
1322
        }
1323
        $r_text = rawWiki($ID, $r_rev);
1324
1325
        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1326
    }
1327
1328
    /*
1329
     * Build navigation
1330
     */
1331
    $l_nav = '';
1332
    $r_nav = '';
1333
    if(!$text) {
1334
        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1335
    }
1336
    /*
1337
     * Create diff object and the formatter
1338
     */
1339
    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
1340
1341
    if($type == 'inline') {
1342
        $diffformatter = new InlineDiffFormatter();
1343
    } else {
1344
        $diffformatter = new TableDiffFormatter();
1345
    }
1346
    /*
1347
     * Display intro
1348
     */
1349
    if($intro) print p_locale_xhtml('diff');
1350
1351
    /*
1352
     * Display type and exact reference
1353
     */
1354
    if(!$text) {
1355
        ptln('<div class="diffoptions group">');
1356
1357
1358
        $form = new Doku_Form(array('action' => wl()));
1359
        $form->addHidden('id', $ID);
1360
        $form->addHidden('rev2[0]', $l_rev);
1361
        $form->addHidden('rev2[1]', $r_rev);
1362
        $form->addHidden('do', 'diff');
1363
        $form->addElement(
1364
             form_makeListboxField(
1365
                 'difftype',
1366
                 array(
1367
                     'sidebyside' => $lang['diff_side'],
1368
                     'inline' => $lang['diff_inline']
1369
                 ),
1370
                 $type,
1371
                 $lang['diff_type'],
1372
                 '', '',
1373
                 array('class' => 'quickselect')
1374
             )
1375
        );
1376
        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1377
        $form->printForm();
1378
1379
        ptln('<p>');
1380
        // link to exactly this view FS#2835
1381
        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
1382
        ptln('</p>');
1383
1384
        ptln('</div>'); // .diffoptions
1385
    }
1386
1387
    /*
1388
     * Display diff view table
1389
     */
1390
    ?>
1391
    <div class="table">
1392
    <table class="diff diff_<?php echo $type ?>">
1393
1394
        <?php
1395
        //navigation and header
1396
        if($type == 'inline') {
1397
            if(!$text) { ?>
1398
                <tr>
1399
                    <td class="diff-lineheader">-</td>
1400
                    <td class="diffnav"><?php echo $l_nav ?></td>
1401
                </tr>
1402
                <tr>
1403
                    <th class="diff-lineheader">-</th>
1404
                    <th <?php echo $l_minor ?>>
1405
                        <?php echo $l_head ?>
1406
                    </th>
1407
                </tr>
1408
            <?php } ?>
1409
            <tr>
1410
                <td class="diff-lineheader">+</td>
1411
                <td class="diffnav"><?php echo $r_nav ?></td>
1412
            </tr>
1413
            <tr>
1414
                <th class="diff-lineheader">+</th>
1415
                <th <?php echo $r_minor ?>>
1416
                    <?php echo $r_head ?>
1417
                </th>
1418
            </tr>
1419
        <?php } else {
1420
            if(!$text) { ?>
1421
                <tr>
1422
                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1423
                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1424
                </tr>
1425
            <?php } ?>
1426
            <tr>
1427
                <th colspan="2" <?php echo $l_minor ?>>
1428
                    <?php echo $l_head ?>
1429
                </th>
1430
                <th colspan="2" <?php echo $r_minor ?>>
1431
                    <?php echo $r_head ?>
1432
                </th>
1433
            </tr>
1434
        <?php }
1435
1436
        //diff view
1437
        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1438
1439
    </table>
1440
    </div>
1441
<?php
1442
}
1443
1444
/**
1445
 * Create html for revision navigation
1446
 *
1447
 * @param PageChangeLog $pagelog changelog object of current page
1448
 * @param string        $type    inline vs sidebyside
1449
 * @param int           $l_rev   left revision timestamp
1450
 * @param int           $r_rev   right revision timestamp
1451
 * @return string[] html of left and right navigation elements
1452
 */
1453
function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1454
    global $INFO, $ID;
1455
1456
    // last timestamp is not in changelog, retrieve timestamp from metadata
1457
    // note: when page is removed, the metadata timestamp is zero
1458
    if(!$r_rev) {
1459
        if(isset($INFO['meta']['last_change']['date'])) {
1460
            $r_rev = $INFO['meta']['last_change']['date'];
1461
        } else {
1462
            $r_rev = 0;
1463
        }
1464
    }
1465
1466
    //retrieve revisions with additional info
1467
    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1468
    $l_revisions = array();
1469
    if(!$l_rev) {
1470
        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1471
    }
1472
    foreach($l_revs as $rev) {
1473
        $info = $pagelog->getRevisionInfo($rev);
1474
        $l_revisions[$rev] = array(
1475
            $rev,
1476
            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1477
            $r_rev ? $rev >= $r_rev : false //disable?
1478
        );
1479
    }
1480
    $r_revisions = array();
1481
    if(!$r_rev) {
1482
        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1483
    }
1484
    foreach($r_revs as $rev) {
1485
        $info = $pagelog->getRevisionInfo($rev);
1486
        $r_revisions[$rev] = array(
1487
            $rev,
1488
            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1489
            $rev <= $l_rev //disable?
1490
        );
1491
    }
1492
1493
    //determine previous/next revisions
1494
    $l_index = array_search($l_rev, $l_revs);
1495
    $l_prev = $l_revs[$l_index + 1];
1496
    $l_next = $l_revs[$l_index - 1];
1497
    if($r_rev) {
1498
        $r_index = array_search($r_rev, $r_revs);
1499
        $r_prev = $r_revs[$r_index + 1];
1500
        $r_next = $r_revs[$r_index - 1];
1501
    } else {
1502
        //removed page
1503
        if($l_next) {
1504
            $r_prev = $r_revs[0];
1505
        } else {
1506
            $r_prev = null;
1507
        }
1508
        $r_next = null;
1509
    }
1510
1511
    /*
1512
     * Left side:
1513
     */
1514
    $l_nav = '';
1515
    //move back
1516
    if($l_prev) {
1517
        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1518
        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1519
    }
1520
    //dropdown
1521
    $form = new Doku_Form(array('action' => wl()));
1522
    $form->addHidden('id', $ID);
1523
    $form->addHidden('difftype', $type);
1524
    $form->addHidden('rev2[1]', $r_rev);
1525
    $form->addHidden('do', 'diff');
1526
    $form->addElement(
1527
         form_makeListboxField(
1528
             'rev2[0]',
1529
             $l_revisions,
1530
             $l_rev,
1531
             '', '', '',
1532
             array('class' => 'quickselect')
1533
         )
1534
    );
1535
    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1536
    $l_nav .= $form->getForm();
1537
    //move forward
1538
    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1539
        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1540
    }
1541
1542
    /*
1543
     * Right side:
1544
     */
1545
    $r_nav = '';
1546
    //move back
1547
    if($l_rev < $r_prev) {
1548
        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1549
    }
1550
    //dropdown
1551
    $form = new Doku_Form(array('action' => wl()));
1552
    $form->addHidden('id', $ID);
1553
    $form->addHidden('rev2[0]', $l_rev);
1554
    $form->addHidden('difftype', $type);
1555
    $form->addHidden('do', 'diff');
1556
    $form->addElement(
1557
         form_makeListboxField(
1558
             'rev2[1]',
1559
             $r_revisions,
1560
             $r_rev,
1561
             '', '', '',
1562
             array('class' => 'quickselect')
1563
         )
1564
    );
1565
    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1566
    $r_nav .= $form->getForm();
1567
    //move forward
1568
    if($r_next) {
1569
        if($pagelog->isCurrentRevision($r_next)) {
1570
            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1571
        } else {
1572
            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1573
        }
1574
        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1575
    }
1576
    return array($l_nav, $r_nav);
1577
}
1578
1579
/**
1580
 * Create html link to a diff defined by two revisions
1581
 *
1582
 * @param string $difftype display type
1583
 * @param string $linktype
1584
 * @param int $lrev oldest revision
1585
 * @param int $rrev newest revision or null for diff with current revision
1586
 * @return string html of link to a diff
1587
 */
1588
function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
1589
    global $ID, $lang;
1590
    if(!$rrev) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $rrev of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1591
        $urlparam = array(
1592
            'do' => 'diff',
1593
            'rev' => $lrev,
1594
            'difftype' => $difftype,
1595
        );
1596
    } else {
1597
        $urlparam = array(
1598
            'do' => 'diff',
1599
            'rev2[0]' => $lrev,
1600
            'rev2[1]' => $rrev,
1601
            'difftype' => $difftype,
1602
        );
1603
    }
1604
    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1605
                '<span>' . $lang[$linktype] . '</span>' .
1606
            '</a>' . "\n";
1607
}
1608
1609
/**
1610
 * Insert soft breaks in diff html
1611
 *
1612
 * @param string $diffhtml
1613
 * @return string
1614
 */
1615
function html_insert_softbreaks($diffhtml) {
1616
    // search the diff html string for both:
1617
    // - html tags, so these can be ignored
1618
    // - long strings of characters without breaking characters
1619
    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1620
}
1621
1622
/**
1623
 * callback which adds softbreaks
1624
 *
1625
 * @param array $match array with first the complete match
1626
 * @return string the replacement
1627
 */
1628
function html_softbreak_callback($match){
1629
    // if match is an html tag, return it intact
1630
    if ($match[0]{0} == '<') return $match[0];
1631
1632
    // its a long string without a breaking character,
1633
    // make certain characters into breaking characters by inserting a
1634
    // breaking character (zero length space, U+200B / #8203) in front them.
1635
    $regex = <<< REGEX
1636
(?(?=                                 # start a conditional expression with a positive look ahead ...
1637
&\#?\\w{1,6};)                        # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1638
&\#?\\w{1,6};                         # yes pattern - a quicker match for the html entity, since we know we have one
1639
|
1640
[?/,&\#;:]                            # no pattern - any other group of 'special' characters to insert a breaking character after
1641
)+                                    # end conditional expression
1642
REGEX;
1643
1644
    return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1645
}
1646
1647
/**
1648
 * show warning on conflict detection
1649
 *
1650
 * @author Andreas Gohr <[email protected]>
1651
 *
1652
 * @param string $text
1653
 * @param string $summary
1654
 */
1655
function html_conflict($text,$summary){
1656
    global $ID;
1657
    global $lang;
1658
1659
    print p_locale_xhtml('conflict');
1660
    $form = new Doku_Form(array('id' => 'dw__editform'));
1661
    $form->addHidden('id', $ID);
1662
    $form->addHidden('wikitext', $text);
1663
    $form->addHidden('summary', $summary);
1664
    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1665
    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1666
    html_form('conflict', $form);
1667
    print '<br /><br /><br /><br />'.NL;
1668
}
1669
1670
/**
1671
 * Prints the global message array
1672
 *
1673
 * @author Andreas Gohr <[email protected]>
1674
 */
1675
function html_msgarea(){
1676
    global $MSG, $MSG_shown;
1677
    /** @var array $MSG */
1678
    // store if the global $MSG has already been shown and thus HTML output has been started
1679
    $MSG_shown = true;
1680
1681
    if(!isset($MSG)) return;
1682
1683
    $shown = array();
1684
    foreach($MSG as $msg){
1685
        $hash = md5($msg['msg']);
1686
        if(isset($shown[$hash])) continue; // skip double messages
1687
        if(info_msg_allowed($msg)){
1688
            print '<div class="'.$msg['lvl'].'">';
1689
            print $msg['msg'];
1690
            print '</div>';
1691
        }
1692
        $shown[$hash] = 1;
1693
    }
1694
1695
    unset($GLOBALS['MSG']);
1696
}
1697
1698
/**
1699
 * Prints the registration form
1700
 *
1701
 * @author Andreas Gohr <[email protected]>
1702
 */
1703
function html_register(){
1704
    global $lang;
1705
    global $conf;
1706
    global $INPUT;
1707
1708
    $base_attrs = array('size'=>50,'required'=>'required');
1709
    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1710
1711
    print p_locale_xhtml('register');
1712
    print '<div class="centeralign">'.NL;
1713
    $form = new Doku_Form(array('id' => 'dw__register'));
1714
    $form->startFieldset($lang['btn_register']);
1715
    $form->addHidden('do', 'register');
1716
    $form->addHidden('save', '1');
1717
    $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1718
    if (!$conf['autopasswd']) {
1719
        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1720
        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1721
    }
1722
    $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1723
    $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1724
    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1725
    $form->endFieldset();
1726
    html_form('register', $form);
1727
1728
    print '</div>'.NL;
1729
}
1730
1731
/**
1732
 * Print the update profile form
1733
 *
1734
 * @author Christopher Smith <[email protected]>
1735
 * @author Andreas Gohr <[email protected]>
1736
 */
1737
function html_updateprofile(){
1738
    global $lang;
1739
    global $conf;
1740
    global $INPUT;
1741
    global $INFO;
1742
    /** @var DokuWiki_Auth_Plugin $auth */
1743
    global $auth;
1744
1745
    print p_locale_xhtml('updateprofile');
1746
    print '<div class="centeralign">'.NL;
1747
1748
    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1749
    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1750
    $form = new Doku_Form(array('id' => 'dw__register'));
1751
    $form->startFieldset($lang['profile']);
1752
    $form->addHidden('do', 'profile');
1753
    $form->addHidden('save', '1');
1754
    $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1755
    $attr = array('size'=>'50');
1756
    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1757
    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1758
    $attr = array('size'=>'50', 'class'=>'edit');
1759
    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1760
    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1761
    $form->addElement(form_makeTag('br'));
1762
    if ($auth->canDo('modPass')) {
1763
        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1764
        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1765
    }
1766
    if ($conf['profileconfirm']) {
1767
        $form->addElement(form_makeTag('br'));
1768
        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1769
    }
1770
    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1771
    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1772
1773
    $form->endFieldset();
1774
    html_form('updateprofile', $form);
1775
1776
    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1777
        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1778
        $form_profiledelete->startFieldset($lang['profdeleteuser']);
1779
        $form_profiledelete->addHidden('do', 'profile_delete');
1780
        $form_profiledelete->addHidden('delete', '1');
1781
        $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1782
        if ($conf['profileconfirm']) {
1783
            $form_profiledelete->addElement(form_makeTag('br'));
1784
            $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1785
        }
1786
        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1787
        $form_profiledelete->endFieldset();
1788
1789
        html_form('profiledelete', $form_profiledelete);
1790
    }
1791
1792
    print '</div>'.NL;
1793
}
1794
1795
/**
1796
 * Preprocess edit form data
1797
 *
1798
 * @author   Andreas Gohr <[email protected]>
1799
 *
1800
 * @triggers HTML_EDITFORM_OUTPUT
1801
 */
1802
function html_edit(){
1803
    global $INPUT;
1804
    global $ID;
1805
    global $REV;
1806
    global $DATE;
1807
    global $PRE;
1808
    global $SUF;
1809
    global $INFO;
1810
    global $SUM;
1811
    global $lang;
1812
    global $conf;
1813
    global $TEXT;
1814
1815
    if ($INPUT->has('changecheck')) {
1816
        $check = $INPUT->str('changecheck');
1817
    } elseif(!$INFO['exists']){
1818
        // $TEXT has been loaded from page template
1819
        $check = md5('');
1820
    } else {
1821
        $check = md5($TEXT);
1822
    }
1823
    $mod = md5($TEXT) !== $check;
1824
1825
    $wr = $INFO['writable'] && !$INFO['locked'];
1826
    $include = 'edit';
1827
    if($wr){
1828
        if ($REV) $include = 'editrev';
1829
    }else{
1830
        // check pseudo action 'source'
1831
        if(!actionOK('source')){
1832
            msg('Command disabled: source',-1);
1833
            return;
1834
        }
1835
        $include = 'read';
1836
    }
1837
1838
    global $license;
1839
1840
    $form = new Doku_Form(array('id' => 'dw__editform'));
1841
    $form->addHidden('id', $ID);
1842
    $form->addHidden('rev', $REV);
1843
    $form->addHidden('date', $DATE);
1844
    $form->addHidden('prefix', $PRE . '.');
1845
    $form->addHidden('suffix', $SUF);
1846
    $form->addHidden('changecheck', $check);
1847
1848
    $data = array('form' => $form,
1849
                  'wr'   => $wr,
1850
                  'media_manager' => true,
1851
                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1852
                  'intro_locale' => $include);
1853
1854
    if ($data['target'] !== 'section') {
1855
        // Only emit event if page is writable, section edit data is valid and
1856
        // edit target is not section.
1857
        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1858
    } else {
1859
        html_edit_form($data);
1860
    }
1861
    if (isset($data['intro_locale'])) {
1862
        echo p_locale_xhtml($data['intro_locale']);
1863
    }
1864
1865
    $form->addHidden('target', $data['target']);
1866
    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1867
    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1868
    $form->addElement(form_makeCloseTag('div'));
1869
    if ($wr) {
1870
        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1871
        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1872
        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1873
        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1874
        $form->addElement(form_makeCloseTag('div'));
1875
        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1876
        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1877
        $elem = html_minoredit();
1878
        if ($elem) $form->addElement($elem);
1879
        $form->addElement(form_makeCloseTag('div'));
1880
    }
1881
    $form->addElement(form_makeCloseTag('div'));
1882
    if($wr && $conf['license']){
1883
        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1884
        $out  = $lang['licenseok'];
1885
        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1886
        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1887
        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1888
        $form->addElement($out);
1889
        $form->addElement(form_makeCloseTag('div'));
1890
    }
1891
1892
    if ($wr) {
1893
        // sets changed to true when previewed
1894
        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1895
        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1896
        echo '/*!]]>*/</script>' . NL;
1897
    } ?>
1898
    <div class="editBox" role="application">
1899
1900
    <div class="toolbar group">
1901
        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1902
        <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1903
            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1904
    </div>
1905
    <?php
1906
1907
    html_form('edit', $form);
1908
    print '</div>'.NL;
1909
}
1910
1911
/**
1912
 * Display the default edit form
1913
 *
1914
 * Is the default action for HTML_EDIT_FORMSELECTION.
1915
 *
1916
 * @param mixed[] $param
1917
 */
1918
function html_edit_form($param) {
1919
    global $TEXT;
1920
1921
    if ($param['target'] !== 'section') {
1922
        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1923
    }
1924
1925
    $attr = array('tabindex'=>'1');
1926
    if (!$param['wr']) $attr['readonly'] = 'readonly';
1927
1928
    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1929
}
1930
1931
/**
1932
 * Adds a checkbox for minor edits for logged in users
1933
 *
1934
 * @author Andreas Gohr <[email protected]>
1935
 *
1936
 * @return array|bool
1937
 */
1938
function html_minoredit(){
1939
    global $conf;
1940
    global $lang;
1941
    global $INPUT;
1942
    // minor edits are for logged in users only
1943
    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1944
        return false;
1945
    }
1946
1947
    $p = array();
1948
    $p['tabindex'] = 3;
1949
    if($INPUT->bool('minor')) $p['checked']='checked';
1950
    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1951
}
1952
1953
/**
1954
 * prints some debug info
1955
 *
1956
 * @author Andreas Gohr <[email protected]>
1957
 */
1958
function html_debug(){
1959
    global $conf;
1960
    global $lang;
1961
    /** @var DokuWiki_Auth_Plugin $auth */
1962
    global $auth;
1963
    global $INFO;
1964
1965
    //remove sensitive data
1966
    $cnf = $conf;
1967
    debug_guard($cnf);
1968
    $nfo = $INFO;
1969
    debug_guard($nfo);
1970
    $ses = $_SESSION;
1971
    debug_guard($ses);
1972
1973
    print '<html><body>';
1974
1975
    print '<p>When reporting bugs please send all the following ';
1976
    print 'output as a mail to [email protected] ';
1977
    print 'The best way to do this is to save this page in your browser</p>';
1978
1979
    print '<b>$INFO:</b><pre>';
1980
    print_r($nfo);
1981
    print '</pre>';
1982
1983
    print '<b>$_SERVER:</b><pre>';
1984
    print_r($_SERVER);
1985
    print '</pre>';
1986
1987
    print '<b>$conf:</b><pre>';
1988
    print_r($cnf);
1989
    print '</pre>';
1990
1991
    print '<b>DOKU_BASE:</b><pre>';
1992
    print DOKU_BASE;
1993
    print '</pre>';
1994
1995
    print '<b>abs DOKU_BASE:</b><pre>';
1996
    print DOKU_URL;
1997
    print '</pre>';
1998
1999
    print '<b>rel DOKU_BASE:</b><pre>';
2000
    print dirname($_SERVER['PHP_SELF']).'/';
2001
    print '</pre>';
2002
2003
    print '<b>PHP Version:</b><pre>';
2004
    print phpversion();
2005
    print '</pre>';
2006
2007
    print '<b>locale:</b><pre>';
2008
    print setlocale(LC_ALL,0);
2009
    print '</pre>';
2010
2011
    print '<b>encoding:</b><pre>';
2012
    print $lang['encoding'];
2013
    print '</pre>';
2014
2015
    if($auth){
2016
        print '<b>Auth backend capabilities:</b><pre>';
2017
        foreach ($auth->getCapabilities() as $cando){
2018
            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
2019
        }
2020
        print '</pre>';
2021
    }
2022
2023
    print '<b>$_SESSION:</b><pre>';
2024
    print_r($ses);
2025
    print '</pre>';
2026
2027
    print '<b>Environment:</b><pre>';
2028
    print_r($_ENV);
2029
    print '</pre>';
2030
2031
    print '<b>PHP settings:</b><pre>';
2032
    $inis = ini_get_all();
2033
    print_r($inis);
2034
    print '</pre>';
2035
2036
    if (function_exists('apache_get_version')) {
2037
        $apache = array();
2038
        $apache['version'] = apache_get_version();
2039
2040
        if (function_exists('apache_get_modules')) {
2041
            $apache['modules'] = apache_get_modules();
2042
        }
2043
        print '<b>Apache</b><pre>';
2044
        print_r($apache);
2045
        print '</pre>';
2046
    }
2047
2048
    print '</body></html>';
2049
}
2050
2051
/**
2052
 * List available Administration Tasks
2053
 *
2054
 * @author Andreas Gohr <[email protected]>
2055
 * @author Håkan Sandell <[email protected]>
2056
 */
2057
function html_admin(){
2058
    global $ID;
2059
    global $INFO;
2060
    global $conf;
2061
    /** @var DokuWiki_Auth_Plugin $auth */
2062
    global $auth;
2063
2064
    // build menu of admin functions from the plugins that handle them
2065
    $pluginlist = plugin_list('admin');
2066
    $menu = array();
2067
    foreach ($pluginlist as $p) {
2068
        /** @var DokuWiki_Admin_Plugin $obj */
2069
        if(($obj = plugin_load('admin',$p)) === null) continue;
2070
2071
        // check permissions
2072
        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
2073
2074
        $menu[$p] = array('plugin' => $p,
2075
                'prompt' => $obj->getMenuText($conf['lang']),
2076
                'sort' => $obj->getMenuSort()
2077
                );
2078
    }
2079
2080
    // data security check
2081
    // simple check if the 'savedir' is relative and accessible when appended to DOKU_URL
2082
    // it verifies either:
2083
    //   'savedir' has been moved elsewhere, or
2084
    //   has protection to prevent the webserver serving files from it
2085
    if (substr($conf['savedir'],0,2) == './'){
2086
        echo '<a style="border:none; float:right;"
2087
                href="http://www.dokuwiki.org/security#web_access_security">
2088
                <img src="'.DOKU_URL.$conf['savedir'].'/security.png" alt="Your data directory seems to be protected properly."
2089
                onerror="this.parentNode.style.display=\'none\'" /></a>';
2090
    }
2091
2092
    print p_locale_xhtml('admin');
2093
2094
    // Admin Tasks
2095
    if($INFO['isadmin']){
2096
        ptln('<ul class="admin_tasks">');
2097
2098
        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
2099
            ptln('  <li class="admin_usermanager"><div class="li">'.
2100
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
2101
                    $menu['usermanager']['prompt'].'</a></div></li>');
2102
        }
2103
        unset($menu['usermanager']);
2104
2105
        if($menu['acl']){
2106
            ptln('  <li class="admin_acl"><div class="li">'.
2107
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
2108
                    $menu['acl']['prompt'].'</a></div></li>');
2109
        }
2110
        unset($menu['acl']);
2111
2112
        if($menu['extension']){
2113
            ptln('  <li class="admin_plugin"><div class="li">'.
2114
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'extension')).'">'.
2115
                    $menu['extension']['prompt'].'</a></div></li>');
2116
        }
2117
        unset($menu['extension']);
2118
2119
        if($menu['config']){
2120
            ptln('  <li class="admin_config"><div class="li">'.
2121
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
2122
                    $menu['config']['prompt'].'</a></div></li>');
2123
        }
2124
        unset($menu['config']);
2125
2126
        if($menu['styling']){
2127
            ptln('  <li class="admin_styling"><div class="li">'.
2128
                '<a href="'.wl($ID, array('do' => 'admin','page' => 'styling')).'">'.
2129
                $menu['styling']['prompt'].'</a></div></li>');
2130
        }
2131
        unset($menu['styling']);
2132
    }
2133
    ptln('</ul>');
2134
2135
    // Manager Tasks
2136
    ptln('<ul class="admin_tasks">');
2137
2138
    if($menu['revert']){
2139
        ptln('  <li class="admin_revert"><div class="li">'.
2140
                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
2141
                $menu['revert']['prompt'].'</a></div></li>');
2142
    }
2143
    unset($menu['revert']);
2144
2145
    if($menu['popularity']){
2146
        ptln('  <li class="admin_popularity"><div class="li">'.
2147
                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
2148
                $menu['popularity']['prompt'].'</a></div></li>');
2149
    }
2150
    unset($menu['popularity']);
2151
2152
    // print DokuWiki version:
2153
    ptln('</ul>');
2154
    echo '<div id="admin__version">';
2155
    echo getVersion();
2156
    echo '</div>';
2157
2158
    // print the rest as sorted list
2159
    if(count($menu)){
2160
        // sort by name, then sort
2161
        usort(
2162
            $menu,
2163
            function ($a, $b) {
2164
                $strcmp = strcasecmp($a['prompt'], $b['prompt']);
2165
                if($strcmp != 0) return $strcmp;
2166
                if($a['sort'] == $b['sort']) return 0;
2167
                return ($a['sort'] < $b['sort']) ? -1 : 1;
2168
            }
2169
        );
2170
2171
        // output the menu
2172
        ptln('<div class="clearer"></div>');
2173
        print p_locale_xhtml('adminplugins');
2174
        ptln('<ul>');
2175
        foreach ($menu as $item) {
2176
            if (!$item['prompt']) continue;
2177
            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
2178
        }
2179
        ptln('</ul>');
2180
    }
2181
}
2182
2183
/**
2184
 * Form to request a new password for an existing account
2185
 *
2186
 * @author Benoit Chesneau <[email protected]>
2187
 * @author Andreas Gohr <[email protected]>
2188
 */
2189
function html_resendpwd() {
2190
    global $lang;
2191
    global $conf;
2192
    global $INPUT;
2193
2194
    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2195
2196
    if(!$conf['autopasswd'] && $token){
2197
        print p_locale_xhtml('resetpwd');
2198
        print '<div class="centeralign">'.NL;
2199
        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2200
        $form->startFieldset($lang['btn_resendpwd']);
2201
        $form->addHidden('token', $token);
2202
        $form->addHidden('do', 'resendpwd');
2203
2204
        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2205
        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2206
2207
        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2208
        $form->endFieldset();
2209
        html_form('resendpwd', $form);
2210
        print '</div>'.NL;
2211
    }else{
2212
        print p_locale_xhtml('resendpwd');
2213
        print '<div class="centeralign">'.NL;
2214
        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2215
        $form->startFieldset($lang['resendpwd']);
2216
        $form->addHidden('do', 'resendpwd');
2217
        $form->addHidden('save', '1');
2218
        $form->addElement(form_makeTag('br'));
2219
        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2220
        $form->addElement(form_makeTag('br'));
2221
        $form->addElement(form_makeTag('br'));
2222
        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2223
        $form->endFieldset();
2224
        html_form('resendpwd', $form);
2225
        print '</div>'.NL;
2226
    }
2227
}
2228
2229
/**
2230
 * Return the TOC rendered to XHTML
2231
 *
2232
 * @author Andreas Gohr <[email protected]>
2233
 *
2234
 * @param array $toc
2235
 * @return string html
2236
 */
2237
function html_TOC($toc){
2238
    if(!count($toc)) return '';
2239
    global $lang;
2240
    $out  = '<!-- TOC START -->'.DOKU_LF;
2241
    $out .= '<div id="dw__toc">'.DOKU_LF;
2242
    $out .= '<h3 class="toggle">';
2243
    $out .= $lang['toc'];
2244
    $out .= '</h3>'.DOKU_LF;
2245
    $out .= '<div>'.DOKU_LF;
2246
    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2247
    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2248
    $out .= '<!-- TOC END -->'.DOKU_LF;
2249
    return $out;
2250
}
2251
2252
/**
2253
 * Callback for html_buildlist
2254
 *
2255
 * @param array $item
2256
 * @return string html
2257
 */
2258
function html_list_toc($item){
2259
    if(isset($item['hid'])){
2260
        $link = '#'.$item['hid'];
2261
    }else{
2262
        $link = $item['link'];
2263
    }
2264
2265
    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2266
}
2267
2268
/**
2269
 * Helper function to build TOC items
2270
 *
2271
 * Returns an array ready to be added to a TOC array
2272
 *
2273
 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2274
 * @param string $text  - what to display in the TOC
2275
 * @param int    $level - nesting level
2276
 * @param string $hash  - is prepended to the given $link, set blank if you want full links
2277
 * @return array the toc item
2278
 */
2279
function html_mktocitem($link, $text, $level, $hash='#'){
2280
    return  array( 'link'  => $hash.$link,
2281
            'title' => $text,
2282
            'type'  => 'ul',
2283
            'level' => $level);
2284
}
2285
2286
/**
2287
 * Output a Doku_Form object.
2288
 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2289
 *
2290
 * @author Tom N Harris <[email protected]>
2291
 *
2292
 * @param string     $name The name of the form
2293
 * @param Doku_Form  $form The form
2294
 */
2295
function html_form($name, &$form) {
2296
    // Safety check in case the caller forgets.
2297
    $form->endFieldset();
2298
    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2299
}
2300
2301
/**
2302
 * Form print function.
2303
 * Just calls printForm() on the data object.
2304
 *
2305
 * @param Doku_Form $data The form
2306
 */
2307
function html_form_output($data) {
2308
    $data->printForm();
2309
}
2310
2311
/**
2312
 * Embed a flash object in HTML
2313
 *
2314
 * This will create the needed HTML to embed a flash movie in a cross browser
2315
 * compatble way using valid XHTML
2316
 *
2317
 * The parameters $params, $flashvars and $atts need to be associative arrays.
2318
 * No escaping needs to be done for them. The alternative content *has* to be
2319
 * escaped because it is used as is. If no alternative content is given
2320
 * $lang['noflash'] is used.
2321
 *
2322
 * @author Andreas Gohr <[email protected]>
2323
 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
2324
 *
2325
 * @param string $swf      - the SWF movie to embed
2326
 * @param int $width       - width of the flash movie in pixels
2327
 * @param int $height      - height of the flash movie in pixels
2328
 * @param array $params    - additional parameters (<param>)
2329
 * @param array $flashvars - parameters to be passed in the flashvar parameter
2330
 * @param array $atts      - additional attributes for the <object> tag
2331
 * @param string $alt      - alternative content (is NOT automatically escaped!)
2332
 * @return string         - the XHTML markup
2333
 */
2334
function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
2335
    global $lang;
2336
2337
    $out = '';
2338
2339
    // prepare the object attributes
2340
    if(is_null($atts)) $atts = array();
2341
    $atts['width']  = (int) $width;
2342
    $atts['height'] = (int) $height;
2343
    if(!$atts['width'])  $atts['width']  = 425;
2344
    if(!$atts['height']) $atts['height'] = 350;
2345
2346
    // add object attributes for standard compliant browsers
2347
    $std = $atts;
2348
    $std['type'] = 'application/x-shockwave-flash';
2349
    $std['data'] = $swf;
2350
2351
    // add object attributes for IE
2352
    $ie  = $atts;
2353
    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
2354
2355
    // open object (with conditional comments)
2356
    $out .= '<!--[if !IE]> -->'.NL;
2357
    $out .= '<object '.buildAttributes($std).'>'.NL;
2358
    $out .= '<!-- <![endif]-->'.NL;
2359
    $out .= '<!--[if IE]>'.NL;
2360
    $out .= '<object '.buildAttributes($ie).'>'.NL;
2361
    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
2362
    $out .= '<!--><!-- -->'.NL;
2363
2364
    // print params
2365
    if(is_array($params)) foreach($params as $key => $val){
2366
        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
2367
    }
2368
2369
    // add flashvars
2370
    if(is_array($flashvars)){
2371
        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
2372
    }
2373
2374
    // alternative content
2375
    if($alt){
2376
        $out .= $alt.NL;
2377
    }else{
2378
        $out .= $lang['noflash'].NL;
2379
    }
2380
2381
    // finish
2382
    $out .= '</object>'.NL;
2383
    $out .= '<!-- <![endif]-->'.NL;
2384
2385
    return $out;
2386
}
2387
2388
/**
2389
 * Prints HTML code for the given tab structure
2390
 *
2391
 * @param array  $tabs        tab structure
2392
 * @param string $current_tab the current tab id
2393
 */
2394
function html_tabs($tabs, $current_tab = null) {
2395
    echo '<ul class="tabs">'.NL;
2396
2397
    foreach($tabs as $id => $tab) {
2398
        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
2399
    }
2400
2401
    echo '</ul>'.NL;
2402
}
2403
2404
/**
2405
 * Prints a single tab
2406
 *
2407
 * @author Kate Arzamastseva <[email protected]>
2408
 * @author Adrian Lang <[email protected]>
2409
 *
2410
 * @param string $href - tab href
2411
 * @param string $caption - tab caption
2412
 * @param boolean $selected - is tab selected
2413
 */
2414
2415
function html_tab($href, $caption, $selected=false) {
2416
    $tab = '<li>';
2417
    if ($selected) {
2418
        $tab .= '<strong>';
2419
    } else {
2420
        $tab .= '<a href="' . hsc($href) . '">';
2421
    }
2422
    $tab .= hsc($caption)
2423
         .  '</' . ($selected ? 'strong' : 'a') . '>'
2424
         .  '</li>'.NL;
2425
    echo $tab;
2426
}
2427
2428
/**
2429
 * Display size change
2430
 *
2431
 * @param int $sizechange - size of change in Bytes
2432
 * @param Doku_Form $form - form to add elements to
2433
 */
2434
2435
function html_sizechange($sizechange, Doku_Form $form) {
2436
    if(isset($sizechange)) {
2437
        $class = 'sizechange';
2438
        $value = filesize_h(abs($sizechange));
2439
        if($sizechange > 0) {
2440
            $class .= ' positive';
2441
            $value = '+' . $value;
2442
        } elseif($sizechange < 0) {
2443
            $class .= ' negative';
2444
            $value = '-' . $value;
2445
        } else {
2446
            $value = '±' . $value;
2447
        }
2448
        $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2449
        $form->addElement($value);
2450
        $form->addElement(form_makeCloseTag('span'));
2451
    }
2452
}
2453