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