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