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