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