xref: /dokuwiki/inc/html.php (revision fb52c6661375e2bc8011b764c06fc9fd67617c55)
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 */
17function html_wikilink($id,$name=null,$search=''){
18    static $xhtml_renderer = null;
19    if(is_null($xhtml_renderer)){
20        $xhtml_renderer = p_get_renderer('xhtml');
21    }
22
23    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
24}
25
26/**
27 * Helps building long attribute lists
28 *
29 * @author Andreas Gohr <andi@splitbrain.org>
30 */
31function html_attbuild($attributes){
32    $ret = '';
33    foreach ( $attributes as $key => $value ) {
34        $ret .= $key.'="'.formText($value).'" ';
35    }
36    return trim($ret);
37}
38
39/**
40 * The loginform
41 *
42 * @author   Andreas Gohr <andi@splitbrain.org>
43 */
44function html_login(){
45    global $lang;
46    global $conf;
47    global $ID;
48
49    print p_locale_xhtml('login');
50    print '<div class="centeralign">'.NL;
51    $form = new Doku_Form(array('id' => 'dw__login'));
52    $form->startFieldset($lang['btn_login']);
53    $form->addHidden('id', $ID);
54    $form->addHidden('do', 'login');
55    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
56    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
57    if($conf['rememberme']) {
58        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
59    }
60    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
61    $form->endFieldset();
62
63    if(actionOK('register')){
64        $form->addElement('<p>'
65                          . $lang['reghere']
66                          . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'
67                          . '</p>');
68    }
69
70    if (actionOK('resendpwd')) {
71        $form->addElement('<p>'
72                          . $lang['pwdforget']
73                          . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'
74                          . '</p>');
75    }
76
77    html_form('login', $form);
78    print '</div>'.NL;
79}
80
81/**
82 * inserts section edit buttons if wanted or removes the markers
83 *
84 * @author Andreas Gohr <andi@splitbrain.org>
85 */
86function html_secedit($text,$show=true){
87    global $INFO;
88
89    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
90
91    if(!$INFO['writable'] || !$show || $INFO['rev']){
92        return preg_replace($regexp,'',$text);
93    }
94
95    return preg_replace_callback($regexp,
96                'html_secedit_button', $text);
97}
98
99/**
100 * prepares section edit button data for event triggering
101 * used as a callback in html_secedit
102 *
103 * @triggers HTML_SECEDIT_BUTTON
104 * @author Andreas Gohr <andi@splitbrain.org>
105 */
106function html_secedit_button($matches){
107    $data = array('secid'  => $matches[1],
108                  'target' => strtolower($matches[2]),
109                  'range'  => $matches[count($matches) - 1]);
110    if (count($matches) === 5) {
111        $data['name'] = $matches[3];
112    }
113
114    return trigger_event('HTML_SECEDIT_BUTTON', $data,
115                         'html_secedit_get_button');
116}
117
118/**
119 * prints a section editing button
120 * used as default action form HTML_SECEDIT_BUTTON
121 *
122 * @author Adrian Lang <lang@cosmocode.de>
123 */
124function html_secedit_get_button($data) {
125    global $ID;
126    global $INFO;
127
128    if (!isset($data['name']) || $data['name'] === '') return;
129
130    $name = $data['name'];
131    unset($data['name']);
132
133    $secid = $data['secid'];
134    unset($data['secid']);
135
136    return "<div class='secedit editbutton_" . $data['target'] .
137                       " editbutton_" . $secid . "'>" .
138           html_btn('secedit', $ID, '',
139                    array_merge(array('do'  => 'edit',
140                                      'rev' => $INFO['lastmod'],
141                                      'summary' => '['.$name.'] '), $data),
142                    'post', $name) . '</div>';
143}
144
145/**
146 * Just the back to top button (in its own form)
147 *
148 * @author Andreas Gohr <andi@splitbrain.org>
149 */
150function html_topbtn(){
151    global $lang;
152
153    $ret  = '';
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=''){
166    global $conf;
167    global $lang;
168
169    $label = $lang['btn_'.$name];
170
171    $ret = '';
172    $tip = '';
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">';
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>';
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    global $conf;
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_filter((array) $phrases);
288    $regex = join('|',array_map('_html_hilight_re_preprocess', array_map('preg_quote_cb',$phrases)));
289
290    if ($regex === '') return $html;
291    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
292    return $html;
293}
294
295/**
296 * Wraps a search term in regex boundary checks.
297 */
298function _html_hilight_re_preprocess($term) {
299    return '\b'.$term.'\b';
300}
301
302/**
303 * Callback used by html_hilight()
304 *
305 * @author Harry Fuecks <hfuecks@gmail.com>
306 */
307function html_hilight_callback($m) {
308    $hlight = unslash($m[0]);
309    if ( !isset($m[2])) {
310        $hlight = '<span class="search_hit">'.$hlight.'</span>';
311    }
312    return $hlight;
313}
314
315/**
316 * Run a search and display the result
317 *
318 * @author Andreas Gohr <andi@splitbrain.org>
319 */
320function html_search(){
321    global $conf;
322    global $QUERY;
323    global $ID;
324    global $lang;
325
326    print p_locale_xhtml('searchpage');
327    flush();
328
329    //check if search is restricted to namespace
330    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
331        $id = cleanID($match[1]);
332    } else {
333        $id = cleanID($QUERY);
334    }
335
336    //show progressbar
337    print '<div class="centeralign" id="dw__loading">'.NL;
338    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
339    print 'showLoadBar();'.NL;
340    print '//--><!]]></script>'.NL;
341    print '<br /></div>'.NL;
342    flush();
343
344    //do quick pagesearch
345    $data = array();
346
347    if($id) $data = ft_pageLookup($id,true,useHeading('navigation'));
348    if(count($data)){
349        print '<div class="search_quickresult">';
350        print '<h3>'.$lang['quickhits'].':</h3>';
351        print '<ul class="search_quickhits">';
352        foreach($data as $id => $title){
353            print '<li> ';
354            if (useHeading('navigation')) {
355                $name = $title;
356            }else{
357                $ns = getNS($id);
358                if($ns){
359                    $name = shorten(noNS($id), ' ('.$ns.')',30);
360                }else{
361                    $name = $id;
362                }
363            }
364            print html_wikilink(':'.$id,$name);
365            print '</li> ';
366        }
367        print '</ul> ';
368        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
369        print '<div class="clearer">&nbsp;</div>';
370        print '</div>';
371    }
372    flush();
373
374    //do fulltext search
375    $data = ft_pageSearch($QUERY,$regex);
376    if(count($data)){
377        $num = 1;
378        foreach($data as $id => $cnt){
379            print '<div class="search_result">';
380            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
381            if($cnt !== 0){
382                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
383                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
384                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
385                }
386                $num++;
387            }
388            print '</div>';
389            flush();
390        }
391    }else{
392        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
393    }
394
395    //hide progressbar
396    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
397    print 'hideLoadBar("dw__loading");'.NL;
398    print '//--><!]]></script>'.NL;
399    flush();
400}
401
402/**
403 * Display error on locked pages
404 *
405 * @author Andreas Gohr <andi@splitbrain.org>
406 */
407function html_locked(){
408    global $ID;
409    global $conf;
410    global $lang;
411    global $INFO;
412
413    $locktime = filemtime(wikiLockFN($ID));
414    $expire = dformat($locktime + $conf['locktime']);
415    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
416
417    print p_locale_xhtml('locked');
418    print '<ul>';
419    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
420    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
421    print '</ul>';
422}
423
424/**
425 * list old revisions
426 *
427 * @author Andreas Gohr <andi@splitbrain.org>
428 * @author Ben Coburn <btcoburn@silicodon.net>
429 */
430function html_revisions($first=0){
431    global $ID;
432    global $INFO;
433    global $conf;
434    global $lang;
435    /* we need to get one additionally log entry to be able to
436     * decide if this is the last page or is there another one.
437     * see html_recent()
438     */
439    $revisions = getRevisions($ID, $first, $conf['recent']+1);
440    if(count($revisions)==0 && $first!=0){
441        $first=0;
442        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
443    }
444    $hasNext = false;
445    if (count($revisions)>$conf['recent']) {
446        $hasNext = true;
447        array_pop($revisions); // remove extra log entry
448    }
449
450    $date = dformat($INFO['lastmod']);
451
452    print p_locale_xhtml('revisions');
453
454    $form = new Doku_Form(array('id' => 'page__revisions'));
455    $form->addElement(form_makeOpenTag('ul'));
456    if($INFO['exists'] && $first==0){
457        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
458            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
459        else
460            $form->addElement(form_makeOpenTag('li'));
461        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
462        $form->addElement(form_makeTag('input', array(
463                        'type' => 'checkbox',
464                        'name' => 'rev2[]',
465                        'value' => 'current')));
466
467        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
468        $form->addElement($date);
469        $form->addElement(form_makeCloseTag('span'));
470
471        $form->addElement(form_makeTag('img', array(
472                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
473                        'width' => '15',
474                        'height' => '11',
475                        'alt'    => '')));
476
477        $form->addElement(form_makeOpenTag('a', array(
478                        'class' => 'wikilink1',
479                        'href'  => wl($ID))));
480        $form->addElement($ID);
481        $form->addElement(form_makeCloseTag('a'));
482
483        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
484        $form->addElement(' &ndash; ');
485        $form->addElement(htmlspecialchars($INFO['sum']));
486        $form->addElement(form_makeCloseTag('span'));
487
488        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
489        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
490        $form->addElement(form_makeCloseTag('span'));
491
492        $form->addElement('('.$lang['current'].')');
493        $form->addElement(form_makeCloseTag('div'));
494        $form->addElement(form_makeCloseTag('li'));
495    }
496
497    foreach($revisions as $rev){
498        $date   = dformat($rev);
499        $info   = getRevisionInfo($ID,$rev,true);
500        $exists = page_exists($ID,$rev);
501
502        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
503            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
504        else
505            $form->addElement(form_makeOpenTag('li'));
506        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
507        if($exists){
508            $form->addElement(form_makeTag('input', array(
509                            'type' => 'checkbox',
510                            'name' => 'rev2[]',
511                            'value' => $rev)));
512        }else{
513            $form->addElement(form_makeTag('img', array(
514                            'src' => DOKU_BASE.'lib/images/blank.gif',
515                            'width' => 14,
516                            'height' => 11,
517                            'alt' => '')));
518        }
519
520        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
521        $form->addElement($date);
522        $form->addElement(form_makeCloseTag('span'));
523
524        if($exists){
525            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
526            $form->addElement(form_makeTag('img', array(
527                            'src'    => DOKU_BASE.'lib/images/diff.png',
528                            'width'  => 15,
529                            'height' => 11,
530                            'title'  => $lang['diff'],
531                            'alt'    => $lang['diff'])));
532            $form->addElement(form_makeCloseTag('a'));
533
534            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
535            $form->addElement($ID);
536            $form->addElement(form_makeCloseTag('a'));
537        }else{
538            $form->addElement(form_makeTag('img', array(
539                            'src' => DOKU_BASE.'lib/images/blank.gif',
540                            'width' => '15',
541                            'height' => '11',
542                            'alt'   => '')));
543            $form->addElement($ID);
544        }
545
546        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
547        $form->addElement(' &ndash; ');
548        $form->addElement(htmlspecialchars($info['sum']));
549        $form->addElement(form_makeCloseTag('span'));
550
551        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
552        if($info['user']){
553            $form->addElement(editorinfo($info['user']));
554            if(auth_ismanager()){
555                $form->addElement(' ('.$info['ip'].')');
556            }
557        }else{
558            $form->addElement($info['ip']);
559        }
560        $form->addElement(form_makeCloseTag('span'));
561
562        $form->addElement(form_makeCloseTag('div'));
563        $form->addElement(form_makeCloseTag('li'));
564    }
565    $form->addElement(form_makeCloseTag('ul'));
566    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
567    html_form('revisions', $form);
568
569    print '<div class="pagenav">';
570    $last = $first + $conf['recent'];
571    if ($first > 0) {
572        $first -= $conf['recent'];
573        if ($first < 0) $first = 0;
574        print '<div class="pagenav-prev">';
575        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
576        print '</div>';
577    }
578    if ($hasNext) {
579        print '<div class="pagenav-next">';
580        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
581        print '</div>';
582    }
583    print '</div>';
584
585}
586
587/**
588 * display recent changes
589 *
590 * @author Andreas Gohr <andi@splitbrain.org>
591 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
592 * @author Ben Coburn <btcoburn@silicodon.net>
593 */
594function html_recent($first=0){
595    global $conf;
596    global $lang;
597    global $ID;
598    /* we need to get one additionally log entry to be able to
599     * decide if this is the last page or is there another one.
600     * This is the cheapest solution to get this information.
601     */
602    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
603    if(count($recents) == 0 && $first != 0){
604        $first=0;
605        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
606    }
607    $hasNext = false;
608    if (count($recents)>$conf['recent']) {
609        $hasNext = true;
610        array_pop($recents); // remove extra log entry
611    }
612
613    print p_locale_xhtml('recent');
614
615    if (getNS($ID) != '')
616        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
617
618    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
619    $form->addHidden('sectok', null);
620    $form->addHidden('do', 'recent');
621    $form->addHidden('id', $ID);
622    $form->addElement(form_makeOpenTag('ul'));
623
624    foreach($recents as $recent){
625        $date = dformat($recent['date']);
626        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
627            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
628        else
629            $form->addElement(form_makeOpenTag('li'));
630
631        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
632
633        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
634        $form->addElement($date);
635        $form->addElement(form_makeCloseTag('span'));
636
637        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
638        $form->addElement(form_makeTag('img', array(
639                        'src'   => DOKU_BASE.'lib/images/diff.png',
640                        'width' => 15,
641                        'height'=> 11,
642                        'title' => $lang['diff'],
643                        'alt'   => $lang['diff']
644                        )));
645        $form->addElement(form_makeCloseTag('a'));
646
647        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
648        $form->addElement(form_makeTag('img', array(
649                        'src'   => DOKU_BASE.'lib/images/history.png',
650                        'width' => 12,
651                        'height'=> 14,
652                        'title' => $lang['btn_revs'],
653                        'alt'   => $lang['btn_revs']
654                        )));
655        $form->addElement(form_makeCloseTag('a'));
656
657        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
658
659        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
660        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
661        $form->addElement(form_makeCloseTag('span'));
662
663        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
664        if($recent['user']){
665            $form->addElement(editorinfo($recent['user']));
666            if(auth_ismanager()){
667                $form->addElement(' ('.$recent['ip'].')');
668            }
669        }else{
670            $form->addElement($recent['ip']);
671        }
672        $form->addElement(form_makeCloseTag('span'));
673
674        $form->addElement(form_makeCloseTag('div'));
675        $form->addElement(form_makeCloseTag('li'));
676    }
677    $form->addElement(form_makeCloseTag('ul'));
678
679    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
680    $last = $first + $conf['recent'];
681    if ($first > 0) {
682        $first -= $conf['recent'];
683        if ($first < 0) $first = 0;
684        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
685        $form->addElement(form_makeTag('input', array(
686                    'type'  => 'submit',
687                    'name'  => 'first['.$first.']',
688                    'value' => $lang['btn_newer'],
689                    'accesskey' => 'n',
690                    'title' => $lang['btn_newer'].' [N]',
691                    'class' => 'button'
692                    )));
693        $form->addElement(form_makeCloseTag('div'));
694    }
695    if ($hasNext) {
696        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
697        $form->addElement(form_makeTag('input', array(
698                        'type'  => 'submit',
699                        'name'  => 'first['.$last.']',
700                        'value' => $lang['btn_older'],
701                        'accesskey' => 'p',
702                        'title' => $lang['btn_older'].' [P]',
703                        'class' => 'button'
704                        )));
705        $form->addElement(form_makeCloseTag('div'));
706    }
707    $form->addElement(form_makeCloseTag('div'));
708    html_form('recent', $form);
709}
710
711/**
712 * Display page index
713 *
714 * @author Andreas Gohr <andi@splitbrain.org>
715 */
716function html_index($ns){
717    global $conf;
718    global $ID;
719    $dir = $conf['datadir'];
720    $ns  = cleanID($ns);
721    #fixme use appropriate function
722    if(empty($ns)){
723        $ns = dirname(str_replace(':','/',$ID));
724        if($ns == '.') $ns ='';
725    }
726    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
727
728    echo p_locale_xhtml('index');
729    echo '<div id="index__tree">';
730
731    $data = array();
732    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
733    echo html_buildlist($data,'idx','html_list_index','html_li_index');
734
735    echo '</div>';
736}
737
738/**
739 * Index item formatter
740 *
741 * User function for html_buildlist()
742 *
743 * @author Andreas Gohr <andi@splitbrain.org>
744 */
745function html_list_index($item){
746    global $ID;
747    $ret = '';
748    $base = ':'.$item['id'];
749    $base = substr($base,strrpos($base,':')+1);
750    if($item['type']=='d'){
751        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
752        $ret .= $base;
753        $ret .= '</strong></a>';
754    }else{
755        $ret .= html_wikilink(':'.$item['id']);
756    }
757    return $ret;
758}
759
760/**
761 * Index List item
762 *
763 * This user function is used in html_build_lidt to build the
764 * <li> tags for namespaces when displaying the page index
765 * it gives different classes to opened or closed "folders"
766 *
767 * @author Andreas Gohr <andi@splitbrain.org>
768 */
769function html_li_index($item){
770    if($item['type'] == "f"){
771        return '<li class="level'.$item['level'].'">';
772    }elseif($item['open']){
773        return '<li class="open">';
774    }else{
775        return '<li class="closed">';
776    }
777}
778
779/**
780 * Default List item
781 *
782 * @author Andreas Gohr <andi@splitbrain.org>
783 */
784function html_li_default($item){
785    return '<li class="level'.$item['level'].'">';
786}
787
788/**
789 * Build an unordered list
790 *
791 * Build an unordered list from the given $data array
792 * Each item in the array has to have a 'level' property
793 * the item itself gets printed by the given $func user
794 * function. The second and optional function is used to
795 * print the <li> tag. Both user function need to accept
796 * a single item.
797 *
798 * Both user functions can be given as array to point to
799 * a member of an object.
800 *
801 * @author Andreas Gohr <andi@splitbrain.org>
802 */
803function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
804    $level = 0;
805    $opens = 0;
806    $ret   = '';
807
808    foreach ($data as $item){
809
810        if( $item['level'] > $level ){
811            //open new list
812            for($i=0; $i<($item['level'] - $level); $i++){
813                if ($i) $ret .= "<li class=\"clear\">\n";
814                $ret .= "\n<ul class=\"$class\">\n";
815            }
816        }elseif( $item['level'] < $level ){
817            //close last item
818            $ret .= "</li>\n";
819            for ($i=0; $i<($level - $item['level']); $i++){
820                //close higher lists
821                $ret .= "</ul>\n</li>\n";
822            }
823        }else{
824            //close last item
825            $ret .= "</li>\n";
826        }
827
828        //remember current level
829        $level = $item['level'];
830
831        //print item
832        $ret .= call_user_func($lifunc,$item);
833        $ret .= '<div class="li">';
834
835        $ret .= call_user_func($func,$item);
836        $ret .= '</div>';
837    }
838
839    //close remaining items and lists
840    for ($i=0; $i < $level; $i++){
841        $ret .= "</li></ul>\n";
842    }
843
844    return $ret;
845}
846
847/**
848 * display backlinks
849 *
850 * @author Andreas Gohr <andi@splitbrain.org>
851 * @author Michael Klier <chi@chimeric.de>
852 */
853function html_backlinks(){
854    global $ID;
855    global $conf;
856    global $lang;
857
858    print p_locale_xhtml('backlinks');
859
860    $data = ft_backlinks($ID);
861
862    if(!empty($data)) {
863        print '<ul class="idx">';
864        foreach($data as $blink){
865            print '<li><div class="li">';
866            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
867            print '</div></li>';
868        }
869        print '</ul>';
870    } else {
871        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
872    }
873}
874
875/**
876 * show diff
877 *
878 * @author Andreas Gohr <andi@splitbrain.org>
879 */
880function html_diff($text='',$intro=true){
881    global $ID;
882    global $REV;
883    global $lang;
884    global $conf;
885
886    // we're trying to be clever here, revisions to compare can be either
887    // given as rev and rev2 parameters, with rev2 being optional. Or in an
888    // array in rev2.
889    $rev1 = $REV;
890
891    if(is_array($_REQUEST['rev2'])){
892        $rev1 = (int) $_REQUEST['rev2'][0];
893        $rev2 = (int) $_REQUEST['rev2'][1];
894
895        if(!$rev1){
896            $rev1 = $rev2;
897            unset($rev2);
898        }
899    }else{
900        $rev2 = (int) $_REQUEST['rev2'];
901    }
902
903    if($text){                      // compare text to the most current revision
904        $l_rev   = '';
905        $l_text  = rawWiki($ID,'');
906        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
907            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
908            $lang['current'];
909
910        $r_rev   = '';
911        $r_text  = cleanText($text);
912        $r_head  = $lang['yours'];
913    }else{
914        if($rev1 && $rev2){            // two specific revisions wanted
915            // make sure order is correct (older on the left)
916            if($rev1 < $rev2){
917                $l_rev = $rev1;
918                $r_rev = $rev2;
919            }else{
920                $l_rev = $rev2;
921                $r_rev = $rev1;
922            }
923        }elseif($rev1){                // single revision given, compare to current
924            $r_rev = '';
925            $l_rev = $rev1;
926        }else{                        // no revision was given, compare previous to current
927            $r_rev = '';
928            $revs = getRevisions($ID, 0, 1);
929            $l_rev = $revs[0];
930            $REV = $l_rev; // store revision back in $REV
931        }
932
933        // when both revisions are empty then the page was created just now
934        if(!$l_rev && !$r_rev){
935            $l_text = '';
936        }else{
937            $l_text = rawWiki($ID,$l_rev);
938        }
939        $r_text = rawWiki($ID,$r_rev);
940
941        if(!$l_rev){
942            $l_head = '&mdash;';
943        }else{
944            $l_info   = getRevisionInfo($ID,$l_rev,true);
945            if($l_info['user']){
946                $l_user = editorinfo($l_info['user']);
947                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
948            } else {
949                $l_user = $l_info['ip'];
950            }
951            $l_user  = '<span class="user">'.$l_user.'</span>';
952            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
953            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
954
955            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
956            $ID.' ['.dformat($l_rev).']</a>'.
957            '<br />'.$l_user.' '.$l_sum;
958        }
959
960        if($r_rev){
961            $r_info   = getRevisionInfo($ID,$r_rev,true);
962            if($r_info['user']){
963                $r_user = editorinfo($r_info['user']);
964                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
965            } else {
966                $r_user = $r_info['ip'];
967            }
968            $r_user = '<span class="user">'.$r_user.'</span>';
969            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
970            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
971
972            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
973            $ID.' ['.dformat($r_rev).']</a>'.
974            '<br />'.$r_user.' '.$r_sum;
975        }elseif($_rev = @filemtime(wikiFN($ID))){
976            $_info   = getRevisionInfo($ID,$_rev,true);
977            if($_info['user']){
978                $_user = editorinfo($_info['user']);
979                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
980            } else {
981                $_user = $_info['ip'];
982            }
983            $_user = '<span class="user">'.$_user.'</span>';
984            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
985            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
986
987            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
988            $ID.' ['.dformat($_rev).']</a> '.
989            '('.$lang['current'].')'.
990            '<br />'.$_user.' '.$_sum;
991        }else{
992            $r_head = '&mdash; ('.$lang['current'].')';
993        }
994    }
995
996    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
997        explode("\n",htmlspecialchars($r_text)));
998
999    $tdf = new TableDiffFormatter();
1000    if($intro) print p_locale_xhtml('diff');
1001
1002    if (!$text) {
1003        $diffurl = wl($ID, array('do'=>'diff', 'rev2[0]'=>$l_rev, 'rev2[1]'=>$r_rev));
1004        ptln('<p class="difflink">');
1005        ptln('  <a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a>');
1006        ptln('</p>');
1007    }
1008    ?>
1009    <table class="diff">
1010    <tr>
1011    <th colspan="2" <?php echo $l_minor?>>
1012    <?php echo $l_head?>
1013    </th>
1014    <th colspan="2" <?php echo $r_minor?>>
1015    <?php echo $r_head?>
1016    </th>
1017    </tr>
1018    <?php echo $tdf->format($df)?>
1019    </table>
1020    <?php
1021}
1022
1023/**
1024 * show warning on conflict detection
1025 *
1026 * @author Andreas Gohr <andi@splitbrain.org>
1027 */
1028function html_conflict($text,$summary){
1029    global $ID;
1030    global $lang;
1031
1032    print p_locale_xhtml('conflict');
1033    $form = new Doku_Form(array('id' => 'dw__editform'));
1034    $form->addHidden('id', $ID);
1035    $form->addHidden('wikitext', $text);
1036    $form->addHidden('summary', $summary);
1037    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1038    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1039    html_form('conflict', $form);
1040    print '<br /><br /><br /><br />'.NL;
1041}
1042
1043/**
1044 * Prints the global message array
1045 *
1046 * @author Andreas Gohr <andi@splitbrain.org>
1047 */
1048function html_msgarea(){
1049    global $MSG;
1050    if(!isset($MSG)) return;
1051
1052    $shown = array();
1053    foreach($MSG as $msg){
1054        $hash = md5($msg['msg']);
1055        if(isset($shown[$hash])) continue; // skip double messages
1056        print '<div class="'.$msg['lvl'].'">';
1057        print $msg['msg'];
1058        print '</div>';
1059        $shown[$hash] = 1;
1060    }
1061}
1062
1063/**
1064 * Prints the registration form
1065 *
1066 * @author Andreas Gohr <andi@splitbrain.org>
1067 */
1068function html_register(){
1069    global $lang;
1070    global $conf;
1071    global $ID;
1072
1073    print p_locale_xhtml('register');
1074    print '<div class="centeralign">'.NL;
1075    $form = new Doku_Form(array('id' => 'dw__register'));
1076    $form->startFieldset($lang['register']);
1077    $form->addHidden('do', 'register');
1078    $form->addHidden('save', '1');
1079    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1080    if (!$conf['autopasswd']) {
1081        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1082        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1083    }
1084    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1085    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1086    $form->addElement(form_makeButton('submit', '', $lang['register']));
1087    $form->endFieldset();
1088    html_form('register', $form);
1089
1090    print '</div>'.NL;
1091}
1092
1093/**
1094 * Print the update profile form
1095 *
1096 * @author Christopher Smith <chris@jalakai.co.uk>
1097 * @author Andreas Gohr <andi@splitbrain.org>
1098 */
1099function html_updateprofile(){
1100    global $lang;
1101    global $conf;
1102    global $ID;
1103    global $INFO;
1104    global $auth;
1105
1106    print p_locale_xhtml('updateprofile');
1107
1108    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1109    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1110    print '<div class="centeralign">'.NL;
1111    $form = new Doku_Form(array('id' => 'dw__register'));
1112    $form->startFieldset($lang['profile']);
1113    $form->addHidden('do', 'profile');
1114    $form->addHidden('save', '1');
1115    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1116    $attr = array('size'=>'50');
1117    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1118    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1119    $attr = array('size'=>'50');
1120    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1121    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1122    $form->addElement(form_makeTag('br'));
1123    if ($auth->canDo('modPass')) {
1124        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1125        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1126    }
1127    if ($conf['profileconfirm']) {
1128        $form->addElement(form_makeTag('br'));
1129        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1130    }
1131    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1132    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1133    $form->endFieldset();
1134    html_form('updateprofile', $form);
1135    print '</div>'.NL;
1136}
1137
1138/**
1139 * Preprocess edit form data
1140 *
1141 * @author   Andreas Gohr <andi@splitbrain.org>
1142 *
1143 * @triggers HTML_EDITFORM_OUTPUT
1144 */
1145function html_edit(){
1146    global $ID;
1147    global $REV;
1148    global $DATE;
1149    global $PRE;
1150    global $SUF;
1151    global $INFO;
1152    global $SUM;
1153    global $lang;
1154    global $conf;
1155    global $TEXT;
1156    global $RANGE;
1157
1158    if (isset($_REQUEST['changecheck'])) {
1159        $check = $_REQUEST['changecheck'];
1160    } elseif(!$INFO['exists']){
1161        // $TEXT has been loaded from page template
1162        $check = md5('');
1163    } else {
1164        $check = md5($TEXT);
1165    }
1166    $mod = md5($TEXT) !== $check;
1167
1168    $wr = $INFO['writable'] && !$INFO['locked'];
1169    $include = 'edit';
1170    if($wr){
1171        if ($REV) $include = 'editrev';
1172    }else{
1173        // check pseudo action 'source'
1174        if(!actionOK('source')){
1175            msg('Command disabled: source',-1);
1176            return;
1177        }
1178        $include = 'read';
1179    }
1180
1181    global $license;
1182
1183    $form = new Doku_Form(array('id' => 'dw__editform'));
1184    $form->addHidden('id', $ID);
1185    $form->addHidden('rev', $REV);
1186    $form->addHidden('date', $DATE);
1187    $form->addHidden('prefix', $PRE . '.');
1188    $form->addHidden('suffix', $SUF);
1189    $form->addHidden('changecheck', $check);
1190
1191    $data = array('form' => $form,
1192                  'wr'   => $wr,
1193                  'media_manager' => true,
1194                  'target' => (isset($_REQUEST['target']) && $wr &&
1195                               $RANGE !== '') ? $_REQUEST['target'] : 'section',
1196                  'intro_locale' => $include);
1197
1198    if ($data['target'] !== 'section') {
1199        // Only emit event if page is writable, section edit data is valid and
1200        // edit target is not section.
1201        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1202    } else {
1203        html_edit_form($data);
1204    }
1205    if (isset($data['intro_locale'])) {
1206        echo p_locale_xhtml($data['intro_locale']);
1207    }
1208
1209    $form->addHidden('target', $data['target']);
1210    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1211    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1212    $form->addElement(form_makeCloseTag('div'));
1213    if ($wr) {
1214        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1215        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1216        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1217        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1218        $form->addElement(form_makeCloseTag('div'));
1219        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1220        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1221        $elem = html_minoredit();
1222        if ($elem) $form->addElement($elem);
1223        $form->addElement(form_makeCloseTag('div'));
1224    }
1225    $form->addElement(form_makeCloseTag('div'));
1226    if($wr && $conf['license']){
1227        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1228        $out  = $lang['licenseok'];
1229        $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1230        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1231        $out .= '> '.$license[$conf['license']]['name'].'</a>';
1232        $form->addElement($out);
1233        $form->addElement(form_makeCloseTag('div'));
1234    }
1235
1236    if ($wr) {
1237        // sets changed to true when previewed
1238        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
1239        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1240        echo '//--><!]]></script>' . NL;
1241    } ?>
1242    <div style="width:99%;">
1243
1244    <div class="toolbar">
1245    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1246    <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']?>"
1247        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1248
1249    </div>
1250    <?php
1251
1252    html_form('edit', $form);
1253    print '</div>'.NL;
1254}
1255
1256/**
1257 * Display the default edit form
1258 *
1259 * Is the default action for HTML_EDIT_FORMSELECTION.
1260 */
1261function html_edit_form($param) {
1262    global $TEXT;
1263
1264    if ($param['target'] !== 'section') {
1265        msg('No editor for edit target ' . $param['target'] . ' found.', -1);
1266    }
1267
1268    $attr = array('tabindex'=>'1');
1269    if (!$param['wr']) $attr['readonly'] = 'readonly';
1270
1271    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1272}
1273
1274/**
1275 * Adds a checkbox for minor edits for logged in users
1276 *
1277 * @author Andreas Gohr <andi@splitbrain.org>
1278 */
1279function html_minoredit(){
1280    global $conf;
1281    global $lang;
1282    // minor edits are for logged in users only
1283    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1284        return false;
1285    }
1286
1287    $p = array();
1288    $p['tabindex'] = 3;
1289    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1290    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1291}
1292
1293/**
1294 * prints some debug info
1295 *
1296 * @author Andreas Gohr <andi@splitbrain.org>
1297 */
1298function html_debug(){
1299    global $conf;
1300    global $lang;
1301    global $auth;
1302    global $INFO;
1303
1304    //remove sensitive data
1305    $cnf = $conf;
1306    debug_guard($cnf);
1307    $nfo = $INFO;
1308    debug_guard($nfo);
1309    $ses = $_SESSION;
1310    debug_guard($ses);
1311
1312    print '<html><body>';
1313
1314    print '<p>When reporting bugs please send all the following ';
1315    print 'output as a mail to andi@splitbrain.org ';
1316    print 'The best way to do this is to save this page in your browser</p>';
1317
1318    print '<b>$INFO:</b><pre>';
1319    print_r($nfo);
1320    print '</pre>';
1321
1322    print '<b>$_SERVER:</b><pre>';
1323    print_r($_SERVER);
1324    print '</pre>';
1325
1326    print '<b>$conf:</b><pre>';
1327    print_r($cnf);
1328    print '</pre>';
1329
1330    print '<b>DOKU_BASE:</b><pre>';
1331    print DOKU_BASE;
1332    print '</pre>';
1333
1334    print '<b>abs DOKU_BASE:</b><pre>';
1335    print DOKU_URL;
1336    print '</pre>';
1337
1338    print '<b>rel DOKU_BASE:</b><pre>';
1339    print dirname($_SERVER['PHP_SELF']).'/';
1340    print '</pre>';
1341
1342    print '<b>PHP Version:</b><pre>';
1343    print phpversion();
1344    print '</pre>';
1345
1346    print '<b>locale:</b><pre>';
1347    print setlocale(LC_ALL,0);
1348    print '</pre>';
1349
1350    print '<b>encoding:</b><pre>';
1351    print $lang['encoding'];
1352    print '</pre>';
1353
1354    if($auth){
1355        print '<b>Auth backend capabilities:</b><pre>';
1356        print_r($auth->cando);
1357        print '</pre>';
1358    }
1359
1360    print '<b>$_SESSION:</b><pre>';
1361    print_r($ses);
1362    print '</pre>';
1363
1364    print '<b>Environment:</b><pre>';
1365    print_r($_ENV);
1366    print '</pre>';
1367
1368    print '<b>PHP settings:</b><pre>';
1369    $inis = ini_get_all();
1370    print_r($inis);
1371    print '</pre>';
1372
1373    print '</body></html>';
1374}
1375
1376/**
1377 * List available Administration Tasks
1378 *
1379 * @author Andreas Gohr <andi@splitbrain.org>
1380 * @author Håkan Sandell <hakan.sandell@home.se>
1381 */
1382function html_admin(){
1383    global $ID;
1384    global $INFO;
1385    global $lang;
1386    global $conf;
1387    global $auth;
1388
1389    // build menu of admin functions from the plugins that handle them
1390    $pluginlist = plugin_list('admin');
1391    $menu = array();
1392    foreach ($pluginlist as $p) {
1393        if($obj =& plugin_load('admin',$p) === null) continue;
1394
1395        // check permissions
1396        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1397
1398        $menu[$p] = array('plugin' => $p,
1399                'prompt' => $obj->getMenuText($conf['lang']),
1400                'sort' => $obj->getMenuSort()
1401                );
1402    }
1403
1404    // data security check
1405    echo '<a style="background: transparent url(data/security.png) left top no-repeat;
1406                  display: block; width:380px; height:73px; border:none; float:right"
1407           target="_blank"
1408           href="http://www.dokuwiki.org/security#web_access_security"></a>';
1409
1410    print p_locale_xhtml('admin');
1411
1412    // Admin Tasks
1413    if($INFO['isadmin']){
1414        ptln('<ul class="admin_tasks">');
1415
1416        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1417            ptln('  <li class="admin_usermanager"><div class="li">'.
1418                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1419                    $menu['usermanager']['prompt'].'</a></div></li>');
1420        }
1421        unset($menu['usermanager']);
1422
1423        if($menu['acl']){
1424            ptln('  <li class="admin_acl"><div class="li">'.
1425                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1426                    $menu['acl']['prompt'].'</a></div></li>');
1427        }
1428        unset($menu['acl']);
1429
1430        if($menu['plugin']){
1431            ptln('  <li class="admin_plugin"><div class="li">'.
1432                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
1433                    $menu['plugin']['prompt'].'</a></div></li>');
1434        }
1435        unset($menu['plugin']);
1436
1437        if($menu['config']){
1438            ptln('  <li class="admin_config"><div class="li">'.
1439                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1440                    $menu['config']['prompt'].'</a></div></li>');
1441        }
1442        unset($menu['config']);
1443    }
1444    ptln('</ul>');
1445
1446    // Manager Tasks
1447    ptln('<ul class="admin_tasks">');
1448
1449    if($menu['revert']){
1450        ptln('  <li class="admin_revert"><div class="li">'.
1451                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1452                $menu['revert']['prompt'].'</a></div></li>');
1453    }
1454    unset($menu['revert']);
1455
1456    if($menu['popularity']){
1457        ptln('  <li class="admin_popularity"><div class="li">'.
1458                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1459                $menu['popularity']['prompt'].'</a></div></li>');
1460    }
1461    unset($menu['popularity']);
1462
1463    // print DokuWiki version:
1464    ptln('</ul>');
1465    echo '<div id="admin__version">';
1466    echo getVersion();
1467    echo '</div>';
1468
1469    // print the rest as sorted list
1470    if(count($menu)){
1471        usort($menu, 'p_sort_modes');
1472        // output the menu
1473        ptln('<div class="clearer"></div>');
1474        print p_locale_xhtml('adminplugins');
1475        ptln('<ul>');
1476        foreach ($menu as $item) {
1477            if (!$item['prompt']) continue;
1478            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1479        }
1480        ptln('</ul>');
1481    }
1482}
1483
1484/**
1485 * Form to request a new password for an existing account
1486 *
1487 * @author Benoit Chesneau <benoit@bchesneau.info>
1488 */
1489function html_resendpwd() {
1490    global $lang;
1491    global $conf;
1492    global $ID;
1493
1494    print p_locale_xhtml('resendpwd');
1495    print '<div class="centeralign">'.NL;
1496    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1497    $form->startFieldset($lang['resendpwd']);
1498    $form->addHidden('do', 'resendpwd');
1499    $form->addHidden('save', '1');
1500    $form->addElement(form_makeTag('br'));
1501    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1502    $form->addElement(form_makeTag('br'));
1503    $form->addElement(form_makeTag('br'));
1504    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1505    $form->endFieldset();
1506    html_form('resendpwd', $form);
1507    print '</div>'.NL;
1508}
1509
1510/**
1511 * Return the TOC rendered to XHTML
1512 *
1513 * @author Andreas Gohr <andi@splitbrain.org>
1514 */
1515function html_TOC($toc){
1516    if(!count($toc)) return '';
1517    global $lang;
1518    $out  = '<!-- TOC START -->'.DOKU_LF;
1519    $out .= '<div class="toc">'.DOKU_LF;
1520    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1521    $out .= $lang['toc'];
1522    $out .= '</div>'.DOKU_LF;
1523    $out .= '<div id="toc__inside">'.DOKU_LF;
1524    $out .= html_buildlist($toc,'toc','html_list_toc');
1525    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1526    $out .= '<!-- TOC END -->'.DOKU_LF;
1527    return $out;
1528}
1529
1530/**
1531 * Callback for html_buildlist
1532 */
1533function html_list_toc($item){
1534    if(isset($item['hid'])){
1535        $link = '#'.$item['hid'];
1536    }else{
1537        $link = $item['link'];
1538    }
1539
1540    return '<span class="li"><a href="'.$link.'" class="toc">'.
1541        hsc($item['title']).'</a></span>';
1542}
1543
1544/**
1545 * Helper function to build TOC items
1546 *
1547 * Returns an array ready to be added to a TOC array
1548 *
1549 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1550 * @param string $text  - what to display in the TOC
1551 * @param int    $level - nesting level
1552 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1553 */
1554function html_mktocitem($link, $text, $level, $hash='#'){
1555    global $conf;
1556    return  array( 'link'  => $hash.$link,
1557            'title' => $text,
1558            'type'  => 'ul',
1559            'level' => $level);
1560}
1561
1562/**
1563 * Output a Doku_Form object.
1564 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1565 *
1566 * @author Tom N Harris <tnharris@whoopdedo.org>
1567 */
1568function html_form($name, &$form) {
1569    // Safety check in case the caller forgets.
1570    $form->endFieldset();
1571    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1572}
1573
1574/**
1575 * Form print function.
1576 * Just calls printForm() on the data object.
1577 */
1578function html_form_output($data) {
1579    $data->printForm();
1580}
1581
1582/**
1583 * Embed a flash object in HTML
1584 *
1585 * This will create the needed HTML to embed a flash movie in a cross browser
1586 * compatble way using valid XHTML
1587 *
1588 * The parameters $params, $flashvars and $atts need to be associative arrays.
1589 * No escaping needs to be done for them. The alternative content *has* to be
1590 * escaped because it is used as is. If no alternative content is given
1591 * $lang['noflash'] is used.
1592 *
1593 * @author Andreas Gohr <andi@splitbrain.org>
1594 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1595 *
1596 * @param string $swf      - the SWF movie to embed
1597 * @param int $width       - width of the flash movie in pixels
1598 * @param int $height      - height of the flash movie in pixels
1599 * @param array $params    - additional parameters (<param>)
1600 * @param array $flashvars - parameters to be passed in the flashvar parameter
1601 * @param array $atts      - additional attributes for the <object> tag
1602 * @param string $alt      - alternative content (is NOT automatically escaped!)
1603 * @returns string         - the XHTML markup
1604 */
1605function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1606    global $lang;
1607
1608    $out = '';
1609
1610    // prepare the object attributes
1611    if(is_null($atts)) $atts = array();
1612    $atts['width']  = (int) $width;
1613    $atts['height'] = (int) $height;
1614    if(!$atts['width'])  $atts['width']  = 425;
1615    if(!$atts['height']) $atts['height'] = 350;
1616
1617    // add object attributes for standard compliant browsers
1618    $std = $atts;
1619    $std['type'] = 'application/x-shockwave-flash';
1620    $std['data'] = $swf;
1621
1622    // add object attributes for IE
1623    $ie  = $atts;
1624    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1625
1626    // open object (with conditional comments)
1627    $out .= '<!--[if !IE]> -->'.NL;
1628    $out .= '<object '.buildAttributes($std).'>'.NL;
1629    $out .= '<!-- <![endif]-->'.NL;
1630    $out .= '<!--[if IE]>'.NL;
1631    $out .= '<object '.buildAttributes($ie).'>'.NL;
1632    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1633    $out .= '<!--><!-- -->'.NL;
1634
1635    // print params
1636    if(is_array($params)) foreach($params as $key => $val){
1637        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1638    }
1639
1640    // add flashvars
1641    if(is_array($flashvars)){
1642        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1643    }
1644
1645    // alternative content
1646    if($alt){
1647        $out .= $alt.NL;
1648    }else{
1649        $out .= $lang['noflash'].NL;
1650    }
1651
1652    // finish
1653    $out .= '</object>'.NL;
1654    $out .= '<!-- <![endif]-->'.NL;
1655
1656    return $out;
1657}
1658
1659