xref: /dokuwiki/inc/html.php (revision 8e69fd30702f1101a9c70dbe6eac6f45f9af3970)
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 * @author Kate Arzamastseva <pshns@ukr.net>
419 */
420function html_revisions($first=0, $media_id = false){
421    global $ID;
422    global $INFO;
423    global $conf;
424    global $lang;
425    $id = $ID;
426    /* we need to get one additionally log entry to be able to
427     * decide if this is the last page or is there another one.
428     * see html_recent()
429     */
430    if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
431    else {
432        $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
433        $id = $media_id;
434    }
435
436    if(count($revisions)==0 && $first!=0){
437        $first=0;
438        if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1);
439        else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true);
440    }
441    $hasNext = false;
442    if (count($revisions)>$conf['recent']) {
443        $hasNext = true;
444        array_pop($revisions); // remove extra log entry
445    }
446
447    if (!$media_id) $date = dformat($INFO['lastmod']);
448    else $date = dformat(@filemtime(mediaFN($id)));
449
450    if (!$media_id) print p_locale_xhtml('revisions');
451
452    $form = new Doku_Form(array('id' => 'page__revisions'));
453    $form->addElement(form_makeOpenTag('ul'));
454
455    if (!$media_id) $exists = $INFO['exists'];
456    else $exists = @file_exists(mediaFN($id));
457
458    if($exists && $first==0){
459        if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
460            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
461        else
462            $form->addElement(form_makeOpenTag('li'));
463        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
464        $form->addElement(form_makeTag('input', array(
465                        'type' => 'checkbox',
466                        'name' => 'rev2[]',
467                        'value' => 'current')));
468
469        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
470        $form->addElement($date);
471        $form->addElement(form_makeCloseTag('span'));
472
473        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
474
475        $form->addElement(form_makeOpenTag('a', array(
476                        'class' => 'wikilink1',
477                        'href'  => wl($id))));
478        $form->addElement($id);
479        $form->addElement(form_makeCloseTag('a'));
480
481        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
482        $form->addElement(' &ndash; ');
483        $form->addElement(htmlspecialchars($INFO['sum']));
484        $form->addElement(form_makeCloseTag('span'));
485
486        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
487        ///
488        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
489        $form->addElement(form_makeCloseTag('span'));
490
491        $form->addElement('('.$lang['current'].')');
492        $form->addElement(form_makeCloseTag('div'));
493        $form->addElement(form_makeCloseTag('li'));
494    }
495
496    foreach($revisions as $rev){
497        $date   = dformat($rev);
498        $info   = getRevisionInfo($id,$rev,true);
499        if (!$media_id) $exists = page_exists($id,$rev);
500        else $exists = @file_exists(mediaFN($id,$rev));
501
502        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
503            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
504        else
505            $form->addElement(form_makeOpenTag('li'));
506        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
507        if($exists){
508            $form->addElement(form_makeTag('input', array(
509                            'type' => 'checkbox',
510                            'name' => 'rev2[]',
511                            'value' => $rev)));
512        }else{
513            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
514        }
515
516        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
517        $form->addElement($date);
518        $form->addElement(form_makeCloseTag('span'));
519
520        if($exists){
521            ///
522            $form->addElement(form_makeOpenTag('a', array('href' => wl($id,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
523            $form->addElement(form_makeTag('img', array(
524                            'src'    => DOKU_BASE.'lib/images/diff.png',
525                            'width'  => 15,
526                            'height' => 11,
527                            'title'  => $lang['diff'],
528                            'alt'    => $lang['diff'])));
529            $form->addElement(form_makeCloseTag('a'));
530            ///
531            $form->addElement(form_makeOpenTag('a', array('href' => wl($id,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
532            $form->addElement($id);
533            $form->addElement(form_makeCloseTag('a'));
534        }else{
535            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
536            $form->addElement($id);
537        }
538
539        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
540        $form->addElement(' &ndash; ');
541        $form->addElement(htmlspecialchars($info['sum']));
542        $form->addElement(form_makeCloseTag('span'));
543
544        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
545        if($info['user']){
546            $form->addElement(editorinfo($info['user']));
547            if(auth_ismanager()){
548                $form->addElement(' ('.$info['ip'].')');
549            }
550        }else{
551            $form->addElement($info['ip']);
552        }
553        $form->addElement(form_makeCloseTag('span'));
554
555        $form->addElement(form_makeCloseTag('div'));
556        $form->addElement(form_makeCloseTag('li'));
557    }
558    $form->addElement(form_makeCloseTag('ul'));
559    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
560    html_form('revisions', $form);
561
562    print '<div class="pagenav">';
563    $last = $first + $conf['recent'];
564    if ($first > 0) {
565        $first -= $conf['recent'];
566        if ($first < 0) $first = 0;
567        print '<div class="pagenav-prev">';
568        print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
569        print '</div>';
570    }
571    if ($hasNext) {
572        print '<div class="pagenav-next">';
573        print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
574        print '</div>';
575    }
576    print '</div>';
577
578}
579
580/**
581 * display recent changes
582 *
583 * @author Andreas Gohr <andi@splitbrain.org>
584 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
585 * @author Ben Coburn <btcoburn@silicodon.net>
586 * @author Kate Arzamastseva <pshns@ukr.net>
587 */
588function html_recent($first=0, $show_changes='both'){
589    global $conf;
590    global $lang;
591    global $ID;
592    /* we need to get one additionally log entry to be able to
593     * decide if this is the last page or is there another one.
594     * This is the cheapest solution to get this information.
595     */
596    if (!$show_changes || $show_changes == 'both') $flags = RECENTS_MEDIA_PAGES_MIXED;
597    if ($show_changes == 'mediafiles') $flags = RECENTS_MEDIA_CHANGES;
598    if ($show_changes == 'pages') $flags = 0;
599
600    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
601    if(count($recents) == 0 && $first != 0){
602        $first=0;
603        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
604    }
605    $hasNext = false;
606    if (count($recents)>$conf['recent']) {
607        $hasNext = true;
608        array_pop($recents); // remove extra log entry
609    }
610
611    print p_locale_xhtml('recent');
612
613    if (getNS($ID) != '')
614        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
615
616    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
617    $form->addHidden('sectok', null);
618    $form->addHidden('do', 'recent');
619    $form->addHidden('id', $ID);
620
621    $form->addElement(form_makeOpenTag('div', array('class' => 'changestypenav')));
622    $attrs = array('name' => 'show_changes',
623                   'value' => 'pages',
624                   '_text' => $lang['pages_changes']);
625    if ($show_changes == 'pages') $attrs['checked'] = 'checked';
626    $form->addElement(form_radiofield($attrs));
627    $attrs = array('name' => 'show_changes',
628                   'value' => 'mediafiles',
629                   '_text' => $lang['media_changes']);
630    if ($show_changes == 'mediafiles') $attrs['checked'] = 'checked';
631    $form->addElement(form_radiofield($attrs));
632    $attrs = array('name' => 'show_changes',
633                   'value' => 'both',
634                   '_text' => $lang['both_changes'] );
635    if (empty($show_changes) || $show_changes == 'both') $attrs['checked'] = 'checked';
636    $form->addElement(form_radiofield($attrs));
637    $form->addElement(form_makeTag('input', array(
638                    'type'  => 'submit',
639                    'value' => $lang['btn_apply'],
640                    'title' => $lang['btn_apply'],
641                    'class' => 'button'
642                    )));
643    $form->addElement(form_makeCloseTag('div'));
644
645    $form->addElement(form_makeOpenTag('ul'));
646
647    foreach($recents as $recent){
648        $date = dformat($recent['date']);
649        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
650            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
651        else
652            $form->addElement(form_makeOpenTag('li'));
653
654        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
655
656        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
657        $form->addElement($date);
658        $form->addElement(form_makeCloseTag('span'));
659
660        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
661        $form->addElement(form_makeTag('img', array(
662                        'src'   => DOKU_BASE.'lib/images/diff.png',
663                        'width' => 15,
664                        'height'=> 11,
665                        'title' => $lang['diff'],
666                        'alt'   => $lang['diff']
667                        )));
668        $form->addElement(form_makeCloseTag('a'));
669
670        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
671        $form->addElement(form_makeTag('img', array(
672                        'src'   => DOKU_BASE.'lib/images/history.png',
673                        'width' => 12,
674                        'height'=> 14,
675                        'title' => $lang['btn_revs'],
676                        'alt'   => $lang['btn_revs']
677                        )));
678        $form->addElement(form_makeCloseTag('a'));
679
680        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
681
682        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
683        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
684        $form->addElement(form_makeCloseTag('span'));
685
686        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
687        if($recent['user']){
688            $form->addElement(editorinfo($recent['user']));
689            if(auth_ismanager()){
690                $form->addElement(' ('.$recent['ip'].')');
691            }
692        }else{
693            $form->addElement($recent['ip']);
694        }
695        $form->addElement(form_makeCloseTag('span'));
696
697        $form->addElement(form_makeCloseTag('div'));
698        $form->addElement(form_makeCloseTag('li'));
699    }
700    $form->addElement(form_makeCloseTag('ul'));
701
702    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
703    $last = $first + $conf['recent'];
704    if ($first > 0) {
705        $first -= $conf['recent'];
706        if ($first < 0) $first = 0;
707        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
708        $form->addElement(form_makeTag('input', array(
709                    'type'  => 'submit',
710                    'name'  => 'first['.$first.']',
711                    'value' => $lang['btn_newer'],
712                    'accesskey' => 'n',
713                    'title' => $lang['btn_newer'].' [N]',
714                    'class' => 'button'
715                    )));
716        $form->addElement(form_makeCloseTag('div'));
717    }
718    if ($hasNext) {
719        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
720        $form->addElement(form_makeTag('input', array(
721                        'type'  => 'submit',
722                        'name'  => 'first['.$last.']',
723                        'value' => $lang['btn_older'],
724                        'accesskey' => 'p',
725                        'title' => $lang['btn_older'].' [P]',
726                        'class' => 'button'
727                        )));
728        $form->addElement(form_makeCloseTag('div'));
729    }
730    $form->addElement(form_makeCloseTag('div'));
731    html_form('recent', $form);
732}
733
734/**
735 * Display page index
736 *
737 * @author Andreas Gohr <andi@splitbrain.org>
738 */
739function html_index($ns){
740    global $conf;
741    global $ID;
742    $dir = $conf['datadir'];
743    $ns  = cleanID($ns);
744    #fixme use appropriate function
745    if(empty($ns)){
746        $ns = dirname(str_replace(':','/',$ID));
747        if($ns == '.') $ns ='';
748    }
749    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
750
751    echo p_locale_xhtml('index');
752    echo '<div id="index__tree">';
753
754    $data = array();
755    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
756    echo html_buildlist($data,'idx','html_list_index','html_li_index');
757
758    echo '</div>';
759}
760
761/**
762 * Index item formatter
763 *
764 * User function for html_buildlist()
765 *
766 * @author Andreas Gohr <andi@splitbrain.org>
767 */
768function html_list_index($item){
769    global $ID;
770    $ret = '';
771    $base = ':'.$item['id'];
772    $base = substr($base,strrpos($base,':')+1);
773    if($item['type']=='d'){
774        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
775        $ret .= $base;
776        $ret .= '</strong></a>';
777    }else{
778        $ret .= html_wikilink(':'.$item['id']);
779    }
780    return $ret;
781}
782
783/**
784 * Index List item
785 *
786 * This user function is used in html_build_lidt to build the
787 * <li> tags for namespaces when displaying the page index
788 * it gives different classes to opened or closed "folders"
789 *
790 * @author Andreas Gohr <andi@splitbrain.org>
791 */
792function html_li_index($item){
793    if($item['type'] == "f"){
794        return '<li class="level'.$item['level'].'">';
795    }elseif($item['open']){
796        return '<li class="open">';
797    }else{
798        return '<li class="closed">';
799    }
800}
801
802/**
803 * Default List item
804 *
805 * @author Andreas Gohr <andi@splitbrain.org>
806 */
807function html_li_default($item){
808    return '<li class="level'.$item['level'].'">';
809}
810
811/**
812 * Build an unordered list
813 *
814 * Build an unordered list from the given $data array
815 * Each item in the array has to have a 'level' property
816 * the item itself gets printed by the given $func user
817 * function. The second and optional function is used to
818 * print the <li> tag. Both user function need to accept
819 * a single item.
820 *
821 * Both user functions can be given as array to point to
822 * a member of an object.
823 *
824 * @author Andreas Gohr <andi@splitbrain.org>
825 */
826function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
827    $level = 0;
828    $opens = 0;
829    $ret   = '';
830
831    foreach ($data as $item){
832
833        if( $item['level'] > $level ){
834            //open new list
835            for($i=0; $i<($item['level'] - $level); $i++){
836                if ($i) $ret .= "<li class=\"clear\">\n";
837                $ret .= "\n<ul class=\"$class\">\n";
838            }
839        }elseif( $item['level'] < $level ){
840            //close last item
841            $ret .= "</li>\n";
842            for ($i=0; $i<($level - $item['level']); $i++){
843                //close higher lists
844                $ret .= "</ul>\n</li>\n";
845            }
846        }else{
847            //close last item
848            $ret .= "</li>\n";
849        }
850
851        //remember current level
852        $level = $item['level'];
853
854        //print item
855        $ret .= call_user_func($lifunc,$item);
856        $ret .= '<div class="li">';
857
858        $ret .= call_user_func($func,$item);
859        $ret .= '</div>';
860    }
861
862    //close remaining items and lists
863    for ($i=0; $i < $level; $i++){
864        $ret .= "</li></ul>\n";
865    }
866
867    return $ret;
868}
869
870/**
871 * display backlinks
872 *
873 * @author Andreas Gohr <andi@splitbrain.org>
874 * @author Michael Klier <chi@chimeric.de>
875 */
876function html_backlinks(){
877    global $ID;
878    global $conf;
879    global $lang;
880
881    print p_locale_xhtml('backlinks');
882
883    $data = ft_backlinks($ID);
884
885    if(!empty($data)) {
886        print '<ul class="idx">';
887        foreach($data as $blink){
888            print '<li><div class="li">';
889            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
890            print '</div></li>';
891        }
892        print '</ul>';
893    } else {
894        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
895    }
896}
897
898/**
899 * show diff
900 *
901 * @author Andreas Gohr <andi@splitbrain.org>
902 * @param  string $text - compare with this text with most current version
903 * @param  bool   $intr - display the intro text
904 */
905function html_diff($text='',$intro=true,$type=null){
906    global $ID;
907    global $REV;
908    global $lang;
909    global $conf;
910
911    if(!$type) $type = $_REQUEST['difftype'];
912    if($type != 'inline') $type = 'sidebyside';
913
914    // we're trying to be clever here, revisions to compare can be either
915    // given as rev and rev2 parameters, with rev2 being optional. Or in an
916    // array in rev2.
917    $rev1 = $REV;
918
919    if(is_array($_REQUEST['rev2'])){
920        $rev1 = (int) $_REQUEST['rev2'][0];
921        $rev2 = (int) $_REQUEST['rev2'][1];
922
923        if(!$rev1){
924            $rev1 = $rev2;
925            unset($rev2);
926        }
927    }else{
928        $rev2 = (int) $_REQUEST['rev2'];
929    }
930
931    $r_minor = '';
932    $l_minor = '';
933
934    if($text){                      // compare text to the most current revision
935        $l_rev   = '';
936        $l_text  = rawWiki($ID,'');
937        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
938            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
939            $lang['current'];
940
941        $r_rev   = '';
942        $r_text  = cleanText($text);
943        $r_head  = $lang['yours'];
944    }else{
945        if($rev1 && $rev2){            // two specific revisions wanted
946            // make sure order is correct (older on the left)
947            if($rev1 < $rev2){
948                $l_rev = $rev1;
949                $r_rev = $rev2;
950            }else{
951                $l_rev = $rev2;
952                $r_rev = $rev1;
953            }
954        }elseif($rev1){                // single revision given, compare to current
955            $r_rev = '';
956            $l_rev = $rev1;
957        }else{                        // no revision was given, compare previous to current
958            $r_rev = '';
959            $revs = getRevisions($ID, 0, 1);
960            $l_rev = $revs[0];
961            $REV = $l_rev; // store revision back in $REV
962        }
963
964        // when both revisions are empty then the page was created just now
965        if(!$l_rev && !$r_rev){
966            $l_text = '';
967        }else{
968            $l_text = rawWiki($ID,$l_rev);
969        }
970        $r_text = rawWiki($ID,$r_rev);
971
972        if(!$l_rev){
973            $l_head = '&mdash;';
974        }else{
975            $l_info   = getRevisionInfo($ID,$l_rev,true);
976            if($l_info['user']){
977                $l_user = editorinfo($l_info['user']);
978                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
979            } else {
980                $l_user = $l_info['ip'];
981            }
982            $l_user  = '<span class="user">'.$l_user.'</span>';
983            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
984            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
985
986            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
987            $ID.' ['.dformat($l_rev).']</a>'.
988            '<br />'.$l_user.' '.$l_sum;
989        }
990
991        if($r_rev){
992            $r_info   = getRevisionInfo($ID,$r_rev,true);
993            if($r_info['user']){
994                $r_user = editorinfo($r_info['user']);
995                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
996            } else {
997                $r_user = $r_info['ip'];
998            }
999            $r_user = '<span class="user">'.$r_user.'</span>';
1000            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
1001            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1002
1003            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
1004            $ID.' ['.dformat($r_rev).']</a>'.
1005            '<br />'.$r_user.' '.$r_sum;
1006        }elseif($_rev = @filemtime(wikiFN($ID))){
1007            $_info   = getRevisionInfo($ID,$_rev,true);
1008            if($_info['user']){
1009                $_user = editorinfo($_info['user']);
1010                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
1011            } else {
1012                $_user = $_info['ip'];
1013            }
1014            $_user = '<span class="user">'.$_user.'</span>';
1015            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
1016            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1017
1018            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
1019            $ID.' ['.dformat($_rev).']</a> '.
1020            '('.$lang['current'].')'.
1021            '<br />'.$_user.' '.$_sum;
1022        }else{
1023            $r_head = '&mdash; ('.$lang['current'].')';
1024        }
1025    }
1026
1027    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
1028        explode("\n",htmlspecialchars($r_text)));
1029
1030    if($type == 'inline'){
1031        $tdf = new InlineDiffFormatter();
1032    } else {
1033        $tdf = new TableDiffFormatter();
1034    }
1035
1036
1037
1038    if($intro) print p_locale_xhtml('diff');
1039
1040    if (!$text) {
1041        ptln('<div class="diffoptions">');
1042
1043        $form = new Doku_Form(array('action'=>wl()));
1044        $form->addHidden('id',$ID);
1045        $form->addHidden('rev2[0]',$l_rev);
1046        $form->addHidden('rev2[1]',$r_rev);
1047        $form->addHidden('do','diff');
1048        $form->addElement(form_makeListboxField(
1049                            'difftype',
1050                            array(
1051                                'sidebyside' => $lang['diff_side'],
1052                                'inline'     => $lang['diff_inline']),
1053                            $type,
1054                            $lang['diff_type'],
1055                            '','',
1056                            array('class'=>'quickselect')));
1057        $form->addElement(form_makeButton('submit', 'diff','Go'));
1058        $form->printForm();
1059
1060
1061        $diffurl = wl($ID, array(
1062                        'do'       => 'diff',
1063                        'rev2[0]'  => $l_rev,
1064                        'rev2[1]'  => $r_rev,
1065                        'difftype' => $type,
1066                      ));
1067        ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>');
1068        ptln('</div>');
1069    }
1070    ?>
1071    <table class="diff diff_<?php echo $type?>">
1072    <tr>
1073    <th colspan="2" <?php echo $l_minor?>>
1074    <?php echo $l_head?>
1075    </th>
1076    <th colspan="2" <?php echo $r_minor?>>
1077    <?php echo $r_head?>
1078    </th>
1079    </tr>
1080    <?php echo $tdf->format($df)?>
1081    </table>
1082    <?php
1083}
1084
1085/**
1086 * show warning on conflict detection
1087 *
1088 * @author Andreas Gohr <andi@splitbrain.org>
1089 */
1090function html_conflict($text,$summary){
1091    global $ID;
1092    global $lang;
1093
1094    print p_locale_xhtml('conflict');
1095    $form = new Doku_Form(array('id' => 'dw__editform'));
1096    $form->addHidden('id', $ID);
1097    $form->addHidden('wikitext', $text);
1098    $form->addHidden('summary', $summary);
1099    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1100    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1101    html_form('conflict', $form);
1102    print '<br /><br /><br /><br />'.NL;
1103}
1104
1105/**
1106 * Prints the global message array
1107 *
1108 * @author Andreas Gohr <andi@splitbrain.org>
1109 */
1110function html_msgarea(){
1111    global $MSG, $MSG_shown;
1112    // store if the global $MSG has already been shown and thus HTML output has been started
1113    $MSG_shown = true;
1114
1115    if(!isset($MSG)) return;
1116
1117    $shown = array();
1118    foreach($MSG as $msg){
1119        $hash = md5($msg['msg']);
1120        if(isset($shown[$hash])) continue; // skip double messages
1121        print '<div class="'.$msg['lvl'].'">';
1122        print $msg['msg'];
1123        print '</div>';
1124        $shown[$hash] = 1;
1125    }
1126
1127    unset($GLOBALS['MSG']);
1128}
1129
1130/**
1131 * Prints the registration form
1132 *
1133 * @author Andreas Gohr <andi@splitbrain.org>
1134 */
1135function html_register(){
1136    global $lang;
1137    global $conf;
1138    global $ID;
1139
1140    print p_locale_xhtml('register');
1141    print '<div class="centeralign">'.NL;
1142    $form = new Doku_Form(array('id' => 'dw__register'));
1143    $form->startFieldset($lang['btn_register']);
1144    $form->addHidden('do', 'register');
1145    $form->addHidden('save', '1');
1146    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block', array('size'=>'50')));
1147    if (!$conf['autopasswd']) {
1148        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1149        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1150    }
1151    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1152    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1153    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1154    $form->endFieldset();
1155    html_form('register', $form);
1156
1157    print '</div>'.NL;
1158}
1159
1160/**
1161 * Print the update profile form
1162 *
1163 * @author Christopher Smith <chris@jalakai.co.uk>
1164 * @author Andreas Gohr <andi@splitbrain.org>
1165 */
1166function html_updateprofile(){
1167    global $lang;
1168    global $conf;
1169    global $ID;
1170    global $INFO;
1171    global $auth;
1172
1173    print p_locale_xhtml('updateprofile');
1174
1175    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
1176    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1177    print '<div class="centeralign">'.NL;
1178    $form = new Doku_Form(array('id' => 'dw__register'));
1179    $form->startFieldset($lang['profile']);
1180    $form->addHidden('do', 'profile');
1181    $form->addHidden('save', '1');
1182    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1183    $attr = array('size'=>'50');
1184    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1185    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
1186    $attr = array('size'=>'50');
1187    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1188    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1189    $form->addElement(form_makeTag('br'));
1190    if ($auth->canDo('modPass')) {
1191        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1192        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1193    }
1194    if ($conf['profileconfirm']) {
1195        $form->addElement(form_makeTag('br'));
1196        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1197    }
1198    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1199    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1200    $form->endFieldset();
1201    html_form('updateprofile', $form);
1202    print '</div>'.NL;
1203}
1204
1205/**
1206 * Preprocess edit form data
1207 *
1208 * @author   Andreas Gohr <andi@splitbrain.org>
1209 *
1210 * @triggers HTML_EDITFORM_OUTPUT
1211 */
1212function html_edit(){
1213    global $ID;
1214    global $REV;
1215    global $DATE;
1216    global $PRE;
1217    global $SUF;
1218    global $INFO;
1219    global $SUM;
1220    global $lang;
1221    global $conf;
1222    global $TEXT;
1223    global $RANGE;
1224
1225    if (isset($_REQUEST['changecheck'])) {
1226        $check = $_REQUEST['changecheck'];
1227    } elseif(!$INFO['exists']){
1228        // $TEXT has been loaded from page template
1229        $check = md5('');
1230    } else {
1231        $check = md5($TEXT);
1232    }
1233    $mod = md5($TEXT) !== $check;
1234
1235    $wr = $INFO['writable'] && !$INFO['locked'];
1236    $include = 'edit';
1237    if($wr){
1238        if ($REV) $include = 'editrev';
1239    }else{
1240        // check pseudo action 'source'
1241        if(!actionOK('source')){
1242            msg('Command disabled: source',-1);
1243            return;
1244        }
1245        $include = 'read';
1246    }
1247
1248    global $license;
1249
1250    $form = new Doku_Form(array('id' => 'dw__editform'));
1251    $form->addHidden('id', $ID);
1252    $form->addHidden('rev', $REV);
1253    $form->addHidden('date', $DATE);
1254    $form->addHidden('prefix', $PRE . '.');
1255    $form->addHidden('suffix', $SUF);
1256    $form->addHidden('changecheck', $check);
1257
1258    $data = array('form' => $form,
1259                  'wr'   => $wr,
1260                  'media_manager' => true,
1261                  'target' => (isset($_REQUEST['target']) && $wr &&
1262                               $RANGE !== '') ? $_REQUEST['target'] : 'section',
1263                  'intro_locale' => $include);
1264
1265    if ($data['target'] !== 'section') {
1266        // Only emit event if page is writable, section edit data is valid and
1267        // edit target is not section.
1268        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1269    } else {
1270        html_edit_form($data);
1271    }
1272    if (isset($data['intro_locale'])) {
1273        echo p_locale_xhtml($data['intro_locale']);
1274    }
1275
1276    $form->addHidden('target', $data['target']);
1277    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1278    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1279    $form->addElement(form_makeCloseTag('div'));
1280    if ($wr) {
1281        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1282        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1283        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1284        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1285        $form->addElement(form_makeCloseTag('div'));
1286        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1287        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1288        $elem = html_minoredit();
1289        if ($elem) $form->addElement($elem);
1290        $form->addElement(form_makeCloseTag('div'));
1291    }
1292    $form->addElement(form_makeCloseTag('div'));
1293    if($wr && $conf['license']){
1294        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1295        $out  = $lang['licenseok'];
1296        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1297        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1298        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1299        $form->addElement($out);
1300        $form->addElement(form_makeCloseTag('div'));
1301    }
1302
1303    if ($wr) {
1304        // sets changed to true when previewed
1305        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
1306        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1307        echo '//--><!]]></script>' . NL;
1308    } ?>
1309    <div style="width:99%;">
1310
1311    <div class="toolbar">
1312    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1313    <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']?>"
1314        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1315
1316    </div>
1317    <?php
1318
1319    html_form('edit', $form);
1320    print '</div>'.NL;
1321}
1322
1323/**
1324 * Display the default edit form
1325 *
1326 * Is the default action for HTML_EDIT_FORMSELECTION.
1327 */
1328function html_edit_form($param) {
1329    global $TEXT;
1330
1331    if ($param['target'] !== 'section') {
1332        msg('No editor for edit target ' . $param['target'] . ' found.', -1);
1333    }
1334
1335    $attr = array('tabindex'=>'1');
1336    if (!$param['wr']) $attr['readonly'] = 'readonly';
1337
1338    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1339}
1340
1341/**
1342 * Adds a checkbox for minor edits for logged in users
1343 *
1344 * @author Andreas Gohr <andi@splitbrain.org>
1345 */
1346function html_minoredit(){
1347    global $conf;
1348    global $lang;
1349    // minor edits are for logged in users only
1350    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1351        return false;
1352    }
1353
1354    $p = array();
1355    $p['tabindex'] = 3;
1356    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1357    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1358}
1359
1360/**
1361 * prints some debug info
1362 *
1363 * @author Andreas Gohr <andi@splitbrain.org>
1364 */
1365function html_debug(){
1366    global $conf;
1367    global $lang;
1368    global $auth;
1369    global $INFO;
1370
1371    //remove sensitive data
1372    $cnf = $conf;
1373    debug_guard($cnf);
1374    $nfo = $INFO;
1375    debug_guard($nfo);
1376    $ses = $_SESSION;
1377    debug_guard($ses);
1378
1379    print '<html><body>';
1380
1381    print '<p>When reporting bugs please send all the following ';
1382    print 'output as a mail to andi@splitbrain.org ';
1383    print 'The best way to do this is to save this page in your browser</p>';
1384
1385    print '<b>$INFO:</b><pre>';
1386    print_r($nfo);
1387    print '</pre>';
1388
1389    print '<b>$_SERVER:</b><pre>';
1390    print_r($_SERVER);
1391    print '</pre>';
1392
1393    print '<b>$conf:</b><pre>';
1394    print_r($cnf);
1395    print '</pre>';
1396
1397    print '<b>DOKU_BASE:</b><pre>';
1398    print DOKU_BASE;
1399    print '</pre>';
1400
1401    print '<b>abs DOKU_BASE:</b><pre>';
1402    print DOKU_URL;
1403    print '</pre>';
1404
1405    print '<b>rel DOKU_BASE:</b><pre>';
1406    print dirname($_SERVER['PHP_SELF']).'/';
1407    print '</pre>';
1408
1409    print '<b>PHP Version:</b><pre>';
1410    print phpversion();
1411    print '</pre>';
1412
1413    print '<b>locale:</b><pre>';
1414    print setlocale(LC_ALL,0);
1415    print '</pre>';
1416
1417    print '<b>encoding:</b><pre>';
1418    print $lang['encoding'];
1419    print '</pre>';
1420
1421    if($auth){
1422        print '<b>Auth backend capabilities:</b><pre>';
1423        print_r($auth->cando);
1424        print '</pre>';
1425    }
1426
1427    print '<b>$_SESSION:</b><pre>';
1428    print_r($ses);
1429    print '</pre>';
1430
1431    print '<b>Environment:</b><pre>';
1432    print_r($_ENV);
1433    print '</pre>';
1434
1435    print '<b>PHP settings:</b><pre>';
1436    $inis = ini_get_all();
1437    print_r($inis);
1438    print '</pre>';
1439
1440    print '</body></html>';
1441}
1442
1443/**
1444 * List available Administration Tasks
1445 *
1446 * @author Andreas Gohr <andi@splitbrain.org>
1447 * @author Håkan Sandell <hakan.sandell@home.se>
1448 */
1449function html_admin(){
1450    global $ID;
1451    global $INFO;
1452    global $lang;
1453    global $conf;
1454    global $auth;
1455
1456    // build menu of admin functions from the plugins that handle them
1457    $pluginlist = plugin_list('admin');
1458    $menu = array();
1459    foreach ($pluginlist as $p) {
1460        if($obj =& plugin_load('admin',$p) === null) continue;
1461
1462        // check permissions
1463        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1464
1465        $menu[$p] = array('plugin' => $p,
1466                'prompt' => $obj->getMenuText($conf['lang']),
1467                'sort' => $obj->getMenuSort()
1468                );
1469    }
1470
1471    // data security check
1472    // @todo: could be checked and only displayed if $conf['savedir'] is under the web root
1473    echo '<a style="border:none; float:right;"
1474            href="http://www.dokuwiki.org/security#web_access_security">
1475            <img src="data/security.png" alt="Your data directory seems to be protected properly."
1476             onerror="this.parentNode.style.display=\'none\'" /></a>';
1477
1478    print p_locale_xhtml('admin');
1479
1480    // Admin Tasks
1481    if($INFO['isadmin']){
1482        ptln('<ul class="admin_tasks">');
1483
1484        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
1485            ptln('  <li class="admin_usermanager"><div class="li">'.
1486                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
1487                    $menu['usermanager']['prompt'].'</a></div></li>');
1488        }
1489        unset($menu['usermanager']);
1490
1491        if($menu['acl']){
1492            ptln('  <li class="admin_acl"><div class="li">'.
1493                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
1494                    $menu['acl']['prompt'].'</a></div></li>');
1495        }
1496        unset($menu['acl']);
1497
1498        if($menu['plugin']){
1499            ptln('  <li class="admin_plugin"><div class="li">'.
1500                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
1501                    $menu['plugin']['prompt'].'</a></div></li>');
1502        }
1503        unset($menu['plugin']);
1504
1505        if($menu['config']){
1506            ptln('  <li class="admin_config"><div class="li">'.
1507                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
1508                    $menu['config']['prompt'].'</a></div></li>');
1509        }
1510        unset($menu['config']);
1511    }
1512    ptln('</ul>');
1513
1514    // Manager Tasks
1515    ptln('<ul class="admin_tasks">');
1516
1517    if($menu['revert']){
1518        ptln('  <li class="admin_revert"><div class="li">'.
1519                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
1520                $menu['revert']['prompt'].'</a></div></li>');
1521    }
1522    unset($menu['revert']);
1523
1524    if($menu['popularity']){
1525        ptln('  <li class="admin_popularity"><div class="li">'.
1526                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
1527                $menu['popularity']['prompt'].'</a></div></li>');
1528    }
1529    unset($menu['popularity']);
1530
1531    // print DokuWiki version:
1532    ptln('</ul>');
1533    echo '<div id="admin__version">';
1534    echo getVersion();
1535    echo '</div>';
1536
1537    // print the rest as sorted list
1538    if(count($menu)){
1539        usort($menu, 'p_sort_modes');
1540        // output the menu
1541        ptln('<div class="clearer"></div>');
1542        print p_locale_xhtml('adminplugins');
1543        ptln('<ul>');
1544        foreach ($menu as $item) {
1545            if (!$item['prompt']) continue;
1546            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1547        }
1548        ptln('</ul>');
1549    }
1550}
1551
1552/**
1553 * Form to request a new password for an existing account
1554 *
1555 * @author Benoit Chesneau <benoit@bchesneau.info>
1556 */
1557function html_resendpwd() {
1558    global $lang;
1559    global $conf;
1560    global $ID;
1561
1562    print p_locale_xhtml('resendpwd');
1563    print '<div class="centeralign">'.NL;
1564    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1565    $form->startFieldset($lang['resendpwd']);
1566    $form->addHidden('do', 'resendpwd');
1567    $form->addHidden('save', '1');
1568    $form->addElement(form_makeTag('br'));
1569    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1570    $form->addElement(form_makeTag('br'));
1571    $form->addElement(form_makeTag('br'));
1572    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1573    $form->endFieldset();
1574    html_form('resendpwd', $form);
1575    print '</div>'.NL;
1576}
1577
1578/**
1579 * Return the TOC rendered to XHTML
1580 *
1581 * @author Andreas Gohr <andi@splitbrain.org>
1582 */
1583function html_TOC($toc){
1584    if(!count($toc)) return '';
1585    global $lang;
1586    $out  = '<!-- TOC START -->'.DOKU_LF;
1587    $out .= '<div class="toc">'.DOKU_LF;
1588    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1589    $out .= $lang['toc'];
1590    $out .= '</div>'.DOKU_LF;
1591    $out .= '<div id="toc__inside">'.DOKU_LF;
1592    $out .= html_buildlist($toc,'toc','html_list_toc');
1593    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1594    $out .= '<!-- TOC END -->'.DOKU_LF;
1595    return $out;
1596}
1597
1598/**
1599 * Callback for html_buildlist
1600 */
1601function html_list_toc($item){
1602    if(isset($item['hid'])){
1603        $link = '#'.$item['hid'];
1604    }else{
1605        $link = $item['link'];
1606    }
1607
1608    return '<span class="li"><a href="'.$link.'" class="toc">'.
1609        hsc($item['title']).'</a></span>';
1610}
1611
1612/**
1613 * Helper function to build TOC items
1614 *
1615 * Returns an array ready to be added to a TOC array
1616 *
1617 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1618 * @param string $text  - what to display in the TOC
1619 * @param int    $level - nesting level
1620 * @param string $hash  - is prepended to the given $link, set blank if you want full links
1621 */
1622function html_mktocitem($link, $text, $level, $hash='#'){
1623    global $conf;
1624    return  array( 'link'  => $hash.$link,
1625            'title' => $text,
1626            'type'  => 'ul',
1627            'level' => $level);
1628}
1629
1630/**
1631 * Output a Doku_Form object.
1632 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1633 *
1634 * @author Tom N Harris <tnharris@whoopdedo.org>
1635 */
1636function html_form($name, &$form) {
1637    // Safety check in case the caller forgets.
1638    $form->endFieldset();
1639    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1640}
1641
1642/**
1643 * Form print function.
1644 * Just calls printForm() on the data object.
1645 */
1646function html_form_output($data) {
1647    $data->printForm();
1648}
1649
1650/**
1651 * Embed a flash object in HTML
1652 *
1653 * This will create the needed HTML to embed a flash movie in a cross browser
1654 * compatble way using valid XHTML
1655 *
1656 * The parameters $params, $flashvars and $atts need to be associative arrays.
1657 * No escaping needs to be done for them. The alternative content *has* to be
1658 * escaped because it is used as is. If no alternative content is given
1659 * $lang['noflash'] is used.
1660 *
1661 * @author Andreas Gohr <andi@splitbrain.org>
1662 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
1663 *
1664 * @param string $swf      - the SWF movie to embed
1665 * @param int $width       - width of the flash movie in pixels
1666 * @param int $height      - height of the flash movie in pixels
1667 * @param array $params    - additional parameters (<param>)
1668 * @param array $flashvars - parameters to be passed in the flashvar parameter
1669 * @param array $atts      - additional attributes for the <object> tag
1670 * @param string $alt      - alternative content (is NOT automatically escaped!)
1671 * @returns string         - the XHTML markup
1672 */
1673function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
1674    global $lang;
1675
1676    $out = '';
1677
1678    // prepare the object attributes
1679    if(is_null($atts)) $atts = array();
1680    $atts['width']  = (int) $width;
1681    $atts['height'] = (int) $height;
1682    if(!$atts['width'])  $atts['width']  = 425;
1683    if(!$atts['height']) $atts['height'] = 350;
1684
1685    // add object attributes for standard compliant browsers
1686    $std = $atts;
1687    $std['type'] = 'application/x-shockwave-flash';
1688    $std['data'] = $swf;
1689
1690    // add object attributes for IE
1691    $ie  = $atts;
1692    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
1693
1694    // open object (with conditional comments)
1695    $out .= '<!--[if !IE]> -->'.NL;
1696    $out .= '<object '.buildAttributes($std).'>'.NL;
1697    $out .= '<!-- <![endif]-->'.NL;
1698    $out .= '<!--[if IE]>'.NL;
1699    $out .= '<object '.buildAttributes($ie).'>'.NL;
1700    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
1701    $out .= '<!--><!-- -->'.NL;
1702
1703    // print params
1704    if(is_array($params)) foreach($params as $key => $val){
1705        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
1706    }
1707
1708    // add flashvars
1709    if(is_array($flashvars)){
1710        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
1711    }
1712
1713    // alternative content
1714    if($alt){
1715        $out .= $alt.NL;
1716    }else{
1717        $out .= $lang['noflash'].NL;
1718    }
1719
1720    // finish
1721    $out .= '</object>'.NL;
1722    $out .= '<!-- <![endif]-->'.NL;
1723
1724    return $out;
1725}
1726
1727