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