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