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