xref: /dokuwiki/inc/html.php (revision 82f2bcd02b36f7edfa9f6a3db97adc7bc2eab1b7)
1<?php
2/**
3 * HTML output functions
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9if(!defined('DOKU_INC')) die('meh.');
10if(!defined('NL')) define('NL',"\n");
11
12/**
13 * Convenience function to quickly build a wikilink
14 *
15 * @author Andreas Gohr <andi@splitbrain.org>
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 */
21function 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 <andi@splitbrain.org>
35 */
36function 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 */
74function html_denied() {
75    print p_locale_xhtml('denied');
76
77    if(!$_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 <andi@splitbrain.org>
86 */
87function html_secedit($text,$show=true){
88    global $INFO;
89
90    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
91
92    if(!$INFO['writable'] || !$show || $INFO['rev']){
93        return preg_replace($regexp,'',$text);
94    }
95
96    return preg_replace_callback($regexp,
97                'html_secedit_button', $text);
98}
99
100/**
101 * prepares section edit button data for event triggering
102 * used as a callback in html_secedit
103 *
104 * @triggers HTML_SECEDIT_BUTTON
105 * @author Andreas Gohr <andi@splitbrain.org>
106 */
107function html_secedit_button($matches){
108    $data = array('secid'  => $matches[1],
109                  'target' => strtolower($matches[2]),
110                  'range'  => $matches[count($matches) - 1]);
111    if (count($matches) === 5) {
112        $data['name'] = $matches[3];
113    }
114
115    return trigger_event('HTML_SECEDIT_BUTTON', $data,
116                         'html_secedit_get_button');
117}
118
119/**
120 * prints a section editing button
121 * used as default action form HTML_SECEDIT_BUTTON
122 *
123 * @author Adrian Lang <lang@cosmocode.de>
124 */
125function html_secedit_get_button($data) {
126    global $ID;
127    global $INFO;
128
129    if (!isset($data['name']) || $data['name'] === '') return '';
130
131    $name = $data['name'];
132    unset($data['name']);
133
134    $secid = $data['secid'];
135    unset($data['secid']);
136
137    return "<div class='secedit editbutton_" . $data['target'] .
138                       " editbutton_" . $secid . "'>" .
139           html_btn('secedit', $ID, '',
140                    array_merge(array('do'  => 'edit',
141                                      'rev' => $INFO['lastmod'],
142                                      'summary' => '['.$name.'] '), $data),
143                    'post', $name) . '</div>';
144}
145
146/**
147 * Just the back to top button (in its own form)
148 *
149 * @author Andreas Gohr <andi@splitbrain.org>
150 */
151function html_topbtn(){
152    global $lang;
153
154    $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>';
155
156    return $ret;
157}
158
159/**
160 * Displays a button (using its own form)
161 * If tooltip exists, the access key tooltip is replaced.
162 *
163 * @author Andreas Gohr <andi@splitbrain.org>
164 */
165function html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){
166    global $conf;
167    global $lang;
168
169    if (!$label)
170        $label = $lang['btn_'.$name];
171
172    $ret = '';
173
174    //filter id (without urlencoding)
175    $id = idfilter($id,false);
176
177    //make nice URLs even for buttons
178    if($conf['userewrite'] == 2){
179        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
180    }elseif($conf['userewrite']){
181        $script = DOKU_BASE.$id;
182    }else{
183        $script = DOKU_BASE.DOKU_SCRIPT;
184        $params['id'] = $id;
185    }
186
187    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
188
189    if(is_array($params)){
190        reset($params);
191        while (list($key, $val) = each($params)) {
192            $ret .= '<input type="hidden" name="'.$key.'" ';
193            $ret .= 'value="'.htmlspecialchars($val).'" />';
194        }
195    }
196
197    if ($tooltip!='') {
198        $tip = htmlspecialchars($tooltip);
199    }else{
200        $tip = htmlspecialchars($label);
201    }
202
203    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
204    if($akey){
205        $tip .= ' ['.strtoupper($akey).']';
206        $ret .= 'accesskey="'.$akey.'" ';
207    }
208    $ret .= 'title="'.$tip.'" ';
209    $ret .= '/>';
210    $ret .= '</div></form>';
211
212    return $ret;
213}
214
215/**
216 * show a wiki page
217 *
218 * @author Andreas Gohr <andi@splitbrain.org>
219 */
220function html_show($txt=null){
221    global $ID;
222    global $REV;
223    global $HIGH;
224    global $INFO;
225    //disable section editing for old revisions or in preview
226    if($txt || $REV){
227        $secedit = false;
228    }else{
229        $secedit = true;
230    }
231
232    if (!is_null($txt)){
233        //PreviewHeader
234        echo '<br id="scroll__here" />';
235        echo p_locale_xhtml('preview');
236        echo '<div class="preview"><div class="pad">';
237        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
238        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
239        echo $html;
240        echo '<div class="clearer"></div>';
241        echo '</div></div>';
242
243    }else{
244        if ($REV) print p_locale_xhtml('showrev');
245        $html = p_wiki_xhtml($ID,$REV,true);
246        $html = html_secedit($html,$secedit);
247        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
248        $html = html_hilight($html,$HIGH);
249        echo $html;
250    }
251}
252
253/**
254 * ask the user about how to handle an exisiting draft
255 *
256 * @author Andreas Gohr <andi@splitbrain.org>
257 */
258function html_draft(){
259    global $INFO;
260    global $ID;
261    global $lang;
262    $draft = unserialize(io_readFile($INFO['draft'],false));
263    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
264
265    print p_locale_xhtml('draft');
266    $form = new Doku_Form(array('id' => 'dw__editform'));
267    $form->addHidden('id', $ID);
268    $form->addHidden('date', $draft['date']);
269    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
270    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
271    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
272    $form->addElement(form_makeCloseTag('div'));
273    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
274    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
275    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
276    html_form('draft', $form);
277}
278
279/**
280 * Highlights searchqueries in HTML code
281 *
282 * @author Andreas Gohr <andi@splitbrain.org>
283 * @author Harry Fuecks <hfuecks@gmail.com>
284 */
285function html_hilight($html,$phrases){
286    $phrases = (array) $phrases;
287    $phrases = array_map('preg_quote_cb', $phrases);
288    $phrases = array_map('ft_snippet_re_preprocess', $phrases);
289    $phrases = array_filter($phrases);
290    $regex = join('|',$phrases);
291
292    if ($regex === '') return $html;
293    if (!utf8_check($regex)) return $html;
294    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
295    return $html;
296}
297
298/**
299 * Callback used by html_hilight()
300 *
301 * @author Harry Fuecks <hfuecks@gmail.com>
302 */
303function html_hilight_callback($m) {
304    $hlight = unslash($m[0]);
305    if ( !isset($m[2])) {
306        $hlight = '<span class="search_hit">'.$hlight.'</span>';
307    }
308    return $hlight;
309}
310
311/**
312 * Run a search and display the result
313 *
314 * @author Andreas Gohr <andi@splitbrain.org>
315 */
316function html_search(){
317    global $QUERY, $ID;
318    global $lang;
319
320    $intro = p_locale_xhtml('searchpage');
321    // allow use of placeholder in search intro
322    $pagecreateinfo = (auth_quickaclcheck($ID) >= AUTH_CREATE) ? $lang['searchcreatepage'] : '';
323    $intro = str_replace(
324        array('@QUERY@', '@SEARCH@', '@CREATEPAGEINFO@'),
325        array(hsc(rawurlencode($QUERY)), hsc($QUERY), $pagecreateinfo),
326        $intro
327    );
328    echo $intro;
329    flush();
330
331    //show progressbar
332    print '<div id="dw__loading">'.NL;
333    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
334    print 'showLoadBar();'.NL;
335    print '/*!]]>*/</script>'.NL;
336    print '</div>'.NL;
337    flush();
338
339    //do quick pagesearch
340    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
341    if(count($data)){
342        print '<div class="search_quickresult">';
343        print '<h3>'.$lang['quickhits'].':</h3>';
344        print '<ul class="search_quickhits">';
345        foreach($data as $id => $title){
346            print '<li> ';
347            if (useHeading('navigation')) {
348                $name = $title;
349            }else{
350                $ns = getNS($id);
351                if($ns){
352                    $name = shorten(noNS($id), ' ('.$ns.')',30);
353                }else{
354                    $name = $id;
355                }
356            }
357            print html_wikilink(':'.$id,$name);
358            print '</li> ';
359        }
360        print '</ul> ';
361        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
362        print '<div class="clearer"></div>';
363        print '</div>';
364    }
365    flush();
366
367    //do fulltext search
368    $data = ft_pageSearch($QUERY,$regex);
369    if(count($data)){
370        print '<dl class="search_results">';
371        $num = 1;
372        foreach($data as $id => $cnt){
373            print '<dt>';
374            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
375            if($cnt !== 0){
376                print ': '.$cnt.' '.$lang['hits'].'';
377            }
378            print '</dt>';
379            if($cnt !== 0){
380                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
381                    print '<dd>'.ft_snippet($id,$regex).'</dd>';
382                }
383                $num++;
384            }
385            flush();
386        }
387        print '</dl>';
388    }else{
389        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
390    }
391
392    //hide progressbar
393    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
394    print 'hideLoadBar("dw__loading");'.NL;
395    print '/*!]]>*/</script>'.NL;
396    flush();
397}
398
399/**
400 * Display error on locked pages
401 *
402 * @author Andreas Gohr <andi@splitbrain.org>
403 */
404function html_locked(){
405    global $ID;
406    global $conf;
407    global $lang;
408    global $INFO;
409
410    $locktime = filemtime(wikiLockFN($ID));
411    $expire = dformat($locktime + $conf['locktime']);
412    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
413
414    print p_locale_xhtml('locked');
415    print '<ul>';
416    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
417    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
418    print '</ul>';
419}
420
421/**
422 * list old revisions
423 *
424 * @author Andreas Gohr <andi@splitbrain.org>
425 * @author Ben Coburn <btcoburn@silicodon.net>
426 * @author Kate Arzamastseva <pshns@ukr.net>
427 */
428function html_revisions($first=0, $media_id = false){
429    global $ID;
430    global $INFO;
431    global $conf;
432    global $lang;
433    $id = $ID;
434    if ($media_id) {
435        $id = $media_id;
436        $changelog = new MediaChangeLog($id);
437    } else {
438        $changelog = new PageChangeLog($id);
439    }
440
441    /* we need to get one additional log entry to be able to
442     * decide if this is the last page or is there another one.
443     * see html_recent()
444     */
445
446    $revisions = $changelog->getRevisions($first, $conf['recent']+1);
447
448    if(count($revisions)==0 && $first!=0){
449        $first=0;
450        $revisions = $changelog->getRevisions($first, $conf['recent']+1);
451    }
452    $hasNext = false;
453    if (count($revisions)>$conf['recent']) {
454        $hasNext = true;
455        array_pop($revisions); // remove extra log entry
456    }
457
458    if (!$media_id) $date = dformat($INFO['lastmod']);
459    else $date = dformat(@filemtime(mediaFN($id)));
460
461    if (!$media_id) print p_locale_xhtml('revisions');
462
463    $params = array('id' => 'page__revisions', 'class' => 'changes');
464    if ($media_id) $params['action'] = media_managerURL(array('image' => $media_id), '&');
465
466    $form = new Doku_Form($params);
467    $form->addElement(form_makeOpenTag('ul'));
468
469    if (!$media_id) $exists = $INFO['exists'];
470    else $exists = @file_exists(mediaFN($id));
471
472    $display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id;
473    if (!$display_name) $display_name = $id;
474
475    if($exists && $first==0){
476        if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
477            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
478        else
479            $form->addElement(form_makeOpenTag('li'));
480        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
481        $form->addElement(form_makeTag('input', array(
482                        'type' => 'checkbox',
483                        'name' => 'rev2[]',
484                        'value' => 'current')));
485
486        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
487        $form->addElement($date);
488        $form->addElement(form_makeCloseTag('span'));
489
490        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
491
492        if (!$media_id) $href = wl($id);
493        else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
494        $form->addElement(form_makeOpenTag('a', array(
495                        'class' => 'wikilink1',
496                        'href'  => $href)));
497        $form->addElement($display_name);
498        $form->addElement(form_makeCloseTag('a'));
499
500        if ($media_id) $form->addElement(form_makeOpenTag('div'));
501
502        if (!$media_id) {
503            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
504            $form->addElement(' – ');
505            $form->addElement(htmlspecialchars($INFO['sum']));
506            $form->addElement(form_makeCloseTag('span'));
507        }
508
509        $changelog->setChunkSize(1024);
510
511        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
512        if($media_id) {
513            $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
514            if($revinfo['user']) {
515                $editor = $revinfo['user'];
516            } else {
517                $editor = $revinfo['ip'];
518            }
519        } else {
520            $editor = $INFO['editor'];
521        }
522        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor));
523        $form->addElement(form_makeCloseTag('span'));
524
525        $form->addElement('('.$lang['current'].')');
526
527        if ($media_id) $form->addElement(form_makeCloseTag('div'));
528
529        $form->addElement(form_makeCloseTag('div'));
530        $form->addElement(form_makeCloseTag('li'));
531    }
532
533    foreach($revisions as $rev){
534        $date = dformat($rev);
535        $info = $changelog->getRevisionInfo($rev);
536        if($media_id) {
537            $exists = @file_exists(mediaFN($id, $rev));
538        } else {
539            $exists = page_exists($id, $rev);
540        }
541
542        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
543            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
544        else
545            $form->addElement(form_makeOpenTag('li'));
546        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
547        if($exists){
548            $form->addElement(form_makeTag('input', array(
549                            'type' => 'checkbox',
550                            'name' => 'rev2[]',
551                            'value' => $rev)));
552        }else{
553            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
554        }
555
556        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
557        $form->addElement($date);
558        $form->addElement(form_makeCloseTag('span'));
559
560        if($exists){
561            if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&');
562            else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
563            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link')));
564            $form->addElement(form_makeTag('img', array(
565                            'src'    => DOKU_BASE.'lib/images/diff.png',
566                            'width'  => 15,
567                            'height' => 11,
568                            'title'  => $lang['diff'],
569                            'alt'    => $lang['diff'])));
570            $form->addElement(form_makeCloseTag('a'));
571            if (!$media_id) $href = wl($id,"rev=$rev",false,'&');
572            else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
573            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1')));
574            $form->addElement($display_name);
575            $form->addElement(form_makeCloseTag('a'));
576        }else{
577            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
578            $form->addElement($display_name);
579        }
580
581        if ($media_id) $form->addElement(form_makeOpenTag('div'));
582
583        if ($info['sum']) {
584            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
585            if (!$media_id) $form->addElement(' – ');
586            $form->addElement('<bdi>'.htmlspecialchars($info['sum']).'</bdi>');
587            $form->addElement(form_makeCloseTag('span'));
588        }
589
590        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
591        if($info['user']){
592            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
593            if(auth_ismanager()){
594                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
595            }
596        }else{
597            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
598        }
599        $form->addElement(form_makeCloseTag('span'));
600
601        if ($media_id) $form->addElement(form_makeCloseTag('div'));
602
603        $form->addElement(form_makeCloseTag('div'));
604        $form->addElement(form_makeCloseTag('li'));
605    }
606    $form->addElement(form_makeCloseTag('ul'));
607    if (!$media_id) {
608        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
609    } else {
610        $form->addHidden('mediado', 'diff');
611        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
612    }
613    html_form('revisions', $form);
614
615    print '<div class="pagenav">';
616    $last = $first + $conf['recent'];
617    if ($first > 0) {
618        $first -= $conf['recent'];
619        if ($first < 0) $first = 0;
620        print '<div class="pagenav-prev">';
621        if ($media_id) {
622            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
623        } else {
624            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
625        }
626        print '</div>';
627    }
628    if ($hasNext) {
629        print '<div class="pagenav-next">';
630        if ($media_id) {
631            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
632        } else {
633            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
634        }
635        print '</div>';
636    }
637    print '</div>';
638
639}
640
641/**
642 * display recent changes
643 *
644 * @author Andreas Gohr <andi@splitbrain.org>
645 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
646 * @author Ben Coburn <btcoburn@silicodon.net>
647 * @author Kate Arzamastseva <pshns@ukr.net>
648 */
649function html_recent($first=0, $show_changes='both'){
650    global $conf;
651    global $lang;
652    global $ID;
653    /* we need to get one additionally log entry to be able to
654     * decide if this is the last page or is there another one.
655     * This is the cheapest solution to get this information.
656     */
657    $flags = 0;
658    if ($show_changes == 'mediafiles' && $conf['mediarevisions']) {
659        $flags = RECENTS_MEDIA_CHANGES;
660    } elseif ($show_changes == 'pages') {
661        $flags = 0;
662    } elseif ($conf['mediarevisions']) {
663        $show_changes = 'both';
664        $flags = RECENTS_MEDIA_PAGES_MIXED;
665    }
666
667    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
668    if(count($recents) == 0 && $first != 0){
669        $first=0;
670        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
671    }
672    $hasNext = false;
673    if (count($recents)>$conf['recent']) {
674        $hasNext = true;
675        array_pop($recents); // remove extra log entry
676    }
677
678    print p_locale_xhtml('recent');
679
680    if (getNS($ID) != '')
681        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
682
683    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
684    $form->addHidden('sectok', null);
685    $form->addHidden('do', 'recent');
686    $form->addHidden('id', $ID);
687
688    if ($conf['mediarevisions']) {
689        $form->addElement('<div class="changeType">');
690        $form->addElement(form_makeListboxField(
691                    'show_changes',
692                    array(
693                        'pages'      => $lang['pages_changes'],
694                        'mediafiles' => $lang['media_changes'],
695                        'both'       => $lang['both_changes']),
696                    $show_changes,
697                    $lang['changes_type'],
698                    '','',
699                    array('class'=>'quickselect')));
700
701        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
702        $form->addElement('</div>');
703    }
704
705    $form->addElement(form_makeOpenTag('ul'));
706
707    foreach($recents as $recent){
708        $date = dformat($recent['date']);
709        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
710            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
711        else
712            $form->addElement(form_makeOpenTag('li'));
713
714        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
715
716        if (!empty($recent['media'])) {
717            $form->addElement(media_printicon($recent['id']));
718        } else {
719            $icon = DOKU_BASE.'lib/images/fileicons/file.png';
720            $form->addElement('<img src="'.$icon.'" alt="'.$recent['id'].'" class="icon" />');
721        }
722
723        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
724        $form->addElement($date);
725        $form->addElement(form_makeCloseTag('span'));
726
727        $diff = false;
728        $href = '';
729
730        if (!empty($recent['media'])) {
731            $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id'])));
732            if ($diff) {
733                $href = media_managerURL(array('tab_details' => 'history',
734                    'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
735            }
736        } else {
737            $href = wl($recent['id'],"do=diff", false, '&');
738        }
739
740        if (!empty($recent['media']) && !$diff) {
741            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
742        } else {
743            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
744            $form->addElement(form_makeTag('img', array(
745                            'src'   => DOKU_BASE.'lib/images/diff.png',
746                            'width' => 15,
747                            'height'=> 11,
748                            'title' => $lang['diff'],
749                            'alt'   => $lang['diff']
750                            )));
751            $form->addElement(form_makeCloseTag('a'));
752        }
753
754        if (!empty($recent['media'])) {
755            $href = media_managerURL(array('tab_details' => 'history',
756                'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
757        } else {
758            $href = wl($recent['id'],"do=revisions",false,'&');
759        }
760        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => $href)));
761        $form->addElement(form_makeTag('img', array(
762                        'src'   => DOKU_BASE.'lib/images/history.png',
763                        'width' => 12,
764                        'height'=> 14,
765                        'title' => $lang['btn_revs'],
766                        'alt'   => $lang['btn_revs']
767                        )));
768        $form->addElement(form_makeCloseTag('a'));
769
770        if (!empty($recent['media'])) {
771            $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
772            $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2';
773            $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href)));
774            $form->addElement($recent['id']);
775            $form->addElement(form_makeCloseTag('a'));
776        } else {
777            $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
778        }
779        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
780        $form->addElement(' – '.htmlspecialchars($recent['sum']));
781        $form->addElement(form_makeCloseTag('span'));
782
783        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
784        if($recent['user']){
785            $form->addElement('<bdi>'.editorinfo($recent['user']).'</bdi>');
786            if(auth_ismanager()){
787                $form->addElement(' <bdo dir="ltr">('.$recent['ip'].')</bdo>');
788            }
789        }else{
790            $form->addElement('<bdo dir="ltr">'.$recent['ip'].'</bdo>');
791        }
792        $form->addElement(form_makeCloseTag('span'));
793
794        $form->addElement(form_makeCloseTag('div'));
795        $form->addElement(form_makeCloseTag('li'));
796    }
797    $form->addElement(form_makeCloseTag('ul'));
798
799    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
800    $last = $first + $conf['recent'];
801    if ($first > 0) {
802        $first -= $conf['recent'];
803        if ($first < 0) $first = 0;
804        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
805        $form->addElement(form_makeTag('input', array(
806                    'type'  => 'submit',
807                    'name'  => 'first['.$first.']',
808                    'value' => $lang['btn_newer'],
809                    'accesskey' => 'n',
810                    'title' => $lang['btn_newer'].' [N]',
811                    'class' => 'button show'
812                    )));
813        $form->addElement(form_makeCloseTag('div'));
814    }
815    if ($hasNext) {
816        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
817        $form->addElement(form_makeTag('input', array(
818                        'type'  => 'submit',
819                        'name'  => 'first['.$last.']',
820                        'value' => $lang['btn_older'],
821                        'accesskey' => 'p',
822                        'title' => $lang['btn_older'].' [P]',
823                        'class' => 'button show'
824                        )));
825        $form->addElement(form_makeCloseTag('div'));
826    }
827    $form->addElement(form_makeCloseTag('div'));
828    html_form('recent', $form);
829}
830
831/**
832 * Display page index
833 *
834 * @author Andreas Gohr <andi@splitbrain.org>
835 */
836function html_index($ns){
837    global $conf;
838    global $ID;
839    $ns  = cleanID($ns);
840    #fixme use appropriate function
841    if(empty($ns)){
842        $ns = dirname(str_replace(':','/',$ID));
843        if($ns == '.') $ns ='';
844    }
845    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
846
847    echo p_locale_xhtml('index');
848    echo '<div id="index__tree">';
849
850    $data = array();
851    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
852    echo html_buildlist($data,'idx','html_list_index','html_li_index');
853
854    echo '</div>';
855}
856
857/**
858 * Index item formatter
859 *
860 * User function for html_buildlist()
861 *
862 * @author Andreas Gohr <andi@splitbrain.org>
863 */
864function html_list_index($item){
865    global $ID, $conf;
866
867    // prevent searchbots needlessly following links
868    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : '';
869
870    $ret = '';
871    $base = ':'.$item['id'];
872    $base = substr($base,strrpos($base,':')+1);
873    if($item['type']=='d'){
874        // FS#2766, no need for search bots to follow namespace links in the index
875        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>';
876        $ret .= $base;
877        $ret .= '</strong></a>';
878    }else{
879        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
880        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
881    }
882    return $ret;
883}
884
885/**
886 * Index List item
887 *
888 * This user function is used in html_buildlist to build the
889 * <li> tags for namespaces when displaying the page index
890 * it gives different classes to opened or closed "folders"
891 *
892 * @author Andreas Gohr <andi@splitbrain.org>
893 */
894function html_li_index($item){
895    if($item['type'] == "f"){
896        return '<li class="level'.$item['level'].'">';
897    }elseif($item['open']){
898        return '<li class="open">';
899    }else{
900        return '<li class="closed">';
901    }
902}
903
904/**
905 * Default List item
906 *
907 * @author Andreas Gohr <andi@splitbrain.org>
908 */
909function html_li_default($item){
910    return '<li class="level'.$item['level'].'">';
911}
912
913/**
914 * Build an unordered list
915 *
916 * Build an unordered list from the given $data array
917 * Each item in the array has to have a 'level' property
918 * the item itself gets printed by the given $func user
919 * function. The second and optional function is used to
920 * print the <li> tag. Both user function need to accept
921 * a single item.
922 *
923 * Both user functions can be given as array to point to
924 * a member of an object.
925 *
926 * @author Andreas Gohr <andi@splitbrain.org>
927 *
928 * @param array    $data  array with item arrays
929 * @param string   $class class of ul wrapper
930 * @param callable $func  callback to print an list item
931 * @param string   $lifunc callback to the opening li tag
932 * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
933                                 0 (we have a root object) or 1 (just the root content)
934 * @return string html of an unordered list
935 */
936function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
937    if (count($data) === 0) {
938        return '';
939    }
940
941    $start_level = $data[0]['level'];
942    $level = $start_level;
943    $ret   = '';
944    $open  = 0;
945
946    foreach ($data as $item){
947
948        if( $item['level'] > $level ){
949            //open new list
950            for($i=0; $i<($item['level'] - $level); $i++){
951                if ($i) $ret .= "<li class=\"clear\">";
952                $ret .= "\n<ul class=\"$class\">\n";
953                $open++;
954            }
955            $level = $item['level'];
956
957        }elseif( $item['level'] < $level ){
958            //close last item
959            $ret .= "</li>\n";
960            while( $level > $item['level'] && $open > 0 ){
961                //close higher lists
962                $ret .= "</ul>\n</li>\n";
963                $level--;
964                $open--;
965            }
966        } elseif ($ret !== '') {
967            //close previous item
968            $ret .= "</li>\n";
969        }
970
971        //print item
972        $ret .= call_user_func($lifunc,$item);
973        $ret .= '<div class="li">';
974
975        $ret .= call_user_func($func,$item);
976        $ret .= '</div>';
977    }
978
979    //close remaining items and lists
980    $ret .= "</li>\n";
981    while($open-- > 0) {
982        $ret .= "</ul></li>\n";
983    }
984
985    if ($forcewrapper || $start_level < 2) {
986        // Trigger building a wrapper ul if the first level is
987        // 0 (we have a root object) or 1 (just the root content)
988        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
989    }
990
991    return $ret;
992}
993
994/**
995 * display backlinks
996 *
997 * @author Andreas Gohr <andi@splitbrain.org>
998 * @author Michael Klier <chi@chimeric.de>
999 */
1000function html_backlinks(){
1001    global $ID;
1002    global $lang;
1003
1004    print p_locale_xhtml('backlinks');
1005
1006    $data = ft_backlinks($ID);
1007
1008    if(!empty($data)) {
1009        print '<ul class="idx">';
1010        foreach($data as $blink){
1011            print '<li><div class="li">';
1012            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
1013            print '</div></li>';
1014        }
1015        print '</ul>';
1016    } else {
1017        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1018    }
1019}
1020
1021/**
1022 * Get header of diff HTML
1023 * @param string $l_rev   Left revisions
1024 * @param string $r_rev   Right revision
1025 * @param string $id      Page id, if null $ID is used
1026 * @param bool   $media   If it is for media files
1027 * @param bool   $inline  Return the header on a single line
1028 * @return array HTML snippets for diff header
1029 */
1030function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1031    global $lang;
1032    if ($id === null) {
1033        global $ID;
1034        $id = $ID;
1035    }
1036    $head_separator = $inline ? ' ' : '<br />';
1037    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1038    $ml_or_wl = $media ? 'ml' : 'wl';
1039    $l_minor = $r_minor = '';
1040
1041    if($media) {
1042        $changelog = new MediaChangeLog($id);
1043    } else {
1044        $changelog = new PageChangeLog($id);
1045    }
1046    if(!$l_rev){
1047        $l_head = '&mdash;';
1048    }else{
1049        $l_info   = $changelog->getRevisionInfo($l_rev);
1050        if($l_info['user']){
1051            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1052            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1053        } else {
1054            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1055        }
1056        $l_user  = '<span class="user">'.$l_user.'</span>';
1057        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1058        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1059
1060        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1061        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1062        $l_head_title.'</a></bdi>'.
1063        $head_separator.$l_user.' '.$l_sum;
1064    }
1065
1066    if($r_rev){
1067        $r_info   = $changelog->getRevisionInfo($r_rev);
1068        if($r_info['user']){
1069            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1070            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1071        } else {
1072            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1073        }
1074        $r_user = '<span class="user">'.$r_user.'</span>';
1075        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1076        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1077
1078        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1079        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1080        $r_head_title.'</a></bdi>'.
1081        $head_separator.$r_user.' '.$r_sum;
1082    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1083        $_info   = $changelog->getRevisionInfo($_rev);
1084        if($_info['user']){
1085            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1086            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1087        } else {
1088            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1089        }
1090        $_user = '<span class="user">'.$_user.'</span>';
1091        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1092        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1093
1094        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1095        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1096        $r_head_title.'</a></bdi> '.
1097        '('.$lang['current'].')'.
1098        $head_separator.$_user.' '.$_sum;
1099    }else{
1100        $r_head = '&mdash; ('.$lang['current'].')';
1101    }
1102
1103    return array($l_head, $r_head, $l_minor, $r_minor);
1104}
1105
1106/**
1107 * Show diff
1108 * between current page version and provided $text
1109 * or between the revisions provided via GET or POST
1110 *
1111 * @author Andreas Gohr <andi@splitbrain.org>
1112 * @param  string $text  when non-empty: compare with this text with most current version
1113 * @param  bool   $intro display the intro text
1114 * @param  string $type  type of the diff (inline or sidebyside)
1115 */
1116function html_diff($text = '', $intro = true, $type = null) {
1117    global $ID;
1118    global $REV;
1119    global $lang;
1120    global $INPUT;
1121    global $INFO;
1122    $pagelog = new PageChangeLog($ID);
1123
1124    /*
1125     * Determine diff type
1126     */
1127    if(!$type) {
1128        $type = $INPUT->str('difftype');
1129        if(empty($type)) {
1130            $type = get_doku_pref('difftype', $type);
1131            if(empty($type) && $INFO['ismobile']) {
1132                $type = 'inline';
1133            }
1134        }
1135    }
1136    if($type != 'inline') $type = 'sidebyside';
1137
1138    /*
1139     * Determine requested revision(s)
1140     */
1141    // we're trying to be clever here, revisions to compare can be either
1142    // given as rev and rev2 parameters, with rev2 being optional. Or in an
1143    // array in rev2.
1144    $rev1 = $REV;
1145
1146    $rev2 = $INPUT->ref('rev2');
1147    if(is_array($rev2)) {
1148        $rev1 = (int) $rev2[0];
1149        $rev2 = (int) $rev2[1];
1150
1151        if(!$rev1) {
1152            $rev1 = $rev2;
1153            unset($rev2);
1154        }
1155    } else {
1156        $rev2 = $INPUT->int('rev2');
1157    }
1158
1159    /*
1160     * Determine left and right revision, its texts and the header
1161     */
1162    $r_minor = '';
1163    $l_minor = '';
1164
1165    if($text) { // compare text to the most current revision
1166        $l_rev = '';
1167        $l_text = rawWiki($ID, '');
1168        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1169            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
1170            $lang['current'];
1171
1172        $r_rev = '';
1173        $r_text = cleanText($text);
1174        $r_head = $lang['yours'];
1175    } else {
1176        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
1177            // make sure order is correct (older on the left)
1178            if($rev1 < $rev2) {
1179                $l_rev = $rev1;
1180                $r_rev = $rev2;
1181            } else {
1182                $l_rev = $rev2;
1183                $r_rev = $rev1;
1184            }
1185        } elseif($rev1) { // single revision given, compare to current
1186            $r_rev = '';
1187            $l_rev = $rev1;
1188        } else { // no revision was given, compare previous to current
1189            $r_rev = '';
1190            $revs = $pagelog->getRevisions(0, 1);
1191            $l_rev = $revs[0];
1192            $REV = $l_rev; // store revision back in $REV
1193        }
1194
1195        // when both revisions are empty then the page was created just now
1196        if(!$l_rev && !$r_rev) {
1197            $l_text = '';
1198        } else {
1199            $l_text = rawWiki($ID, $l_rev);
1200        }
1201        $r_text = rawWiki($ID, $r_rev);
1202
1203        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1204    }
1205
1206    /*
1207     * Build navigation
1208     */
1209    $l_nav = '';
1210    $r_nav = '';
1211    if(!$text) {
1212        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1213    }
1214    /*
1215     * Create diff object and the formatter
1216     */
1217    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
1218
1219    if($type == 'inline') {
1220        $diffformatter = new InlineDiffFormatter();
1221    } else {
1222        $diffformatter = new TableDiffFormatter();
1223    }
1224    /*
1225     * Display intro
1226     */
1227    if($intro) print p_locale_xhtml('diff');
1228
1229    /*
1230     * Display type and exact reference
1231     */
1232    if(!$text) {
1233        ptln('<div class="diffoptions group">');
1234
1235
1236        $form = new Doku_Form(array('action' => wl()));
1237        $form->addHidden('id', $ID);
1238        $form->addHidden('rev2[0]', $l_rev);
1239        $form->addHidden('rev2[1]', $r_rev);
1240        $form->addHidden('do', 'diff');
1241        $form->addElement(
1242             form_makeListboxField(
1243                 'difftype',
1244                 array(
1245                     'sidebyside' => $lang['diff_side'],
1246                     'inline' => $lang['diff_inline']
1247                 ),
1248                 $type,
1249                 $lang['diff_type'],
1250                 '', '',
1251                 array('class' => 'quickselect')
1252             )
1253        );
1254        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1255        $form->printForm();
1256
1257        ptln('<p>');
1258        // link to exactly this view FS#2835
1259        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
1260        ptln('</p>');
1261
1262        ptln('</div>'); // .diffoptions
1263    }
1264
1265    /*
1266     * Display diff view table
1267     */
1268    ?>
1269    <div class="table">
1270    <table class="diff diff_<?php echo $type ?>">
1271
1272        <?php
1273        //navigation and header
1274        if($type == 'inline') {
1275            if(!$text) { ?>
1276                <tr>
1277                    <td class="diff-lineheader">-</td>
1278                    <td class="diffnav"><?php echo $l_nav ?></td>
1279                </tr>
1280                <tr>
1281                    <th class="diff-lineheader">-</th>
1282                    <th <?php echo $l_minor ?>>
1283                        <?php echo $l_head ?>
1284                    </th>
1285                </tr>
1286            <?php } ?>
1287            <tr>
1288                <td class="diff-lineheader">+</td>
1289                <td class="diffnav"><?php echo $r_nav ?></td>
1290            </tr>
1291            <tr>
1292                <th class="diff-lineheader">+</th>
1293                <th <?php echo $r_minor ?>>
1294                    <?php echo $r_head ?>
1295                </th>
1296            </tr>
1297        <?php } else {
1298            if(!$text) { ?>
1299                <tr>
1300                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1301                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1302                </tr>
1303            <?php } ?>
1304            <tr>
1305                <th colspan="2" <?php echo $l_minor ?>>
1306                    <?php echo $l_head ?>
1307                </th>
1308                <th colspan="2" <?php echo $r_minor ?>>
1309                    <?php echo $r_head ?>
1310                </th>
1311            </tr>
1312        <?php }
1313
1314        //diff view
1315        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1316
1317    </table>
1318    </div>
1319<?php
1320}
1321
1322/**
1323 * Create html for revision navigation
1324 *
1325 * @param PageChangeLog $pagelog changelog object of current page
1326 * @param string        $type    inline vs sidebyside
1327 * @param int           $l_rev   left revision timestamp
1328 * @param int           $r_rev   right revision timestamp
1329 * @return string[] html of left and right navigation elements
1330 */
1331function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1332    global $INFO, $ID;
1333
1334    // last timestamp is not in changelog, retrieve timestamp from metadata
1335    // note: when page is removed, the metadata timestamp is zero
1336    $r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date'];
1337
1338    //retrieve revisions with additional info
1339    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1340    $l_revisions = array();
1341    if(!$l_rev) {
1342        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1343    }
1344    foreach($l_revs as $rev) {
1345        $info = $pagelog->getRevisionInfo($rev);
1346        $l_revisions[$rev] = array(
1347            $rev,
1348            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1349            $r_rev ? $rev >= $r_rev : false //disable?
1350        );
1351    }
1352    $r_revisions = array();
1353    if(!$r_rev) {
1354        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1355    }
1356    foreach($r_revs as $rev) {
1357        $info = $pagelog->getRevisionInfo($rev);
1358        $r_revisions[$rev] = array(
1359            $rev,
1360            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1361            $rev <= $l_rev //disable?
1362        );
1363    }
1364
1365    //determine previous/next revisions
1366    $l_index = array_search($l_rev, $l_revs);
1367    $l_prev = $l_revs[$l_index + 1];
1368    $l_next = $l_revs[$l_index - 1];
1369    if($r_rev) {
1370        $r_index = array_search($r_rev, $r_revs);
1371        $r_prev = $r_revs[$r_index + 1];
1372        $r_next = $r_revs[$r_index - 1];
1373    } else {
1374        //removed page
1375        if($l_next) {
1376            $r_prev = $r_revs[0];
1377        } else {
1378            $r_prev = null;
1379        }
1380        $r_next = null;
1381    }
1382
1383    /*
1384     * Left side:
1385     */
1386    $l_nav = '';
1387    //move back
1388    if($l_prev) {
1389        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1390        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1391    }
1392    //dropdown
1393    $form = new Doku_Form(array('action' => wl()));
1394    $form->addHidden('id', $ID);
1395    $form->addHidden('difftype', $type);
1396    $form->addHidden('rev2[1]', $r_rev);
1397    $form->addHidden('do', 'diff');
1398    $form->addElement(
1399         form_makeListboxField(
1400             'rev2[0]',
1401             $l_revisions,
1402             $l_rev,
1403             '', '', '',
1404             array('class' => 'quickselect')
1405         )
1406    );
1407    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1408    $l_nav .= $form->getForm();
1409    //move forward
1410    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1411        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1412    }
1413
1414    /*
1415     * Right side:
1416     */
1417    $r_nav = '';
1418    //move back
1419    if($l_rev < $r_prev) {
1420        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1421    }
1422    //dropdown
1423    $form = new Doku_Form(array('action' => wl()));
1424    $form->addHidden('id', $ID);
1425    $form->addHidden('rev2[0]', $l_rev);
1426    $form->addHidden('difftype', $type);
1427    $form->addHidden('do', 'diff');
1428    $form->addElement(
1429         form_makeListboxField(
1430             'rev2[1]',
1431             $r_revisions,
1432             $r_rev,
1433             '', '', '',
1434             array('class' => 'quickselect')
1435         )
1436    );
1437    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1438    $r_nav .= $form->getForm();
1439    //move forward
1440    if($r_next) {
1441        if($pagelog->isCurrentRevision($r_next)) {
1442            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1443        } else {
1444            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1445        }
1446        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1447    }
1448    return array($l_nav, $r_nav);
1449}
1450
1451/**
1452 * Create html link to a diff defined by two revisions
1453 *
1454 * @param string $difftype display type
1455 * @param string $linktype
1456 * @param int $lrev oldest revision
1457 * @param int $rrev newest revision or null for diff with current revision
1458 * @return string html of link to a diff
1459 */
1460function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
1461    global $ID, $lang;
1462    if(!$rrev) {
1463        $urlparam = array(
1464            'do' => 'diff',
1465            'rev' => $lrev,
1466            'difftype' => $difftype,
1467        );
1468    } else {
1469        $urlparam = array(
1470            'do' => 'diff',
1471            'rev2[0]' => $lrev,
1472            'rev2[1]' => $rrev,
1473            'difftype' => $difftype,
1474        );
1475    }
1476    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1477                '<span>' . $lang[$linktype] . '</span>' .
1478            '</a>' . "\n";
1479}
1480
1481/**
1482 * Insert soft breaks in diff html
1483 *
1484 * @param $diffhtml
1485 * @return string
1486 */
1487function html_insert_softbreaks($diffhtml) {
1488    // search the diff html string for both:
1489    // - html tags, so these can be ignored
1490    // - long strings of characters without breaking characters
1491    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1492}
1493
1494/**
1495 * callback which adds softbreaks
1496 *
1497 * @param array $match array with first the complete match
1498 * @return string the replacement
1499 */
1500function html_softbreak_callback($match){
1501    // if match is an html tag, return it intact
1502    if ($match[0]{0} == '<') return $match[0];
1503
1504    // its a long string without a breaking character,
1505    // make certain characters into breaking characters by inserting a
1506    // breaking character (zero length space, U+200B / #8203) in front them.
1507    $regex = <<< REGEX
1508(?(?=                                 # start a conditional expression with a positive look ahead ...
1509&\#?\\w{1,6};)                        # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1510&\#?\\w{1,6};                         # yes pattern - a quicker match for the html entity, since we know we have one
1511|
1512[?/,&\#;:]                            # no pattern - any other group of 'special' characters to insert a breaking character after
1513)+                                    # end conditional expression
1514REGEX;
1515
1516    return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1517}
1518
1519/**
1520 * show warning on conflict detection
1521 *
1522 * @author Andreas Gohr <andi@splitbrain.org>
1523 */
1524function html_conflict($text,$summary){
1525    global $ID;
1526    global $lang;
1527
1528    print p_locale_xhtml('conflict');
1529    $form = new Doku_Form(array('id' => 'dw__editform'));
1530    $form->addHidden('id', $ID);
1531    $form->addHidden('wikitext', $text);
1532    $form->addHidden('summary', $summary);
1533    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1534    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1535    html_form('conflict', $form);
1536    print '<br /><br /><br /><br />'.NL;
1537}
1538
1539/**
1540 * Prints the global message array
1541 *
1542 * @author Andreas Gohr <andi@splitbrain.org>
1543 */
1544function html_msgarea(){
1545    global $MSG, $MSG_shown;
1546    /** @var array $MSG */
1547    // store if the global $MSG has already been shown and thus HTML output has been started
1548    $MSG_shown = true;
1549
1550    if(!isset($MSG)) return;
1551
1552    $shown = array();
1553    foreach($MSG as $msg){
1554        $hash = md5($msg['msg']);
1555        if(isset($shown[$hash])) continue; // skip double messages
1556        if(info_msg_allowed($msg)){
1557            print '<div class="'.$msg['lvl'].'">';
1558            print $msg['msg'];
1559            print '</div>';
1560        }
1561        $shown[$hash] = 1;
1562    }
1563
1564    unset($GLOBALS['MSG']);
1565}
1566
1567/**
1568 * Prints the registration form
1569 *
1570 * @author Andreas Gohr <andi@splitbrain.org>
1571 */
1572function html_register(){
1573    global $lang;
1574    global $conf;
1575    global $INPUT;
1576
1577    $base_attrs = array('size'=>50,'required'=>'required');
1578    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1579
1580    print p_locale_xhtml('register');
1581    print '<div class="centeralign">'.NL;
1582    $form = new Doku_Form(array('id' => 'dw__register'));
1583    $form->startFieldset($lang['btn_register']);
1584    $form->addHidden('do', 'register');
1585    $form->addHidden('save', '1');
1586    $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1587    if (!$conf['autopasswd']) {
1588        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1589        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1590    }
1591    $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1592    $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1593    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1594    $form->endFieldset();
1595    html_form('register', $form);
1596
1597    print '</div>'.NL;
1598}
1599
1600/**
1601 * Print the update profile form
1602 *
1603 * @author Christopher Smith <chris@jalakai.co.uk>
1604 * @author Andreas Gohr <andi@splitbrain.org>
1605 */
1606function html_updateprofile(){
1607    global $lang;
1608    global $conf;
1609    global $INPUT;
1610    global $INFO;
1611    /** @var DokuWiki_Auth_Plugin $auth */
1612    global $auth;
1613
1614    print p_locale_xhtml('updateprofile');
1615    print '<div class="centeralign">'.NL;
1616
1617    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1618    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1619    $form = new Doku_Form(array('id' => 'dw__register'));
1620    $form->startFieldset($lang['profile']);
1621    $form->addHidden('do', 'profile');
1622    $form->addHidden('save', '1');
1623    $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1624    $attr = array('size'=>'50');
1625    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1626    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1627    $attr = array('size'=>'50', 'class'=>'edit');
1628    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1629    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1630    $form->addElement(form_makeTag('br'));
1631    if ($auth->canDo('modPass')) {
1632        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1633        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1634    }
1635    if ($conf['profileconfirm']) {
1636        $form->addElement(form_makeTag('br'));
1637        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1638    }
1639    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1640    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1641
1642    $form->endFieldset();
1643    html_form('updateprofile', $form);
1644
1645    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1646        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1647        $form_profiledelete->startFieldset($lang['profdeleteuser']);
1648        $form_profiledelete->addHidden('do', 'profile_delete');
1649        $form_profiledelete->addHidden('delete', '1');
1650        $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1651        if ($conf['profileconfirm']) {
1652            $form_profiledelete->addElement(form_makeTag('br'));
1653            $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1654        }
1655        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1656        $form_profiledelete->endFieldset();
1657
1658        html_form('profiledelete', $form_profiledelete);
1659    }
1660
1661    print '</div>'.NL;
1662}
1663
1664/**
1665 * Preprocess edit form data
1666 *
1667 * @author   Andreas Gohr <andi@splitbrain.org>
1668 *
1669 * @triggers HTML_EDITFORM_OUTPUT
1670 */
1671function html_edit(){
1672    global $INPUT;
1673    global $ID;
1674    global $REV;
1675    global $DATE;
1676    global $PRE;
1677    global $SUF;
1678    global $INFO;
1679    global $SUM;
1680    global $lang;
1681    global $conf;
1682    global $TEXT;
1683    global $RANGE;
1684
1685    if ($INPUT->has('changecheck')) {
1686        $check = $INPUT->str('changecheck');
1687    } elseif(!$INFO['exists']){
1688        // $TEXT has been loaded from page template
1689        $check = md5('');
1690    } else {
1691        $check = md5($TEXT);
1692    }
1693    $mod = md5($TEXT) !== $check;
1694
1695    $wr = $INFO['writable'] && !$INFO['locked'];
1696    $include = 'edit';
1697    if($wr){
1698        if ($REV) $include = 'editrev';
1699    }else{
1700        // check pseudo action 'source'
1701        if(!actionOK('source')){
1702            msg('Command disabled: source',-1);
1703            return;
1704        }
1705        $include = 'read';
1706    }
1707
1708    global $license;
1709
1710    $form = new Doku_Form(array('id' => 'dw__editform'));
1711    $form->addHidden('id', $ID);
1712    $form->addHidden('rev', $REV);
1713    $form->addHidden('date', $DATE);
1714    $form->addHidden('prefix', $PRE . '.');
1715    $form->addHidden('suffix', $SUF);
1716    $form->addHidden('changecheck', $check);
1717
1718    $data = array('form' => $form,
1719                  'wr'   => $wr,
1720                  'media_manager' => true,
1721                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1722                  'intro_locale' => $include);
1723
1724    if ($data['target'] !== 'section') {
1725        // Only emit event if page is writable, section edit data is valid and
1726        // edit target is not section.
1727        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1728    } else {
1729        html_edit_form($data);
1730    }
1731    if (isset($data['intro_locale'])) {
1732        echo p_locale_xhtml($data['intro_locale']);
1733    }
1734
1735    $form->addHidden('target', $data['target']);
1736    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1737    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1738    $form->addElement(form_makeCloseTag('div'));
1739    if ($wr) {
1740        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1741        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1742        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1743        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1744        $form->addElement(form_makeCloseTag('div'));
1745        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1746        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1747        $elem = html_minoredit();
1748        if ($elem) $form->addElement($elem);
1749        $form->addElement(form_makeCloseTag('div'));
1750    }
1751    $form->addElement(form_makeCloseTag('div'));
1752    if($wr && $conf['license']){
1753        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1754        $out  = $lang['licenseok'];
1755        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1756        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1757        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1758        $form->addElement($out);
1759        $form->addElement(form_makeCloseTag('div'));
1760    }
1761
1762    if ($wr) {
1763        // sets changed to true when previewed
1764        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1765        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1766        echo '/*!]]>*/</script>' . NL;
1767    } ?>
1768    <div class="editBox" role="application">
1769
1770    <div class="toolbar group">
1771        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1772        <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']?>"
1773            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1774    </div>
1775    <?php
1776
1777    html_form('edit', $form);
1778    print '</div>'.NL;
1779}
1780
1781/**
1782 * Display the default edit form
1783 *
1784 * Is the default action for HTML_EDIT_FORMSELECTION.
1785 * @param mixed[] $param
1786 */
1787function html_edit_form($param) {
1788    global $TEXT;
1789
1790    if ($param['target'] !== 'section') {
1791        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1792    }
1793
1794    $attr = array('tabindex'=>'1');
1795    if (!$param['wr']) $attr['readonly'] = 'readonly';
1796
1797    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1798}
1799
1800/**
1801 * Adds a checkbox for minor edits for logged in users
1802 *
1803 * @author Andreas Gohr <andi@splitbrain.org>
1804 */
1805function html_minoredit(){
1806    global $conf;
1807    global $lang;
1808    global $INPUT;
1809    // minor edits are for logged in users only
1810    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1811        return false;
1812    }
1813
1814    $p = array();
1815    $p['tabindex'] = 3;
1816    if($INPUT->bool('minor')) $p['checked']='checked';
1817    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1818}
1819
1820/**
1821 * prints some debug info
1822 *
1823 * @author Andreas Gohr <andi@splitbrain.org>
1824 */
1825function html_debug(){
1826    global $conf;
1827    global $lang;
1828    /** @var DokuWiki_Auth_Plugin $auth */
1829    global $auth;
1830    global $INFO;
1831
1832    //remove sensitive data
1833    $cnf = $conf;
1834    debug_guard($cnf);
1835    $nfo = $INFO;
1836    debug_guard($nfo);
1837    $ses = $_SESSION;
1838    debug_guard($ses);
1839
1840    print '<html><body>';
1841
1842    print '<p>When reporting bugs please send all the following ';
1843    print 'output as a mail to andi@splitbrain.org ';
1844    print 'The best way to do this is to save this page in your browser</p>';
1845
1846    print '<b>$INFO:</b><pre>';
1847    print_r($nfo);
1848    print '</pre>';
1849
1850    print '<b>$_SERVER:</b><pre>';
1851    print_r($_SERVER);
1852    print '</pre>';
1853
1854    print '<b>$conf:</b><pre>';
1855    print_r($cnf);
1856    print '</pre>';
1857
1858    print '<b>DOKU_BASE:</b><pre>';
1859    print DOKU_BASE;
1860    print '</pre>';
1861
1862    print '<b>abs DOKU_BASE:</b><pre>';
1863    print DOKU_URL;
1864    print '</pre>';
1865
1866    print '<b>rel DOKU_BASE:</b><pre>';
1867    print dirname($_SERVER['PHP_SELF']).'/';
1868    print '</pre>';
1869
1870    print '<b>PHP Version:</b><pre>';
1871    print phpversion();
1872    print '</pre>';
1873
1874    print '<b>locale:</b><pre>';
1875    print setlocale(LC_ALL,0);
1876    print '</pre>';
1877
1878    print '<b>encoding:</b><pre>';
1879    print $lang['encoding'];
1880    print '</pre>';
1881
1882    if($auth){
1883        print '<b>Auth backend capabilities:</b><pre>';
1884        foreach ($auth->getCapabilities() as $cando){
1885            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
1886        }
1887        print '</pre>';
1888    }
1889
1890    print '<b>$_SESSION:</b><pre>';
1891    print_r($ses);
1892    print '</pre>';
1893
1894    print '<b>Environment:</b><pre>';
1895    print_r($_ENV);
1896    print '</pre>';
1897
1898    print '<b>PHP settings:</b><pre>';
1899    $inis = ini_get_all();
1900    print_r($inis);
1901    print '</pre>';
1902
1903    if (function_exists('apache_get_version')) {
1904        $apache['version'] = apache_get_version();
1905
1906        if (function_exists('apache_get_modules')) {
1907            $apache['modules'] = apache_get_modules();
1908        }
1909        print '<b>Apache</b><pre>';
1910        print_r($apache);
1911        print '</pre>';
1912    }
1913
1914    print '</body></html>';
1915}
1916
1917/**
1918 * List available Administration Tasks
1919 *
1920 * @author Andreas Gohr <andi@splitbrain.org>
1921 * @author Håkan Sandell <hakan.sandell@home.se>
1922 */
1923function html_admin(){
1924    global $ID;
1925    global $INFO;
1926    global $conf;
1927    /** @var DokuWiki_Auth_Plugin $auth */
1928    global $auth;
1929
1930    // build menu of admin functions from the plugins that handle them
1931    $pluginlist = plugin_list('admin');
1932    $menu = array();
1933    foreach ($pluginlist as $p) {
1934        /** @var DokuWiki_Admin_Plugin $obj */
1935        if(($obj = plugin_load('admin',$p)) === null) continue;
1936
1937        // check permissions
1938        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1939
1940        $menu[$p] = array('plugin' => $p,
1941                'prompt' => $obj->getMenuText($conf['lang']),
1942                'sort' => $obj->getMenuSort()
1943                );
1944    }
1945
1946    // data security check
1947    // simple check if the 'savedir' is relative and accessible when appended to DOKU_URL
1948    // it verifies either:
1949    //   'savedir' has been moved elsewhere, or
1950    //   has protection to prevent the webserver serving files from it
1951    if (substr($conf['savedir'],0,2) == './'){
1952        echo '<a style="border:none; float:right;"
1953                href="http://www.dokuwiki.org/security#web_access_security">
1954                <img src="'.DOKU_URL.$conf['savedir'].'/security.png" alt="Your data directory seems to be protected properly."
1955                onerror="this.parentNode.style.display=\'none\'" /></a>';
1956    }
1957
1958    print p_locale_xhtml('admin');
1959
1960    // Admin Tasks
1961    if($INFO['isadmin']){
1962        ptln('<ul class="admin_tasks">');
1963
1964        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1965            ptln('  <li class="admin_usermanager"><div class="li">'.
1966                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1967                    $menu['usermanager']['prompt'].'</a></div></li>');
1968        }
1969        unset($menu['usermanager']);
1970
1971        if($menu['acl']){
1972            ptln('  <li class="admin_acl"><div class="li">'.
1973                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1974                    $menu['acl']['prompt'].'</a></div></li>');
1975        }
1976        unset($menu['acl']);
1977
1978        if($menu['extension']){
1979            ptln('  <li class="admin_plugin"><div class="li">'.
1980                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'extension')).'">'.
1981                    $menu['extension']['prompt'].'</a></div></li>');
1982        }
1983        unset($menu['extension']);
1984
1985        if($menu['config']){
1986            ptln('  <li class="admin_config"><div class="li">'.
1987                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1988                    $menu['config']['prompt'].'</a></div></li>');
1989        }
1990        unset($menu['config']);
1991    }
1992    ptln('</ul>');
1993
1994    // Manager Tasks
1995    ptln('<ul class="admin_tasks">');
1996
1997    if($menu['revert']){
1998        ptln('  <li class="admin_revert"><div class="li">'.
1999                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
2000                $menu['revert']['prompt'].'</a></div></li>');
2001    }
2002    unset($menu['revert']);
2003
2004    if($menu['popularity']){
2005        ptln('  <li class="admin_popularity"><div class="li">'.
2006                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
2007                $menu['popularity']['prompt'].'</a></div></li>');
2008    }
2009    unset($menu['popularity']);
2010
2011    // print DokuWiki version:
2012    ptln('</ul>');
2013    echo '<div id="admin__version">';
2014    echo getVersion();
2015    echo '</div>';
2016
2017    // print the rest as sorted list
2018    if(count($menu)){
2019        usort($menu, 'p_sort_modes');
2020        // output the menu
2021        ptln('<div class="clearer"></div>');
2022        print p_locale_xhtml('adminplugins');
2023        ptln('<ul>');
2024        foreach ($menu as $item) {
2025            if (!$item['prompt']) continue;
2026            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
2027        }
2028        ptln('</ul>');
2029    }
2030}
2031
2032/**
2033 * Form to request a new password for an existing account
2034 *
2035 * @author Benoit Chesneau <benoit@bchesneau.info>
2036 * @author Andreas Gohr <gohr@cosmocode.de>
2037 */
2038function html_resendpwd() {
2039    global $lang;
2040    global $conf;
2041    global $INPUT;
2042
2043    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2044
2045    if(!$conf['autopasswd'] && $token){
2046        print p_locale_xhtml('resetpwd');
2047        print '<div class="centeralign">'.NL;
2048        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2049        $form->startFieldset($lang['btn_resendpwd']);
2050        $form->addHidden('token', $token);
2051        $form->addHidden('do', 'resendpwd');
2052
2053        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2054        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2055
2056        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2057        $form->endFieldset();
2058        html_form('resendpwd', $form);
2059        print '</div>'.NL;
2060    }else{
2061        print p_locale_xhtml('resendpwd');
2062        print '<div class="centeralign">'.NL;
2063        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2064        $form->startFieldset($lang['resendpwd']);
2065        $form->addHidden('do', 'resendpwd');
2066        $form->addHidden('save', '1');
2067        $form->addElement(form_makeTag('br'));
2068        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2069        $form->addElement(form_makeTag('br'));
2070        $form->addElement(form_makeTag('br'));
2071        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2072        $form->endFieldset();
2073        html_form('resendpwd', $form);
2074        print '</div>'.NL;
2075    }
2076}
2077
2078/**
2079 * Return the TOC rendered to XHTML
2080 *
2081 * @author Andreas Gohr <andi@splitbrain.org>
2082 */
2083function html_TOC($toc){
2084    if(!count($toc)) return '';
2085    global $lang;
2086    $out  = '<!-- TOC START -->'.DOKU_LF;
2087    $out .= '<div id="dw__toc">'.DOKU_LF;
2088    $out .= '<h3 class="toggle">';
2089    $out .= $lang['toc'];
2090    $out .= '</h3>'.DOKU_LF;
2091    $out .= '<div>'.DOKU_LF;
2092    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2093    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2094    $out .= '<!-- TOC END -->'.DOKU_LF;
2095    return $out;
2096}
2097
2098/**
2099 * Callback for html_buildlist
2100 */
2101function html_list_toc($item){
2102    if(isset($item['hid'])){
2103        $link = '#'.$item['hid'];
2104    }else{
2105        $link = $item['link'];
2106    }
2107
2108    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2109}
2110
2111/**
2112 * Helper function to build TOC items
2113 *
2114 * Returns an array ready to be added to a TOC array
2115 *
2116 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2117 * @param string $text  - what to display in the TOC
2118 * @param int    $level - nesting level
2119 * @param string $hash  - is prepended to the given $link, set blank if you want full links
2120 * @return array the toc item
2121 */
2122function html_mktocitem($link, $text, $level, $hash='#'){
2123    return  array( 'link'  => $hash.$link,
2124            'title' => $text,
2125            'type'  => 'ul',
2126            'level' => $level);
2127}
2128
2129/**
2130 * Output a Doku_Form object.
2131 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2132 *
2133 * @author Tom N Harris <tnharris@whoopdedo.org>
2134 * @param string     $name The name of the form
2135 * @param Doku_Form  $form The form
2136 */
2137function html_form($name, &$form) {
2138    // Safety check in case the caller forgets.
2139    $form->endFieldset();
2140    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2141}
2142
2143/**
2144 * Form print function.
2145 * Just calls printForm() on the data object.
2146 * @param Doku_Form $data The form
2147 */
2148function html_form_output($data) {
2149    $data->printForm();
2150}
2151
2152/**
2153 * Embed a flash object in HTML
2154 *
2155 * This will create the needed HTML to embed a flash movie in a cross browser
2156 * compatble way using valid XHTML
2157 *
2158 * The parameters $params, $flashvars and $atts need to be associative arrays.
2159 * No escaping needs to be done for them. The alternative content *has* to be
2160 * escaped because it is used as is. If no alternative content is given
2161 * $lang['noflash'] is used.
2162 *
2163 * @author Andreas Gohr <andi@splitbrain.org>
2164 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
2165 *
2166 * @param string $swf      - the SWF movie to embed
2167 * @param int $width       - width of the flash movie in pixels
2168 * @param int $height      - height of the flash movie in pixels
2169 * @param array $params    - additional parameters (<param>)
2170 * @param array $flashvars - parameters to be passed in the flashvar parameter
2171 * @param array $atts      - additional attributes for the <object> tag
2172 * @param string $alt      - alternative content (is NOT automatically escaped!)
2173 * @return string         - the XHTML markup
2174 */
2175function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
2176    global $lang;
2177
2178    $out = '';
2179
2180    // prepare the object attributes
2181    if(is_null($atts)) $atts = array();
2182    $atts['width']  = (int) $width;
2183    $atts['height'] = (int) $height;
2184    if(!$atts['width'])  $atts['width']  = 425;
2185    if(!$atts['height']) $atts['height'] = 350;
2186
2187    // add object attributes for standard compliant browsers
2188    $std = $atts;
2189    $std['type'] = 'application/x-shockwave-flash';
2190    $std['data'] = $swf;
2191
2192    // add object attributes for IE
2193    $ie  = $atts;
2194    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
2195
2196    // open object (with conditional comments)
2197    $out .= '<!--[if !IE]> -->'.NL;
2198    $out .= '<object '.buildAttributes($std).'>'.NL;
2199    $out .= '<!-- <![endif]-->'.NL;
2200    $out .= '<!--[if IE]>'.NL;
2201    $out .= '<object '.buildAttributes($ie).'>'.NL;
2202    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
2203    $out .= '<!--><!-- -->'.NL;
2204
2205    // print params
2206    if(is_array($params)) foreach($params as $key => $val){
2207        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
2208    }
2209
2210    // add flashvars
2211    if(is_array($flashvars)){
2212        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
2213    }
2214
2215    // alternative content
2216    if($alt){
2217        $out .= $alt.NL;
2218    }else{
2219        $out .= $lang['noflash'].NL;
2220    }
2221
2222    // finish
2223    $out .= '</object>'.NL;
2224    $out .= '<!-- <![endif]-->'.NL;
2225
2226    return $out;
2227}
2228
2229/**
2230 * Prints HTML code for the given tab structure
2231 *
2232 * @param array  $tabs        tab structure
2233 * @param string $current_tab the current tab id
2234 */
2235function html_tabs($tabs, $current_tab = null) {
2236    echo '<ul class="tabs">'.NL;
2237
2238    foreach($tabs as $id => $tab) {
2239        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
2240    }
2241
2242    echo '</ul>'.NL;
2243}
2244/**
2245 * Prints a single tab
2246 *
2247 * @author Kate Arzamastseva <pshns@ukr.net>
2248 * @author Adrian Lang <mail@adrianlang.de>
2249 *
2250 * @param string $href - tab href
2251 * @param string $caption - tab caption
2252 * @param boolean $selected - is tab selected
2253 */
2254
2255function html_tab($href, $caption, $selected=false) {
2256    $tab = '<li>';
2257    if ($selected) {
2258        $tab .= '<strong>';
2259    } else {
2260        $tab .= '<a href="' . hsc($href) . '">';
2261    }
2262    $tab .= hsc($caption)
2263         .  '</' . ($selected ? 'strong' : 'a') . '>'
2264         .  '</li>'.NL;
2265    echo $tab;
2266}
2267
2268