xref: /dokuwiki/inc/html.php (revision 64373bfcbb5e8c82f512283345f7822f1b8ef69f)
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'],
141                                      'summary' => '['.$name.'] '), $data),
142                    'post', $name) . '</div>';
143}
144
145/**
146 * Just the back to top button (in its own form)
147 *
148 * @author Andreas Gohr <andi@splitbrain.org>
149 */
150function html_topbtn(){
151    global $lang;
152
153    $ret  = '';
154    $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>';
155
156    return $ret;
157}
158
159/**
160 * Displays a button (using its own form)
161 * If tooltip exists, the access key tooltip is replaced.
162 *
163 * @author Andreas Gohr <andi@splitbrain.org>
164 */
165function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
166    global $conf;
167    global $lang;
168
169    $label = $lang['btn_'.$name];
170
171    $ret = '';
172    $tip = '';
173
174    //filter id (without urlencoding)
175    $id = idfilter($id,false);
176
177    //make nice URLs even for buttons
178    if($conf['userewrite'] == 2){
179        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
180    }elseif($conf['userewrite']){
181        $script = DOKU_BASE.$id;
182    }else{
183        $script = DOKU_BASE.DOKU_SCRIPT;
184        $params['id'] = $id;
185    }
186
187    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
188
189    if(is_array($params)){
190        reset($params);
191        while (list($key, $val) = each($params)) {
192            $ret .= '<input type="hidden" name="'.$key.'" ';
193            $ret .= 'value="'.htmlspecialchars($val).'" />';
194        }
195    }
196
197    if ($tooltip!='') {
198        $tip = htmlspecialchars($tooltip);
199    }else{
200        $tip = htmlspecialchars($label);
201    }
202
203    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
204    if($akey){
205        $tip .= ' ['.strtoupper($akey).']';
206        $ret .= 'accesskey="'.$akey.'" ';
207    }
208    $ret .= 'title="'.$tip.'" ';
209    $ret .= '/>';
210    $ret .= '</div></form>';
211
212    return $ret;
213}
214
215/**
216 * show a wiki page
217 *
218 * @author Andreas Gohr <andi@splitbrain.org>
219 */
220function html_show($txt=null){
221    global $ID;
222    global $REV;
223    global $HIGH;
224    global $INFO;
225    //disable section editing for old revisions or in preview
226    if($txt || $REV){
227        $secedit = false;
228    }else{
229        $secedit = true;
230    }
231
232    if (!is_null($txt)){
233        //PreviewHeader
234        echo '<br id="scroll__here" />';
235        echo p_locale_xhtml('preview');
236        echo '<div class="preview">';
237        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
238        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
239        echo $html;
240        echo '<div class="clearer"></div>';
241        echo '</div>';
242
243    }else{
244        if ($REV) print p_locale_xhtml('showrev');
245        $html = p_wiki_xhtml($ID,$REV,true);
246        $html = html_secedit($html,$secedit);
247        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
248        $html = html_hilight($html,$HIGH);
249        echo $html;
250    }
251}
252
253/**
254 * ask the user about how to handle an exisiting draft
255 *
256 * @author Andreas Gohr <andi@splitbrain.org>
257 */
258function html_draft(){
259    global $INFO;
260    global $ID;
261    global $lang;
262    global $conf;
263    $draft = unserialize(io_readFile($INFO['draft'],false));
264    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
265
266    print p_locale_xhtml('draft');
267    $form = new Doku_Form(array('id' => 'dw__editform'));
268    $form->addHidden('id', $ID);
269    $form->addHidden('date', $draft['date']);
270    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
271    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
272    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
273    $form->addElement(form_makeCloseTag('div'));
274    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
275    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
276    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
277    html_form('draft', $form);
278}
279
280/**
281 * Highlights searchqueries in HTML code
282 *
283 * @author Andreas Gohr <andi@splitbrain.org>
284 * @author Harry Fuecks <hfuecks@gmail.com>
285 */
286function html_hilight($html,$phrases){
287    $phrases = array_filter((array) $phrases);
288    $regex = join('|',array_map('preg_quote_cb',$phrases));
289
290    if ($regex === '') return $html;
291    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
292    return $html;
293}
294
295/**
296 * Callback used by html_hilight()
297 *
298 * @author Harry Fuecks <hfuecks@gmail.com>
299 */
300function html_hilight_callback($m) {
301    $hlight = unslash($m[0]);
302    if ( !isset($m[2])) {
303        $hlight = '<span class="search_hit">'.$hlight.'</span>';
304    }
305    return $hlight;
306}
307
308/**
309 * Run a search and display the result
310 *
311 * @author Andreas Gohr <andi@splitbrain.org>
312 */
313function html_search(){
314    global $conf;
315    global $QUERY;
316    global $ID;
317    global $lang;
318
319    print p_locale_xhtml('searchpage');
320    flush();
321
322    //check if search is restricted to namespace
323    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
324        $id = cleanID($match[1]);
325    } else {
326        $id = cleanID($QUERY);
327    }
328
329    //show progressbar
330    print '<div class="centeralign" id="dw__loading">'.NL;
331    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
332    print 'showLoadBar();'.NL;
333    print '//--><!]]></script>'.NL;
334    print '<br /></div>'.NL;
335    flush();
336
337    //do quick pagesearch
338    $data = array();
339
340    if($id) $data = ft_pageLookup($id,true,useHeading('navigation'));
341    if(count($data)){
342        print '<div class="search_quickresult">';
343        print '<h3>'.$lang['quickhits'].':</h3>';
344        print '<ul class="search_quickhits">';
345        foreach($data as $id => $title){
346            print '<li> ';
347            if (useHeading('navigation')) {
348                $name = $title;
349            }else{
350                $ns = getNS($id);
351                if($ns){
352                    $name = shorten(noNS($id), ' ('.$ns.')',30);
353                }else{
354                    $name = $id;
355                }
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    global $conf;
711    global $ID;
712    $dir = $conf['datadir'];
713    $ns  = cleanID($ns);
714    #fixme use appropriate function
715    if(empty($ns)){
716        $ns = dirname(str_replace(':','/',$ID));
717        if($ns == '.') $ns ='';
718    }
719    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
720
721    echo p_locale_xhtml('index');
722    echo '<div id="index__tree">';
723
724    $data = array();
725    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
726    echo html_buildlist($data,'idx','html_list_index','html_li_index');
727
728    echo '</div>';
729}
730
731/**
732 * Index item formatter
733 *
734 * User function for html_buildlist()
735 *
736 * @author Andreas Gohr <andi@splitbrain.org>
737 */
738function html_list_index($item){
739    global $ID;
740    $ret = '';
741    $base = ':'.$item['id'];
742    $base = substr($base,strrpos($base,':')+1);
743    if($item['type']=='d'){
744        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
745        $ret .= $base;
746        $ret .= '</strong></a>';
747    }else{
748        $ret .= html_wikilink(':'.$item['id']);
749    }
750    return $ret;
751}
752
753/**
754 * Index List item
755 *
756 * This user function is used in html_build_lidt to build the
757 * <li> tags for namespaces when displaying the page index
758 * it gives different classes to opened or closed "folders"
759 *
760 * @author Andreas Gohr <andi@splitbrain.org>
761 */
762function html_li_index($item){
763    if($item['type'] == "f"){
764        return '<li class="level'.$item['level'].'">';
765    }elseif($item['open']){
766        return '<li class="open">';
767    }else{
768        return '<li class="closed">';
769    }
770}
771
772/**
773 * Default List item
774 *
775 * @author Andreas Gohr <andi@splitbrain.org>
776 */
777function html_li_default($item){
778    return '<li class="level'.$item['level'].'">';
779}
780
781/**
782 * Build an unordered list
783 *
784 * Build an unordered list from the given $data array
785 * Each item in the array has to have a 'level' property
786 * the item itself gets printed by the given $func user
787 * function. The second and optional function is used to
788 * print the <li> tag. Both user function need to accept
789 * a single item.
790 *
791 * Both user functions can be given as array to point to
792 * a member of an object.
793 *
794 * @author Andreas Gohr <andi@splitbrain.org>
795 */
796function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
797    $level = 0;
798    $opens = 0;
799    $ret   = '';
800
801    foreach ($data as $item){
802
803        if( $item['level'] > $level ){
804            //open new list
805            for($i=0; $i<($item['level'] - $level); $i++){
806                if ($i) $ret .= "<li class=\"clear\">\n";
807                $ret .= "\n<ul class=\"$class\">\n";
808            }
809        }elseif( $item['level'] < $level ){
810            //close last item
811            $ret .= "</li>\n";
812            for ($i=0; $i<($level - $item['level']); $i++){
813                //close higher lists
814                $ret .= "</ul>\n</li>\n";
815            }
816        }else{
817            //close last item
818            $ret .= "</li>\n";
819        }
820
821        //remember current level
822        $level = $item['level'];
823
824        //print item
825        $ret .= call_user_func($lifunc,$item);
826        $ret .= '<div class="li">';
827
828        $ret .= call_user_func($func,$item);
829        $ret .= '</div>';
830    }
831
832    //close remaining items and lists
833    for ($i=0; $i < $level; $i++){
834        $ret .= "</li></ul>\n";
835    }
836
837    return $ret;
838}
839
840/**
841 * display backlinks
842 *
843 * @author Andreas Gohr <andi@splitbrain.org>
844 * @author Michael Klier <chi@chimeric.de>
845 */
846function html_backlinks(){
847    global $ID;
848    global $conf;
849    global $lang;
850
851    print p_locale_xhtml('backlinks');
852
853    $data = ft_backlinks($ID);
854
855    if(!empty($data)) {
856        print '<ul class="idx">';
857        foreach($data as $blink){
858            print '<li><div class="li">';
859            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
860            print '</div></li>';
861        }
862        print '</ul>';
863    } else {
864        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
865    }
866}
867
868/**
869 * show diff
870 *
871 * @author Andreas Gohr <andi@splitbrain.org>
872 */
873function html_diff($text='',$intro=true){
874    global $ID;
875    global $REV;
876    global $lang;
877    global $conf;
878
879    // we're trying to be clever here, revisions to compare can be either
880    // given as rev and rev2 parameters, with rev2 being optional. Or in an
881    // array in rev2.
882    $rev1 = $REV;
883
884    if(is_array($_REQUEST['rev2'])){
885        $rev1 = (int) $_REQUEST['rev2'][0];
886        $rev2 = (int) $_REQUEST['rev2'][1];
887
888        if(!$rev1){
889            $rev1 = $rev2;
890            unset($rev2);
891        }
892    }else{
893        $rev2 = (int) $_REQUEST['rev2'];
894    }
895
896    if($text){                      // compare text to the most current revision
897        $l_rev   = '';
898        $l_text  = rawWiki($ID,'');
899        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
900            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
901            $lang['current'];
902
903        $r_rev   = '';
904        $r_text  = cleanText($text);
905        $r_head  = $lang['yours'];
906    }else{
907        if($rev1 && $rev2){            // two specific revisions wanted
908            // make sure order is correct (older on the left)
909            if($rev1 < $rev2){
910                $l_rev = $rev1;
911                $r_rev = $rev2;
912            }else{
913                $l_rev = $rev2;
914                $r_rev = $rev1;
915            }
916        }elseif($rev1){                // single revision given, compare to current
917            $r_rev = '';
918            $l_rev = $rev1;
919        }else{                        // no revision was given, compare previous to current
920            $r_rev = '';
921            $revs = getRevisions($ID, 0, 1);
922            $l_rev = $revs[0];
923            $REV = $l_rev; // store revision back in $REV
924        }
925
926        // when both revisions are empty then the page was created just now
927        if(!$l_rev && !$r_rev){
928            $l_text = '';
929        }else{
930            $l_text = rawWiki($ID,$l_rev);
931        }
932        $r_text = rawWiki($ID,$r_rev);
933
934        if(!$l_rev){
935            $l_head = '&mdash;';
936        }else{
937            $l_info   = getRevisionInfo($ID,$l_rev,true);
938            if($l_info['user']){
939                $l_user = editorinfo($l_info['user']);
940                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
941            } else {
942                $l_user = $l_info['ip'];
943            }
944            $l_user  = '<span class="user">'.$l_user.'</span>';
945            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
946            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
947
948            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
949            $ID.' ['.dformat($l_rev).']</a>'.
950            '<br />'.$l_user.' '.$l_sum;
951        }
952
953        if($r_rev){
954            $r_info   = getRevisionInfo($ID,$r_rev,true);
955            if($r_info['user']){
956                $r_user = editorinfo($r_info['user']);
957                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
958            } else {
959                $r_user = $r_info['ip'];
960            }
961            $r_user = '<span class="user">'.$r_user.'</span>';
962            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
963            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
964
965            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
966            $ID.' ['.dformat($r_rev).']</a>'.
967            '<br />'.$r_user.' '.$r_sum;
968        }elseif($_rev = @filemtime(wikiFN($ID))){
969            $_info   = getRevisionInfo($ID,$_rev,true);
970            if($_info['user']){
971                $_user = editorinfo($_info['user']);
972                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
973            } else {
974                $_user = $_info['ip'];
975            }
976            $_user = '<span class="user">'.$_user.'</span>';
977            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
978            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
979
980            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
981            $ID.' ['.dformat($_rev).']</a> '.
982            '('.$lang['current'].')'.
983            '<br />'.$_user.' '.$_sum;
984        }else{
985            $r_head = '&mdash; ('.$lang['current'].')';
986        }
987    }
988
989    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
990        explode("\n",htmlspecialchars($r_text)));
991
992    $tdf = new TableDiffFormatter();
993    if($intro) print p_locale_xhtml('diff');
994
995    if (!$text) {
996        ptln('<div class="level1"><p>');
997        ptln('  <a class="wikilink1" href="'.wl($ID, 'do=diff&rev2[]='.$l_rev.'&rev2[]='.$r_rev).'">'.$lang['difflink'].'</a>');
998        ptln('</p></div>');
999    }
1000    ?>
1001    <table class="diff">
1002    <tr>
1003    <th colspan="2" <?php echo $l_minor?>>
1004    <?php echo $l_head?>
1005    </th>
1006    <th colspan="2" <?php echo $r_minor?>>
1007    <?php echo $r_head?>
1008    </th>
1009    </tr>
1010    <?php echo $tdf->format($df)?>
1011    </table>
1012    <?php
1013}
1014
1015/**
1016 * show warning on conflict detection
1017 *
1018 * @author Andreas Gohr <andi@splitbrain.org>
1019 */
1020function html_conflict($text,$summary){
1021    global $ID;
1022    global $lang;
1023
1024    print p_locale_xhtml('conflict');
1025    $form = new Doku_Form(array('id' => 'dw__editform'));
1026    $form->addHidden('id', $ID);
1027    $form->addHidden('wikitext', $text);
1028    $form->addHidden('summary', $summary);
1029    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1030    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1031    html_form('conflict', $form);
1032    print '<br /><br /><br /><br />'.NL;
1033}
1034
1035/**
1036 * Prints the global message array
1037 *
1038 * @author Andreas Gohr <andi@splitbrain.org>
1039 */
1040function html_msgarea(){
1041    global $MSG;
1042    if(!isset($MSG)) return;
1043
1044    $shown = array();
1045    foreach($MSG as $msg){
1046        $hash = md5($msg['msg']);
1047        if(isset($shown[$hash])) continue; // skip double messages
1048        print '<div class="'.$msg['lvl'].'">';
1049        print $msg['msg'];
1050        print '</div>';
1051        $shown[$hash] = 1;
1052    }
1053}
1054
1055/**
1056 * Prints the registration form
1057 *
1058 * @author Andreas Gohr <andi@splitbrain.org>
1059 */
1060function html_register(){
1061    global $lang;
1062    global $conf;
1063    global $ID;
1064
1065    print p_locale_xhtml('register');
1066    print '<div class="centeralign">'.NL;
1067    $form = new Doku_Form(array('id' => 'dw__register'));
1068    $form->startFieldset($lang['register']);
1069    $form->addHidden('do', 'register');
1070    $form->addHidden('save', '1');
1071    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1072    if (!$conf['autopasswd']) {
1073        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1074        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1075    }
1076    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1077    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1078    $form->addElement(form_makeButton('submit', '', $lang['register']));
1079    $form->endFieldset();
1080    html_form('register', $form);
1081
1082    print '</div>'.NL;
1083}
1084
1085/**
1086 * Print the update profile form
1087 *
1088 * @author Christopher Smith <chris@jalakai.co.uk>
1089 * @author Andreas Gohr <andi@splitbrain.org>
1090 */
1091function html_updateprofile(){
1092    global $lang;
1093    global $conf;
1094    global $ID;
1095    global $INFO;
1096    global $auth;
1097
1098    print p_locale_xhtml('updateprofile');
1099
1100    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1101    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1102    print '<div class="centeralign">'.NL;
1103    $form = new Doku_Form(array('id' => 'dw__register'));
1104    $form->startFieldset($lang['profile']);
1105    $form->addHidden('do', 'profile');
1106    $form->addHidden('save', '1');
1107    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1108    $attr = array('size'=>'50');
1109    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1110    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1111    $attr = array('size'=>'50');
1112    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1113    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1114    $form->addElement(form_makeTag('br'));
1115    if ($auth->canDo('modPass')) {
1116        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1117        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1118    }
1119    if ($conf['profileconfirm']) {
1120        $form->addElement(form_makeTag('br'));
1121        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1122    }
1123    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1124    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1125    $form->endFieldset();
1126    html_form('updateprofile', $form);
1127    print '</div>'.NL;
1128}
1129
1130/**
1131 * Preprocess edit form data
1132 *
1133 * @author   Andreas Gohr <andi@splitbrain.org>
1134 *
1135 * @triggers HTML_EDITFORM_OUTPUT
1136 */
1137function html_edit(){
1138    global $ID;
1139    global $REV;
1140    global $DATE;
1141    global $PRE;
1142    global $SUF;
1143    global $INFO;
1144    global $SUM;
1145    global $lang;
1146    global $conf;
1147    global $TEXT;
1148    global $RANGE;
1149
1150    if (isset($_REQUEST['changecheck'])) {
1151        $check = $_REQUEST['changecheck'];
1152    } elseif(!$INFO['exists']){
1153        // $TEXT has been loaded from page template
1154        $check = md5('');
1155    } else {
1156        $check = md5($TEXT);
1157    }
1158    $mod = md5($TEXT) !== $check;
1159
1160    $wr = $INFO['writable'] && !$INFO['locked'];
1161    $include = 'edit';
1162    if($wr){
1163        if ($REV) $include = 'editrev';
1164    }else{
1165        // check pseudo action 'source'
1166        if(!actionOK('source')){
1167            msg('Command disabled: source',-1);
1168            return;
1169        }
1170        $include = 'read';
1171    }
1172
1173    global $license;
1174
1175    $form = new Doku_Form(array('id' => 'dw__editform'));
1176    $form->addHidden('id', $ID);
1177    $form->addHidden('rev', $REV);
1178    $form->addHidden('date', $DATE);
1179    $form->addHidden('prefix', $PRE);
1180    $form->addHidden('suffix', $SUF);
1181    $form->addHidden('changecheck', $check);
1182
1183    $data = array('form' => $form,
1184                  'wr'   => $wr,
1185                  'media_manager' => true,
1186                  'target' => (isset($_REQUEST['target']) && $wr &&
1187                               $RANGE !== '') ? $_REQUEST['target'] : 'section',
1188                  'intro_locale' => $include);
1189
1190    if ($data['target'] !== 'section') {
1191        // Only emit event if page is writable, section edit data is valid and
1192        // edit target is not section.
1193        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1194    } else {
1195        html_edit_form($data);
1196    }
1197    if (isset($data['intro_locale'])) {
1198        echo p_locale_xhtml($data['intro_locale']);
1199    }
1200
1201    $form->addHidden('target', $data['target']);
1202    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1203    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1204    $form->addElement(form_makeCloseTag('div'));
1205    if ($wr) {
1206        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1207        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1208        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1209        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1210        $form->addElement(form_makeCloseTag('div'));
1211        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1212        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1213        $elem = html_minoredit();
1214        if ($elem) $form->addElement($elem);
1215        $form->addElement(form_makeCloseTag('div'));
1216    }
1217    $form->addElement(form_makeCloseTag('div'));
1218    if($wr && $conf['license']){
1219        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1220        $out  = $lang['licenseok'];
1221        $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1222        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1223        $out .= '> '.$license[$conf['license']]['name'].'</a>';
1224        $form->addElement($out);
1225        $form->addElement(form_makeCloseTag('div'));
1226    }
1227
1228    if ($wr) {
1229        // sets changed to true when previewed
1230        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
1231        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1232        echo '//--><!]]></script>' . NL;
1233    } ?>
1234    <div style="width:99%;">
1235
1236    <div class="toolbar">
1237    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1238    <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']?>"
1239        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1240
1241    </div>
1242    <?php
1243
1244    html_form('edit', $form);
1245    print '</div>'.NL;
1246}
1247
1248/**
1249 * Display the default edit form
1250 *
1251 * Is the default action for HTML_EDIT_FORMSELECTION.
1252 */
1253function html_edit_form($param) {
1254    global $TEXT;
1255
1256    if ($param['target'] !== 'section') {
1257        msg('No editor for edit target ' . $param['target'] . ' found.', -1);
1258    }
1259
1260    $attr = array('tabindex'=>'1');
1261    if (!$param['wr']) $attr['readonly'] = 'readonly';
1262
1263    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1264}
1265
1266/**
1267 * Adds a checkbox for minor edits for logged in users
1268 *
1269 * @author Andreas Gohr <andi@splitbrain.org>
1270 */
1271function html_minoredit(){
1272    global $conf;
1273    global $lang;
1274    // minor edits are for logged in users only
1275    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1276        return false;
1277    }
1278
1279    $p = array();
1280    $p['tabindex'] = 3;
1281    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1282    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1283}
1284
1285/**
1286 * prints some debug info
1287 *
1288 * @author Andreas Gohr <andi@splitbrain.org>
1289 */
1290function html_debug(){
1291    global $conf;
1292    global $lang;
1293    global $auth;
1294    global $INFO;
1295
1296    //remove sensitive data
1297    $cnf = $conf;
1298    debug_guard($cnf);
1299    $nfo = $INFO;
1300    debug_guard($nfo);
1301    $ses = $_SESSION;
1302    debug_guard($ses);
1303
1304    print '<html><body>';
1305
1306    print '<p>When reporting bugs please send all the following ';
1307    print 'output as a mail to andi@splitbrain.org ';
1308    print 'The best way to do this is to save this page in your browser</p>';
1309
1310    print '<b>$INFO:</b><pre>';
1311    print_r($nfo);
1312    print '</pre>';
1313
1314    print '<b>$_SERVER:</b><pre>';
1315    print_r($_SERVER);
1316    print '</pre>';
1317
1318    print '<b>$conf:</b><pre>';
1319    print_r($cnf);
1320    print '</pre>';
1321
1322    print '<b>DOKU_BASE:</b><pre>';
1323    print DOKU_BASE;
1324    print '</pre>';
1325
1326    print '<b>abs DOKU_BASE:</b><pre>';
1327    print DOKU_URL;
1328    print '</pre>';
1329
1330    print '<b>rel DOKU_BASE:</b><pre>';
1331    print dirname($_SERVER['PHP_SELF']).'/';
1332    print '</pre>';
1333
1334    print '<b>PHP Version:</b><pre>';
1335    print phpversion();
1336    print '</pre>';
1337
1338    print '<b>locale:</b><pre>';
1339    print setlocale(LC_ALL,0);
1340    print '</pre>';
1341
1342    print '<b>encoding:</b><pre>';
1343    print $lang['encoding'];
1344    print '</pre>';
1345
1346    if($auth){
1347        print '<b>Auth backend capabilities:</b><pre>';
1348        print_r($auth->cando);
1349        print '</pre>';
1350    }
1351
1352    print '<b>$_SESSION:</b><pre>';
1353    print_r($ses);
1354    print '</pre>';
1355
1356    print '<b>Environment:</b><pre>';
1357    print_r($_ENV);
1358    print '</pre>';
1359
1360    print '<b>PHP settings:</b><pre>';
1361    $inis = ini_get_all();
1362    print_r($inis);
1363    print '</pre>';
1364
1365    print '</body></html>';
1366}
1367
1368/**
1369 * List available Administration Tasks
1370 *
1371 * @author Andreas Gohr <andi@splitbrain.org>
1372 * @author Håkan Sandell <hakan.sandell@home.se>
1373 */
1374function html_admin(){
1375    global $ID;
1376    global $INFO;
1377    global $lang;
1378    global $conf;
1379    global $auth;
1380
1381    // build menu of admin functions from the plugins that handle them
1382    $pluginlist = plugin_list('admin');
1383    $menu = array();
1384    foreach ($pluginlist as $p) {
1385        if($obj =& plugin_load('admin',$p) === null) continue;
1386
1387        // check permissions
1388        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1389
1390        $menu[$p] = array('plugin' => $p,
1391                'prompt' => $obj->getMenuText($conf['lang']),
1392                'sort' => $obj->getMenuSort()
1393                );
1394    }
1395
1396    print p_locale_xhtml('admin');
1397
1398    // Admin Tasks
1399    if($INFO['isadmin']){
1400        ptln('<ul class="admin_tasks">');
1401
1402        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1403            ptln('  <li class="admin_usermanager"><div class="li">'.
1404                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1405                    $menu['usermanager']['prompt'].'</a></div></li>');
1406        }
1407        unset($menu['usermanager']);
1408
1409        if($menu['acl']){
1410            ptln('  <li class="admin_acl"><div class="li">'.
1411                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1412                    $menu['acl']['prompt'].'</a></div></li>');
1413        }
1414        unset($menu['acl']);
1415
1416        if($menu['plugin']){
1417            ptln('  <li class="admin_plugin"><div class="li">'.
1418                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
1419                    $menu['plugin']['prompt'].'</a></div></li>');
1420        }
1421        unset($menu['plugin']);
1422
1423        if($menu['config']){
1424            ptln('  <li class="admin_config"><div class="li">'.
1425                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1426                    $menu['config']['prompt'].'</a></div></li>');
1427        }
1428        unset($menu['config']);
1429    }
1430    ptln('</ul>');
1431
1432    // Manager Tasks
1433    ptln('<ul class="admin_tasks">');
1434
1435    if($menu['revert']){
1436        ptln('  <li class="admin_revert"><div class="li">'.
1437                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1438                $menu['revert']['prompt'].'</a></div></li>');
1439    }
1440    unset($menu['revert']);
1441
1442    if($menu['popularity']){
1443        ptln('  <li class="admin_popularity"><div class="li">'.
1444                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1445                $menu['popularity']['prompt'].'</a></div></li>');
1446    }
1447    unset($menu['popularity']);
1448
1449    ptln('</ul>');
1450
1451    // print the rest as sorted list
1452    if(count($menu)){
1453        usort($menu, 'p_sort_modes');
1454        // output the menu
1455        ptln('<div class="clearer"></div>');
1456        print p_locale_xhtml('adminplugins');
1457        ptln('<ul>');
1458        foreach ($menu as $item) {
1459            if (!$item['prompt']) continue;
1460            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1461        }
1462        ptln('</ul>');
1463    }
1464}
1465
1466/**
1467 * Form to request a new password for an existing account
1468 *
1469 * @author Benoit Chesneau <benoit@bchesneau.info>
1470 */
1471function html_resendpwd() {
1472    global $lang;
1473    global $conf;
1474    global $ID;
1475
1476    print p_locale_xhtml('resendpwd');
1477    print '<div class="centeralign">'.NL;
1478    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1479    $form->startFieldset($lang['resendpwd']);
1480    $form->addHidden('do', 'resendpwd');
1481    $form->addHidden('save', '1');
1482    $form->addElement(form_makeTag('br'));
1483    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1484    $form->addElement(form_makeTag('br'));
1485    $form->addElement(form_makeTag('br'));
1486    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1487    $form->endFieldset();
1488    html_form('resendpwd', $form);
1489    print '</div>'.NL;
1490}
1491
1492/**
1493 * Return the TOC rendered to XHTML
1494 *
1495 * @author Andreas Gohr <andi@splitbrain.org>
1496 */
1497function html_TOC($toc){
1498    if(!count($toc)) return '';
1499    global $lang;
1500    $out  = '<!-- TOC START -->'.DOKU_LF;
1501    $out .= '<div class="toc">'.DOKU_LF;
1502    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1503    $out .= $lang['toc'];
1504    $out .= '</div>'.DOKU_LF;
1505    $out .= '<div id="toc__inside">'.DOKU_LF;
1506    $out .= html_buildlist($toc,'toc','html_list_toc');
1507    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1508    $out .= '<!-- TOC END -->'.DOKU_LF;
1509    return $out;
1510}
1511
1512/**
1513 * Callback for html_buildlist
1514 */
1515function html_list_toc($item){
1516    if(isset($item['hid'])){
1517        $link = '#'.$item['hid'];
1518    }else{
1519        $link = $item['link'];
1520    }
1521
1522    return '<span class="li"><a href="'.$link.'" class="toc">'.
1523        hsc($item['title']).'</a></span>';
1524}
1525
1526/**
1527 * Helper function to build TOC items
1528 *
1529 * Returns an array ready to be added to a TOC array
1530 *
1531 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1532 * @param string $text  - what to display in the TOC
1533 * @param int    $level - nesting level
1534 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1535 */
1536function html_mktocitem($link, $text, $level, $hash='#'){
1537    global $conf;
1538    return  array( 'link'  => $hash.$link,
1539            'title' => $text,
1540            'type'  => 'ul',
1541            'level' => $level);
1542}
1543
1544/**
1545 * Output a Doku_Form object.
1546 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1547 *
1548 * @author Tom N Harris <tnharris@whoopdedo.org>
1549 */
1550function html_form($name, &$form) {
1551    // Safety check in case the caller forgets.
1552    $form->endFieldset();
1553    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1554}
1555
1556/**
1557 * Form print function.
1558 * Just calls printForm() on the data object.
1559 */
1560function html_form_output($data) {
1561    $data->printForm();
1562}
1563
1564/**
1565 * Embed a flash object in HTML
1566 *
1567 * This will create the needed HTML to embed a flash movie in a cross browser
1568 * compatble way using valid XHTML
1569 *
1570 * The parameters $params, $flashvars and $atts need to be associative arrays.
1571 * No escaping needs to be done for them. The alternative content *has* to be
1572 * escaped because it is used as is. If no alternative content is given
1573 * $lang['noflash'] is used.
1574 *
1575 * @author Andreas Gohr <andi@splitbrain.org>
1576 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1577 *
1578 * @param string $swf      - the SWF movie to embed
1579 * @param int $width       - width of the flash movie in pixels
1580 * @param int $height      - height of the flash movie in pixels
1581 * @param array $params    - additional parameters (<param>)
1582 * @param array $flashvars - parameters to be passed in the flashvar parameter
1583 * @param array $atts      - additional attributes for the <object> tag
1584 * @param string $alt      - alternative content (is NOT automatically escaped!)
1585 * @returns string         - the XHTML markup
1586 */
1587function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1588    global $lang;
1589
1590    $out = '';
1591
1592    // prepare the object attributes
1593    if(is_null($atts)) $atts = array();
1594    $atts['width']  = (int) $width;
1595    $atts['height'] = (int) $height;
1596    if(!$atts['width'])  $atts['width']  = 425;
1597    if(!$atts['height']) $atts['height'] = 350;
1598
1599    // add object attributes for standard compliant browsers
1600    $std = $atts;
1601    $std['type'] = 'application/x-shockwave-flash';
1602    $std['data'] = $swf;
1603
1604    // add object attributes for IE
1605    $ie  = $atts;
1606    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1607
1608    // open object (with conditional comments)
1609    $out .= '<!--[if !IE]> -->'.NL;
1610    $out .= '<object '.buildAttributes($std).'>'.NL;
1611    $out .= '<!-- <![endif]-->'.NL;
1612    $out .= '<!--[if IE]>'.NL;
1613    $out .= '<object '.buildAttributes($ie).'>'.NL;
1614    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1615    $out .= '<!--><!-- -->'.NL;
1616
1617    // print params
1618    if(is_array($params)) foreach($params as $key => $val){
1619        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1620    }
1621
1622    // add flashvars
1623    if(is_array($flashvars)){
1624        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1625    }
1626
1627    // alternative content
1628    if($alt){
1629        $out .= $alt.NL;
1630    }else{
1631        $out .= $lang['noflash'].NL;
1632    }
1633
1634    // finish
1635    $out .= '</object>'.NL;
1636    $out .= '<!-- <![endif]-->'.NL;
1637
1638    return $out;
1639}
1640
1641