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