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