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