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