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