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