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