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