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