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