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