xref: /dokuwiki/inc/html.php (revision ec57f1190eb6df5ddeba76bb2c35b46d65d31561)
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");
11if (!defined('SEC_EDIT_PATTERN')) {
12    define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*}) -->#');
13}
14
15
16/**
17 * Convenience function to quickly build a wikilink
18 *
19 * @author Andreas Gohr <andi@splitbrain.org>
20 * @param string  $id      id of the target page
21 * @param string  $name    the name of the link, i.e. the text that is displayed
22 * @param string|array  $search  search string(s) that shall be highlighted in the target page
23 * @return string the HTML code of the link
24 */
25function html_wikilink($id,$name=null,$search=''){
26    /** @var Doku_Renderer_xhtml $xhtml_renderer */
27    static $xhtml_renderer = null;
28    if(is_null($xhtml_renderer)){
29        $xhtml_renderer = p_get_renderer('xhtml');
30    }
31
32    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
33}
34
35/**
36 * The loginform
37 *
38 * @author   Andreas Gohr <andi@splitbrain.org>
39 */
40function html_login(){
41    global $lang;
42    global $conf;
43    global $ID;
44    global $INPUT;
45
46    print p_locale_xhtml('login');
47    print '<div class="centeralign">'.NL;
48    $form = new Doku_Form(array('id' => 'dw__login'));
49    $form->startFieldset($lang['btn_login']);
50    $form->addHidden('id', $ID);
51    $form->addHidden('do', 'login');
52    $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block'));
53    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
54    if($conf['rememberme']) {
55        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
56    }
57    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
58    $form->endFieldset();
59
60    if(actionOK('register')){
61        $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>');
62    }
63
64    if (actionOK('resendpwd')) {
65        $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>');
66    }
67
68    html_form('login', $form);
69    print '</div>'.NL;
70}
71
72
73/**
74 * Denied page content
75 *
76 * @return string html
77 */
78function html_denied() {
79    print p_locale_xhtml('denied');
80
81    if(empty($_SERVER['REMOTE_USER'])){
82        html_login();
83    }
84}
85
86/**
87 * inserts section edit buttons if wanted or removes the markers
88 *
89 * @author Andreas Gohr <andi@splitbrain.org>
90 *
91 * @param string $text
92 * @param bool   $show show section edit buttons?
93 * @return string
94 */
95function html_secedit($text,$show=true){
96    global $INFO;
97
98    if(!$INFO['writable'] || !$show || $INFO['rev']){
99        return preg_replace(SEC_EDIT_PATTERN,'',$text);
100    }
101
102    return preg_replace_callback(SEC_EDIT_PATTERN,
103                'html_secedit_button', $text);
104}
105
106/**
107 * prepares section edit button data for event triggering
108 * used as a callback in html_secedit
109 *
110 * @author Andreas Gohr <andi@splitbrain.org>
111 *
112 * @param array $matches matches with regexp
113 * @return string
114 * @triggers HTML_SECEDIT_BUTTON
115 */
116function html_secedit_button($matches){
117    $data = json_decode($matches[1], true);
118    if ($data == NULL) {
119        return;
120    }
121    $data ['target'] = strtolower($data['target']);
122    $data ['hid'] = strtolower($data['hid']);
123
124    return trigger_event('HTML_SECEDIT_BUTTON', $data,
125                         'html_secedit_get_button');
126}
127
128/**
129 * prints a section editing button
130 * used as default action form HTML_SECEDIT_BUTTON
131 *
132 * @author Adrian Lang <lang@cosmocode.de>
133 *
134 * @param array $data name, section id and target
135 * @return string html
136 */
137function html_secedit_get_button($data) {
138    global $ID;
139    global $INFO;
140
141    if (!isset($data['name']) || $data['name'] === '') return '';
142
143    $name = $data['name'];
144    unset($data['name']);
145
146    $secid = $data['secid'];
147    unset($data['secid']);
148
149    return "<div class='secedit editbutton_" . $data['target'] .
150                       " editbutton_" . $secid . "'>" .
151           html_btn('secedit', $ID, '',
152                    array_merge(array('do'  => 'edit',
153                                      'rev' => $INFO['lastmod'],
154                                      'summary' => '['.$name.'] '), $data),
155                    'post', $name) . '</div>';
156}
157
158/**
159 * Just the back to top button (in its own form)
160 *
161 * @author Andreas Gohr <andi@splitbrain.org>
162 *
163 * @return string html
164 */
165function html_topbtn(){
166    global $lang;
167
168    $ret  = '<a class="nolink" href="#dokuwiki__top"><button class="button" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'">'.$lang['btn_top'].'</button></a>';
169
170    return $ret;
171}
172
173/**
174 * Displays a button (using its own form)
175 * If tooltip exists, the access key tooltip is replaced.
176 *
177 * @author Andreas Gohr <andi@splitbrain.org>
178 *
179 * @param string         $name
180 * @param string         $id
181 * @param string         $akey   access key
182 * @param string[] $params key-value pairs added as hidden inputs
183 * @param string         $method
184 * @param string         $tooltip
185 * @param bool|string    $label  label text, false: lookup btn_$name in localization
186 * @return string
187 */
188function html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false){
189    global $conf;
190    global $lang;
191
192    if (!$label)
193        $label = $lang['btn_'.$name];
194
195    $ret = '';
196
197    //filter id (without urlencoding)
198    $id = idfilter($id,false);
199
200    //make nice URLs even for buttons
201    if($conf['userewrite'] == 2){
202        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
203    }elseif($conf['userewrite']){
204        $script = DOKU_BASE.$id;
205    }else{
206        $script = DOKU_BASE.DOKU_SCRIPT;
207        $params['id'] = $id;
208    }
209
210    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
211
212    if(is_array($params)){
213        foreach($params as $key => $val) {
214            $ret .= '<input type="hidden" name="'.$key.'" ';
215            $ret .= 'value="'.hsc($val).'" />';
216        }
217    }
218
219    if ($tooltip!='') {
220        $tip = hsc($tooltip);
221    }else{
222        $tip = hsc($label);
223    }
224
225    $ret .= '<button type="submit" ';
226    if($akey){
227        $tip .= ' ['.strtoupper($akey).']';
228        $ret .= 'accesskey="'.$akey.'" ';
229    }
230    $ret .= 'title="'.$tip.'">';
231    $ret .= hsc($label);
232    $ret .= '</button>';
233    $ret .= '</div></form>';
234
235    return $ret;
236}
237/**
238 * show a revision warning
239 *
240 * @author Szymon Olewniczak <dokuwiki@imz.re>
241 */
242function html_showrev() {
243    print p_locale_xhtml('showrev');
244}
245
246/**
247 * Show a wiki page
248 *
249 * @author Andreas Gohr <andi@splitbrain.org>
250 *
251 * @param null|string $txt wiki text or null for showing $ID
252 */
253function html_show($txt=null){
254    global $ID;
255    global $REV;
256    global $HIGH;
257    global $INFO;
258    global $DATE_AT;
259    //disable section editing for old revisions or in preview
260    if($txt || $REV){
261        $secedit = false;
262    }else{
263        $secedit = true;
264    }
265
266    if (!is_null($txt)){
267        //PreviewHeader
268        echo '<br id="scroll__here" />';
269        echo p_locale_xhtml('preview');
270        echo '<div class="preview"><div class="pad">';
271        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
272        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
273        echo $html;
274        echo '<div class="clearer"></div>';
275        echo '</div></div>';
276
277    }else{
278        if ($REV||$DATE_AT){
279            $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
280            trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
281        }
282        $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
283        $html = html_secedit($html,$secedit);
284        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
285        $html = html_hilight($html,$HIGH);
286        echo $html;
287    }
288}
289
290/**
291 * ask the user about how to handle an exisiting draft
292 *
293 * @author Andreas Gohr <andi@splitbrain.org>
294 */
295function html_draft(){
296    global $INFO;
297    global $ID;
298    global $lang;
299    $draft = unserialize(io_readFile($INFO['draft'],false));
300    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
301
302    print p_locale_xhtml('draft');
303    $form = new Doku_Form(array('id' => 'dw__editform'));
304    $form->addHidden('id', $ID);
305    $form->addHidden('date', $draft['date']);
306    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
307    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
308    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
309    $form->addElement(form_makeCloseTag('div'));
310    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
311    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
312    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
313    html_form('draft', $form);
314}
315
316/**
317 * Highlights searchqueries in HTML code
318 *
319 * @author Andreas Gohr <andi@splitbrain.org>
320 * @author Harry Fuecks <hfuecks@gmail.com>
321 *
322 * @param string $html
323 * @param array|string $phrases
324 * @return string html
325 */
326function html_hilight($html,$phrases){
327    $phrases = (array) $phrases;
328    $phrases = array_map('preg_quote_cb', $phrases);
329    $phrases = array_map('ft_snippet_re_preprocess', $phrases);
330    $phrases = array_filter($phrases);
331    $regex = join('|',$phrases);
332
333    if ($regex === '') return $html;
334    if (!utf8_check($regex)) return $html;
335    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
336    return $html;
337}
338
339/**
340 * Callback used by html_hilight()
341 *
342 * @author Harry Fuecks <hfuecks@gmail.com>
343 *
344 * @param array $m matches
345 * @return string html
346 */
347function html_hilight_callback($m) {
348    $hlight = unslash($m[0]);
349    if ( !isset($m[2])) {
350        $hlight = '<span class="search_hit">'.$hlight.'</span>';
351    }
352    return $hlight;
353}
354
355/**
356 * Run a search and display the result
357 *
358 * @author Andreas Gohr <andi@splitbrain.org>
359 */
360function html_search(){
361    global $QUERY, $ID;
362    global $lang;
363
364    $intro = p_locale_xhtml('searchpage');
365    // allow use of placeholder in search intro
366    $pagecreateinfo = (auth_quickaclcheck($ID) >= AUTH_CREATE) ? $lang['searchcreatepage'] : '';
367    $intro = str_replace(
368        array('@QUERY@', '@SEARCH@', '@CREATEPAGEINFO@'),
369        array(hsc(rawurlencode($QUERY)), hsc($QUERY), $pagecreateinfo),
370        $intro
371    );
372    echo $intro;
373
374    //do quick pagesearch
375    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
376    if(count($data)){
377        print '<div class="search_quickresult">';
378        print '<h3>'.$lang['quickhits'].':</h3>';
379        print '<ul class="search_quickhits">';
380        foreach($data as $id => $title){
381            print '<li> ';
382            if (useHeading('navigation')) {
383                $name = $title;
384            }else{
385                $ns = getNS($id);
386                if($ns){
387                    $name = shorten(noNS($id), ' ('.$ns.')',30);
388                }else{
389                    $name = $id;
390                }
391            }
392            print html_wikilink(':'.$id,$name);
393            print '</li> ';
394        }
395        print '</ul> ';
396        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
397        print '<div class="clearer"></div>';
398        print '</div>';
399    }
400
401    //do fulltext search
402    $regex = array();
403    $data = ft_pageSearch($QUERY,$regex);
404    if(count($data)){
405        print '<dl class="search_results">';
406        $num = 1;
407        foreach($data as $id => $cnt){
408            print '<dt>';
409            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
410            if($cnt !== 0){
411                print ': '.$cnt.' '.$lang['hits'].'';
412            }
413            print '</dt>';
414            if($cnt !== 0){
415                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
416                    print '<dd>'.ft_snippet($id,$regex).'</dd>';
417                }
418                $num++;
419            }
420        }
421        print '</dl>';
422    }else{
423        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
424    }
425}
426
427/**
428 * Display error on locked pages
429 *
430 * @author Andreas Gohr <andi@splitbrain.org>
431 */
432function html_locked(){
433    global $ID;
434    global $conf;
435    global $lang;
436    global $INFO;
437
438    $locktime = filemtime(wikiLockFN($ID));
439    $expire = dformat($locktime + $conf['locktime']);
440    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
441
442    print p_locale_xhtml('locked');
443    print '<ul>';
444    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
445    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
446    print '</ul>';
447}
448
449/**
450 * list old revisions
451 *
452 * @author Andreas Gohr <andi@splitbrain.org>
453 * @author Ben Coburn <btcoburn@silicodon.net>
454 * @author Kate Arzamastseva <pshns@ukr.net>
455 *
456 * @param int $first skip the first n changelog lines
457 * @param bool|string $media_id id of media, or false for current page
458 */
459function html_revisions($first=0, $media_id = false){
460    global $ID;
461    global $INFO;
462    global $conf;
463    global $lang;
464    $id = $ID;
465    if ($media_id) {
466        $id = $media_id;
467        $changelog = new MediaChangeLog($id);
468    } else {
469        $changelog = new PageChangeLog($id);
470    }
471
472    /* we need to get one additional log entry to be able to
473     * decide if this is the last page or is there another one.
474     * see html_recent()
475     */
476
477    $revisions = $changelog->getRevisions($first, $conf['recent']+1);
478
479    if(count($revisions)==0 && $first!=0){
480        $first=0;
481        $revisions = $changelog->getRevisions($first, $conf['recent']+1);
482    }
483    $hasNext = false;
484    if (count($revisions)>$conf['recent']) {
485        $hasNext = true;
486        array_pop($revisions); // remove extra log entry
487    }
488
489    if (!$media_id) print p_locale_xhtml('revisions');
490
491    $params = array('id' => 'page__revisions', 'class' => 'changes');
492    if($media_id) {
493        $params['action'] = media_managerURL(array('image' => $media_id), '&');
494    }
495
496    if(!$media_id) {
497        $exists = $INFO['exists'];
498        $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id;
499        if(!$display_name) {
500            $display_name = $id;
501        }
502    } else {
503        $exists = file_exists(mediaFN($id));
504        $display_name = $id;
505    }
506
507    $form = new Doku_Form($params);
508    $form->addElement(form_makeOpenTag('ul'));
509
510    if($exists && $first == 0) {
511        $minor = false;
512        if($media_id) {
513            $date = dformat(@filemtime(mediaFN($id)));
514            $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
515
516            $changelog->setChunkSize(1024);
517            $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
518
519            $summary = $revinfo['sum'];
520            if($revinfo['user']) {
521                $editor = $revinfo['user'];
522            } else {
523                $editor = $revinfo['ip'];
524            }
525            $sizechange = $revinfo['sizechange'];
526        } else {
527            $date = dformat($INFO['lastmod']);
528            if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) {
529                if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
530                    $minor = true;
531                }
532                if(isset($INFO['meta']['last_change']['sizechange'])) {
533                    $sizechange = $INFO['meta']['last_change']['sizechange'];
534                } else {
535                    $sizechange = null;
536                }
537            }
538            $pagelog = new PageChangeLog($ID);
539            $latestrev = $pagelog->getRevisions(-1, 1);
540            $latestrev = array_pop($latestrev);
541            $href = wl($id,"rev=$latestrev",false,'&');
542            $summary = $INFO['sum'];
543            $editor = $INFO['editor'];
544        }
545
546        $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : ''))));
547        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
548        $form->addElement(form_makeTag('input', array(
549                        'type' => 'checkbox',
550                        'name' => 'rev2[]',
551                        'value' => 'current')));
552
553        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
554        $form->addElement($date);
555        $form->addElement(form_makeCloseTag('span'));
556
557        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
558
559        $form->addElement(form_makeOpenTag('a', array(
560                        'class' => 'wikilink1',
561                        'href'  => $href)));
562        $form->addElement($display_name);
563        $form->addElement(form_makeCloseTag('a'));
564
565        if ($media_id) $form->addElement(form_makeOpenTag('div'));
566
567        if($summary) {
568            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
569            if(!$media_id) $form->addElement(' – ');
570            $form->addElement('<bdi>' . hsc($summary) . '</bdi>');
571            $form->addElement(form_makeCloseTag('span'));
572        }
573
574        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
575        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>');
576        $form->addElement(form_makeCloseTag('span'));
577
578        html_sizechange($sizechange, $form);
579
580        $form->addElement('('.$lang['current'].')');
581
582        if ($media_id) $form->addElement(form_makeCloseTag('div'));
583
584        $form->addElement(form_makeCloseTag('div'));
585        $form->addElement(form_makeCloseTag('li'));
586    }
587
588    foreach($revisions as $rev) {
589        $date = dformat($rev);
590        $info = $changelog->getRevisionInfo($rev);
591        if($media_id) {
592            $exists = file_exists(mediaFN($id, $rev));
593        } else {
594            $exists = page_exists($id, $rev);
595        }
596
597        $class = '';
598        if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
599            $class = 'minor';
600        }
601        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
602        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
603        if($exists){
604            $form->addElement(form_makeTag('input', array(
605                            'type' => 'checkbox',
606                            'name' => 'rev2[]',
607                            'value' => $rev)));
608        }else{
609            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
610        }
611
612        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
613        $form->addElement($date);
614        $form->addElement(form_makeCloseTag('span'));
615
616        if($exists){
617            if (!$media_id) {
618                $href = wl($id,"rev=$rev,do=diff", false, '&');
619            } else {
620                $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
621            }
622            $form->addElement(form_makeOpenTag('a', array(
623                            'class' => 'diff_link',
624                            'href' => $href)));
625            $form->addElement(form_makeTag('img', array(
626                            'src'    => DOKU_BASE.'lib/images/diff.png',
627                            'width'  => 15,
628                            'height' => 11,
629                            'title'  => $lang['diff'],
630                            'alt'    => $lang['diff'])));
631            $form->addElement(form_makeCloseTag('a'));
632
633            if (!$media_id) {
634                $href = wl($id,"rev=$rev",false,'&');
635            } else {
636                $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
637            }
638            $form->addElement(form_makeOpenTag('a', array(
639                            'class' => 'wikilink1',
640                            'href' => $href)));
641            $form->addElement($display_name);
642            $form->addElement(form_makeCloseTag('a'));
643        }else{
644            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
645            $form->addElement($display_name);
646        }
647
648        if ($media_id) $form->addElement(form_makeOpenTag('div'));
649
650        if ($info['sum']) {
651            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
652            if(!$media_id) $form->addElement(' – ');
653            $form->addElement('<bdi>'.hsc($info['sum']).'</bdi>');
654            $form->addElement(form_makeCloseTag('span'));
655        }
656
657        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
658        if($info['user']){
659            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
660            if(auth_ismanager()){
661                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
662            }
663        }else{
664            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
665        }
666        $form->addElement(form_makeCloseTag('span'));
667
668        html_sizechange($info['sizechange'], $form);
669
670        if ($media_id) $form->addElement(form_makeCloseTag('div'));
671
672        $form->addElement(form_makeCloseTag('div'));
673        $form->addElement(form_makeCloseTag('li'));
674    }
675    $form->addElement(form_makeCloseTag('ul'));
676    if (!$media_id) {
677        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
678    } else {
679        $form->addHidden('mediado', 'diff');
680        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
681    }
682    html_form('revisions', $form);
683
684    print '<div class="pagenav">';
685    $last = $first + $conf['recent'];
686    if ($first > 0) {
687        $first -= $conf['recent'];
688        if ($first < 0) $first = 0;
689        print '<div class="pagenav-prev">';
690        if ($media_id) {
691            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
692        } else {
693            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
694        }
695        print '</div>';
696    }
697    if ($hasNext) {
698        print '<div class="pagenav-next">';
699        if ($media_id) {
700            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
701        } else {
702            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
703        }
704        print '</div>';
705    }
706    print '</div>';
707
708}
709
710/**
711 * display recent changes
712 *
713 * @author Andreas Gohr <andi@splitbrain.org>
714 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
715 * @author Ben Coburn <btcoburn@silicodon.net>
716 * @author Kate Arzamastseva <pshns@ukr.net>
717 *
718 * @param int $first
719 * @param string $show_changes
720 */
721function html_recent($first = 0, $show_changes = 'both') {
722    global $conf;
723    global $lang;
724    global $ID;
725    /* we need to get one additionally log entry to be able to
726     * decide if this is the last page or is there another one.
727     * This is the cheapest solution to get this information.
728     */
729    $flags = 0;
730    if($show_changes == 'mediafiles' && $conf['mediarevisions']) {
731        $flags = RECENTS_MEDIA_CHANGES;
732    } elseif($show_changes == 'pages') {
733        $flags = 0;
734    } elseif($conf['mediarevisions']) {
735        $show_changes = 'both';
736        $flags = RECENTS_MEDIA_PAGES_MIXED;
737    }
738
739    $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
740    if(count($recents) == 0 && $first != 0) {
741        $first = 0;
742        $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags);
743    }
744    $hasNext = false;
745    if(count($recents) > $conf['recent']) {
746        $hasNext = true;
747        array_pop($recents); // remove extra log entry
748    }
749
750    print p_locale_xhtml('recent');
751
752    if(getNS($ID) != '') {
753        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
754    }
755
756    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
757    $form->addHidden('sectok', null);
758    $form->addHidden('do', 'recent');
759    $form->addHidden('id', $ID);
760
761    if($conf['mediarevisions']) {
762        $form->addElement('<div class="changeType">');
763        $form->addElement(form_makeListboxField(
764                    'show_changes',
765                    array(
766                        'pages'      => $lang['pages_changes'],
767                        'mediafiles' => $lang['media_changes'],
768                        'both'       => $lang['both_changes']
769                    ),
770                    $show_changes,
771                    $lang['changes_type'],
772                    '', '',
773                    array('class' => 'quickselect')));
774
775        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
776        $form->addElement('</div>');
777    }
778
779    $form->addElement(form_makeOpenTag('ul'));
780
781    foreach($recents as $recent) {
782        $date = dformat($recent['date']);
783
784        $class = '';
785        if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
786            $class = 'minor';
787        }
788        $form->addElement(form_makeOpenTag('li', array('class' => $class)));
789        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
790
791        if(!empty($recent['media'])) {
792            $form->addElement(media_printicon($recent['id']));
793        } else {
794            $icon = DOKU_BASE . 'lib/images/fileicons/file.png';
795            $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />');
796        }
797
798        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
799        $form->addElement($date);
800        $form->addElement(form_makeCloseTag('span'));
801
802        $diff = false;
803        $href = '';
804
805        if(!empty($recent['media'])) {
806            $changelog = new MediaChangeLog($recent['id']);
807            $revs = $changelog->getRevisions(0, 1);
808            $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
809            if($diff) {
810                $href = media_managerURL(array(
811                                            'tab_details' => 'history',
812                                            'mediado' => 'diff',
813                                            'image' => $recent['id'],
814                                            'ns' => getNS($recent['id'])
815                                        ), '&');
816            }
817        } else {
818            $href = wl($recent['id'], "do=diff", false, '&');
819        }
820
821        if(!empty($recent['media']) && !$diff) {
822            $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
823        } else {
824            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
825            $form->addElement(form_makeTag('img', array(
826                            'src'    => DOKU_BASE . 'lib/images/diff.png',
827                            'width'  => 15,
828                            'height' => 11,
829                            'title'  => $lang['diff'],
830                            'alt'    => $lang['diff']
831                        )));
832            $form->addElement(form_makeCloseTag('a'));
833        }
834
835        if(!empty($recent['media'])) {
836            $href = media_managerURL(array('tab_details' => 'history', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
837        } else {
838            $href = wl($recent['id'], "do=revisions", false, '&');
839        }
840        $form->addElement(form_makeOpenTag('a', array(
841                        'class' => 'revisions_link',
842                        'href'  => $href)));
843        $form->addElement(form_makeTag('img', array(
844                        'src'    => DOKU_BASE . 'lib/images/history.png',
845                        'width'  => 12,
846                        'height' => 14,
847                        'title'  => $lang['btn_revs'],
848                        'alt'    => $lang['btn_revs']
849                    )));
850        $form->addElement(form_makeCloseTag('a'));
851
852        if(!empty($recent['media'])) {
853            $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
854            $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2';
855            $form->addElement(form_makeOpenTag('a', array(
856                        'class' => $class,
857                        'href'  => $href)));
858            $form->addElement($recent['id']);
859            $form->addElement(form_makeCloseTag('a'));
860        } else {
861            $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id']));
862        }
863        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
864        $form->addElement(' – ' . hsc($recent['sum']));
865        $form->addElement(form_makeCloseTag('span'));
866
867        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
868        if($recent['user']) {
869            $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>');
870            if(auth_ismanager()) {
871                $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>');
872            }
873        } else {
874            $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>');
875        }
876        $form->addElement(form_makeCloseTag('span'));
877
878        html_sizechange($recent['sizechange'], $form);
879
880        $form->addElement(form_makeCloseTag('div'));
881        $form->addElement(form_makeCloseTag('li'));
882    }
883    $form->addElement(form_makeCloseTag('ul'));
884
885    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
886    $last = $first + $conf['recent'];
887    if($first > 0) {
888        $first -= $conf['recent'];
889        if($first < 0) $first = 0;
890        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
891        $form->addElement(form_makeOpenTag('button', array(
892                        'type'      => 'submit',
893                        'name'      => 'first[' . $first . ']',
894                        'accesskey' => 'n',
895                        'title'     => $lang['btn_newer'] . ' [N]',
896                        'class'     => 'button show'
897                    )));
898        $form->addElement($lang['btn_newer']);
899        $form->addElement(form_makeCloseTag('button'));
900        $form->addElement(form_makeCloseTag('div'));
901    }
902    if($hasNext) {
903        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
904        $form->addElement(form_makeOpenTag('button', array(
905                        'type'      => 'submit',
906                        'name'      => 'first[' . $last . ']',
907                        'accesskey' => 'p',
908                        'title'     => $lang['btn_older'] . ' [P]',
909                        'class'     => 'button show'
910                    )));
911        $form->addElement($lang['btn_older']);
912        $form->addElement(form_makeCloseTag('button'));
913        $form->addElement(form_makeCloseTag('div'));
914    }
915    $form->addElement(form_makeCloseTag('div'));
916    html_form('recent', $form);
917}
918
919/**
920 * Display page index
921 *
922 * @author Andreas Gohr <andi@splitbrain.org>
923 *
924 * @param string $ns
925 */
926function html_index($ns){
927    global $conf;
928    global $ID;
929    $ns  = cleanID($ns);
930    if(empty($ns)){
931        $ns = getNS($ID);
932        if($ns === false) $ns ='';
933    }
934    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
935
936    echo p_locale_xhtml('index');
937    echo '<div id="index__tree" class="index__tree">';
938
939    $data = array();
940    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
941    echo html_buildlist($data,'idx','html_list_index','html_li_index');
942
943    echo '</div>';
944}
945
946/**
947 * Index item formatter
948 *
949 * User function for html_buildlist()
950 *
951 * @author Andreas Gohr <andi@splitbrain.org>
952 *
953 * @param array $item
954 * @return string
955 */
956function html_list_index($item){
957    global $ID, $conf;
958
959    // prevent searchbots needlessly following links
960    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : '';
961
962    $ret = '';
963    $base = ':'.$item['id'];
964    $base = substr($base,strrpos($base,':')+1);
965    if($item['type']=='d'){
966        // FS#2766, no need for search bots to follow namespace links in the index
967        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>';
968        $ret .= $base;
969        $ret .= '</strong></a>';
970    }else{
971        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
972        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
973    }
974    return $ret;
975}
976
977/**
978 * Index List item
979 *
980 * This user function is used in html_buildlist to build the
981 * <li> tags for namespaces when displaying the page index
982 * it gives different classes to opened or closed "folders"
983 *
984 * @author Andreas Gohr <andi@splitbrain.org>
985 *
986 * @param array $item
987 * @return string html
988 */
989function html_li_index($item){
990    global $INFO;
991    global $ACT;
992
993    $class = '';
994    $id = '';
995
996    if($item['type'] == "f"){
997        // scroll to the current item
998        if($item['id'] == $INFO['id'] && $ACT == 'index') {
999            $id = ' id="scroll__here"';
1000            $class = ' bounce';
1001        }
1002        return '<li class="level'.$item['level'].$class.'" '.$id.'>';
1003    }elseif($item['open']){
1004        return '<li class="open">';
1005    }else{
1006        return '<li class="closed">';
1007    }
1008}
1009
1010/**
1011 * Default List item
1012 *
1013 * @author Andreas Gohr <andi@splitbrain.org>
1014 *
1015 * @param array $item
1016 * @return string html
1017 */
1018function html_li_default($item){
1019    return '<li class="level'.$item['level'].'">';
1020}
1021
1022/**
1023 * Build an unordered list
1024 *
1025 * Build an unordered list from the given $data array
1026 * Each item in the array has to have a 'level' property
1027 * the item itself gets printed by the given $func user
1028 * function. The second and optional function is used to
1029 * print the <li> tag. Both user function need to accept
1030 * a single item.
1031 *
1032 * Both user functions can be given as array to point to
1033 * a member of an object.
1034 *
1035 * @author Andreas Gohr <andi@splitbrain.org>
1036 *
1037 * @param array    $data  array with item arrays
1038 * @param string   $class class of ul wrapper
1039 * @param callable $func  callback to print an list item
1040 * @param callable $lifunc callback to the opening li tag
1041 * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
1042 *                               0 (we have a root object) or 1 (just the root content)
1043 * @return string html of an unordered list
1044 */
1045function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1046    if (count($data) === 0) {
1047        return '';
1048    }
1049
1050    $firstElement = reset($data);
1051    $start_level = $firstElement['level'];
1052    $level = $start_level;
1053    $ret   = '';
1054    $open  = 0;
1055
1056    foreach ($data as $item){
1057
1058        if( $item['level'] > $level ){
1059            //open new list
1060            for($i=0; $i<($item['level'] - $level); $i++){
1061                if ($i) $ret .= "<li class=\"clear\">";
1062                $ret .= "\n<ul class=\"$class\">\n";
1063                $open++;
1064            }
1065            $level = $item['level'];
1066
1067        }elseif( $item['level'] < $level ){
1068            //close last item
1069            $ret .= "</li>\n";
1070            while( $level > $item['level'] && $open > 0 ){
1071                //close higher lists
1072                $ret .= "</ul>\n</li>\n";
1073                $level--;
1074                $open--;
1075            }
1076        } elseif ($ret !== '') {
1077            //close previous item
1078            $ret .= "</li>\n";
1079        }
1080
1081        //print item
1082        $ret .= call_user_func($lifunc,$item);
1083        $ret .= '<div class="li">';
1084
1085        $ret .= call_user_func($func,$item);
1086        $ret .= '</div>';
1087    }
1088
1089    //close remaining items and lists
1090    $ret .= "</li>\n";
1091    while($open-- > 0) {
1092        $ret .= "</ul></li>\n";
1093    }
1094
1095    if ($forcewrapper || $start_level < 2) {
1096        // Trigger building a wrapper ul if the first level is
1097        // 0 (we have a root object) or 1 (just the root content)
1098        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1099    }
1100
1101    return $ret;
1102}
1103
1104/**
1105 * display backlinks
1106 *
1107 * @author Andreas Gohr <andi@splitbrain.org>
1108 * @author Michael Klier <chi@chimeric.de>
1109 */
1110function html_backlinks(){
1111    global $ID;
1112    global $lang;
1113
1114    print p_locale_xhtml('backlinks');
1115
1116    $data = ft_backlinks($ID);
1117
1118    if(!empty($data)) {
1119        print '<ul class="idx">';
1120        foreach($data as $blink){
1121            print '<li><div class="li">';
1122            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
1123            print '</div></li>';
1124        }
1125        print '</ul>';
1126    } else {
1127        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1128    }
1129}
1130
1131/**
1132 * Get header of diff HTML
1133 *
1134 * @param string $l_rev   Left revisions
1135 * @param string $r_rev   Right revision
1136 * @param string $id      Page id, if null $ID is used
1137 * @param bool   $media   If it is for media files
1138 * @param bool   $inline  Return the header on a single line
1139 * @return string[] HTML snippets for diff header
1140 */
1141function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1142    global $lang;
1143    if ($id === null) {
1144        global $ID;
1145        $id = $ID;
1146    }
1147    $head_separator = $inline ? ' ' : '<br />';
1148    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1149    $ml_or_wl = $media ? 'ml' : 'wl';
1150    $l_minor = $r_minor = '';
1151
1152    if($media) {
1153        $changelog = new MediaChangeLog($id);
1154    } else {
1155        $changelog = new PageChangeLog($id);
1156    }
1157    if(!$l_rev){
1158        $l_head = '&mdash;';
1159    }else{
1160        $l_info   = $changelog->getRevisionInfo($l_rev);
1161        if($l_info['user']){
1162            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1163            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1164        } else {
1165            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1166        }
1167        $l_user  = '<span class="user">'.$l_user.'</span>';
1168        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1169        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1170
1171        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1172        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1173        $l_head_title.'</a></bdi>'.
1174        $head_separator.$l_user.' '.$l_sum;
1175    }
1176
1177    if($r_rev){
1178        $r_info   = $changelog->getRevisionInfo($r_rev);
1179        if($r_info['user']){
1180            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1181            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1182        } else {
1183            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1184        }
1185        $r_user = '<span class="user">'.$r_user.'</span>';
1186        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1187        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1188
1189        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1190        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1191        $r_head_title.'</a></bdi>'.
1192        $head_separator.$r_user.' '.$r_sum;
1193    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1194        $_info   = $changelog->getRevisionInfo($_rev);
1195        if($_info['user']){
1196            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1197            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1198        } else {
1199            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1200        }
1201        $_user = '<span class="user">'.$_user.'</span>';
1202        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1203        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1204
1205        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1206        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1207        $r_head_title.'</a></bdi> '.
1208        '('.$lang['current'].')'.
1209        $head_separator.$_user.' '.$_sum;
1210    }else{
1211        $r_head = '&mdash; ('.$lang['current'].')';
1212    }
1213
1214    return array($l_head, $r_head, $l_minor, $r_minor);
1215}
1216
1217/**
1218 * Show diff
1219 * between current page version and provided $text
1220 * or between the revisions provided via GET or POST
1221 *
1222 * @author Andreas Gohr <andi@splitbrain.org>
1223 * @param  string $text  when non-empty: compare with this text with most current version
1224 * @param  bool   $intro display the intro text
1225 * @param  string $type  type of the diff (inline or sidebyside)
1226 */
1227function html_diff($text = '', $intro = true, $type = null) {
1228    global $ID;
1229    global $REV;
1230    global $lang;
1231    global $INPUT;
1232    global $INFO;
1233    $pagelog = new PageChangeLog($ID);
1234
1235    /*
1236     * Determine diff type
1237     */
1238    if(!$type) {
1239        $type = $INPUT->str('difftype');
1240        if(empty($type)) {
1241            $type = get_doku_pref('difftype', $type);
1242            if(empty($type) && $INFO['ismobile']) {
1243                $type = 'inline';
1244            }
1245        }
1246    }
1247    if($type != 'inline') $type = 'sidebyside';
1248
1249    /*
1250     * Determine requested revision(s)
1251     */
1252    // we're trying to be clever here, revisions to compare can be either
1253    // given as rev and rev2 parameters, with rev2 being optional. Or in an
1254    // array in rev2.
1255    $rev1 = $REV;
1256
1257    $rev2 = $INPUT->ref('rev2');
1258    if(is_array($rev2)) {
1259        $rev1 = (int) $rev2[0];
1260        $rev2 = (int) $rev2[1];
1261
1262        if(!$rev1) {
1263            $rev1 = $rev2;
1264            unset($rev2);
1265        }
1266    } else {
1267        $rev2 = $INPUT->int('rev2');
1268    }
1269
1270    /*
1271     * Determine left and right revision, its texts and the header
1272     */
1273    $r_minor = '';
1274    $l_minor = '';
1275
1276    if($text) { // compare text to the most current revision
1277        $l_rev = '';
1278        $l_text = rawWiki($ID, '');
1279        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1280            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
1281            $lang['current'];
1282
1283        $r_rev = '';
1284        $r_text = cleanText($text);
1285        $r_head = $lang['yours'];
1286    } else {
1287        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
1288            // make sure order is correct (older on the left)
1289            if($rev1 < $rev2) {
1290                $l_rev = $rev1;
1291                $r_rev = $rev2;
1292            } else {
1293                $l_rev = $rev2;
1294                $r_rev = $rev1;
1295            }
1296        } elseif($rev1) { // single revision given, compare to current
1297            $r_rev = '';
1298            $l_rev = $rev1;
1299        } else { // no revision was given, compare previous to current
1300            $r_rev = '';
1301            $revs = $pagelog->getRevisions(0, 1);
1302            $l_rev = $revs[0];
1303            $REV = $l_rev; // store revision back in $REV
1304        }
1305
1306        // when both revisions are empty then the page was created just now
1307        if(!$l_rev && !$r_rev) {
1308            $l_text = '';
1309        } else {
1310            $l_text = rawWiki($ID, $l_rev);
1311        }
1312        $r_text = rawWiki($ID, $r_rev);
1313
1314        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1315    }
1316
1317    /*
1318     * Build navigation
1319     */
1320    $l_nav = '';
1321    $r_nav = '';
1322    if(!$text) {
1323        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1324    }
1325    /*
1326     * Create diff object and the formatter
1327     */
1328    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
1329
1330    if($type == 'inline') {
1331        $diffformatter = new InlineDiffFormatter();
1332    } else {
1333        $diffformatter = new TableDiffFormatter();
1334    }
1335    /*
1336     * Display intro
1337     */
1338    if($intro) print p_locale_xhtml('diff');
1339
1340    /*
1341     * Display type and exact reference
1342     */
1343    if(!$text) {
1344        ptln('<div class="diffoptions group">');
1345
1346
1347        $form = new Doku_Form(array('action' => wl()));
1348        $form->addHidden('id', $ID);
1349        $form->addHidden('rev2[0]', $l_rev);
1350        $form->addHidden('rev2[1]', $r_rev);
1351        $form->addHidden('do', 'diff');
1352        $form->addElement(
1353             form_makeListboxField(
1354                 'difftype',
1355                 array(
1356                     'sidebyside' => $lang['diff_side'],
1357                     'inline' => $lang['diff_inline']
1358                 ),
1359                 $type,
1360                 $lang['diff_type'],
1361                 '', '',
1362                 array('class' => 'quickselect')
1363             )
1364        );
1365        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1366        $form->printForm();
1367
1368        ptln('<p>');
1369        // link to exactly this view FS#2835
1370        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
1371        ptln('</p>');
1372
1373        ptln('</div>'); // .diffoptions
1374    }
1375
1376    /*
1377     * Display diff view table
1378     */
1379    ?>
1380    <div class="table">
1381    <table class="diff diff_<?php echo $type ?>">
1382
1383        <?php
1384        //navigation and header
1385        if($type == 'inline') {
1386            if(!$text) { ?>
1387                <tr>
1388                    <td class="diff-lineheader">-</td>
1389                    <td class="diffnav"><?php echo $l_nav ?></td>
1390                </tr>
1391                <tr>
1392                    <th class="diff-lineheader">-</th>
1393                    <th <?php echo $l_minor ?>>
1394                        <?php echo $l_head ?>
1395                    </th>
1396                </tr>
1397            <?php } ?>
1398            <tr>
1399                <td class="diff-lineheader">+</td>
1400                <td class="diffnav"><?php echo $r_nav ?></td>
1401            </tr>
1402            <tr>
1403                <th class="diff-lineheader">+</th>
1404                <th <?php echo $r_minor ?>>
1405                    <?php echo $r_head ?>
1406                </th>
1407            </tr>
1408        <?php } else {
1409            if(!$text) { ?>
1410                <tr>
1411                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1412                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1413                </tr>
1414            <?php } ?>
1415            <tr>
1416                <th colspan="2" <?php echo $l_minor ?>>
1417                    <?php echo $l_head ?>
1418                </th>
1419                <th colspan="2" <?php echo $r_minor ?>>
1420                    <?php echo $r_head ?>
1421                </th>
1422            </tr>
1423        <?php }
1424
1425        //diff view
1426        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1427
1428    </table>
1429    </div>
1430<?php
1431}
1432
1433/**
1434 * Create html for revision navigation
1435 *
1436 * @param PageChangeLog $pagelog changelog object of current page
1437 * @param string        $type    inline vs sidebyside
1438 * @param int           $l_rev   left revision timestamp
1439 * @param int           $r_rev   right revision timestamp
1440 * @return string[] html of left and right navigation elements
1441 */
1442function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1443    global $INFO, $ID;
1444
1445    // last timestamp is not in changelog, retrieve timestamp from metadata
1446    // note: when page is removed, the metadata timestamp is zero
1447    if(!$r_rev) {
1448        if(isset($INFO['meta']['last_change']['date'])) {
1449            $r_rev = $INFO['meta']['last_change']['date'];
1450        } else {
1451            $r_rev = 0;
1452        }
1453    }
1454
1455    //retrieve revisions with additional info
1456    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1457    $l_revisions = array();
1458    if(!$l_rev) {
1459        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1460    }
1461    foreach($l_revs as $rev) {
1462        $info = $pagelog->getRevisionInfo($rev);
1463        $l_revisions[$rev] = array(
1464            $rev,
1465            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1466            $r_rev ? $rev >= $r_rev : false //disable?
1467        );
1468    }
1469    $r_revisions = array();
1470    if(!$r_rev) {
1471        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1472    }
1473    foreach($r_revs as $rev) {
1474        $info = $pagelog->getRevisionInfo($rev);
1475        $r_revisions[$rev] = array(
1476            $rev,
1477            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1478            $rev <= $l_rev //disable?
1479        );
1480    }
1481
1482    //determine previous/next revisions
1483    $l_index = array_search($l_rev, $l_revs);
1484    $l_prev = $l_revs[$l_index + 1];
1485    $l_next = $l_revs[$l_index - 1];
1486    if($r_rev) {
1487        $r_index = array_search($r_rev, $r_revs);
1488        $r_prev = $r_revs[$r_index + 1];
1489        $r_next = $r_revs[$r_index - 1];
1490    } else {
1491        //removed page
1492        if($l_next) {
1493            $r_prev = $r_revs[0];
1494        } else {
1495            $r_prev = null;
1496        }
1497        $r_next = null;
1498    }
1499
1500    /*
1501     * Left side:
1502     */
1503    $l_nav = '';
1504    //move back
1505    if($l_prev) {
1506        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1507        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1508    }
1509    //dropdown
1510    $form = new Doku_Form(array('action' => wl()));
1511    $form->addHidden('id', $ID);
1512    $form->addHidden('difftype', $type);
1513    $form->addHidden('rev2[1]', $r_rev);
1514    $form->addHidden('do', 'diff');
1515    $form->addElement(
1516         form_makeListboxField(
1517             'rev2[0]',
1518             $l_revisions,
1519             $l_rev,
1520             '', '', '',
1521             array('class' => 'quickselect')
1522         )
1523    );
1524    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1525    $l_nav .= $form->getForm();
1526    //move forward
1527    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1528        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1529    }
1530
1531    /*
1532     * Right side:
1533     */
1534    $r_nav = '';
1535    //move back
1536    if($l_rev < $r_prev) {
1537        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1538    }
1539    //dropdown
1540    $form = new Doku_Form(array('action' => wl()));
1541    $form->addHidden('id', $ID);
1542    $form->addHidden('rev2[0]', $l_rev);
1543    $form->addHidden('difftype', $type);
1544    $form->addHidden('do', 'diff');
1545    $form->addElement(
1546         form_makeListboxField(
1547             'rev2[1]',
1548             $r_revisions,
1549             $r_rev,
1550             '', '', '',
1551             array('class' => 'quickselect')
1552         )
1553    );
1554    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1555    $r_nav .= $form->getForm();
1556    //move forward
1557    if($r_next) {
1558        if($pagelog->isCurrentRevision($r_next)) {
1559            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1560        } else {
1561            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1562        }
1563        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1564    }
1565    return array($l_nav, $r_nav);
1566}
1567
1568/**
1569 * Create html link to a diff defined by two revisions
1570 *
1571 * @param string $difftype display type
1572 * @param string $linktype
1573 * @param int $lrev oldest revision
1574 * @param int $rrev newest revision or null for diff with current revision
1575 * @return string html of link to a diff
1576 */
1577function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
1578    global $ID, $lang;
1579    if(!$rrev) {
1580        $urlparam = array(
1581            'do' => 'diff',
1582            'rev' => $lrev,
1583            'difftype' => $difftype,
1584        );
1585    } else {
1586        $urlparam = array(
1587            'do' => 'diff',
1588            'rev2[0]' => $lrev,
1589            'rev2[1]' => $rrev,
1590            'difftype' => $difftype,
1591        );
1592    }
1593    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1594                '<span>' . $lang[$linktype] . '</span>' .
1595            '</a>' . "\n";
1596}
1597
1598/**
1599 * Insert soft breaks in diff html
1600 *
1601 * @param string $diffhtml
1602 * @return string
1603 */
1604function html_insert_softbreaks($diffhtml) {
1605    // search the diff html string for both:
1606    // - html tags, so these can be ignored
1607    // - long strings of characters without breaking characters
1608    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1609}
1610
1611/**
1612 * callback which adds softbreaks
1613 *
1614 * @param array $match array with first the complete match
1615 * @return string the replacement
1616 */
1617function html_softbreak_callback($match){
1618    // if match is an html tag, return it intact
1619    if ($match[0]{0} == '<') return $match[0];
1620
1621    // its a long string without a breaking character,
1622    // make certain characters into breaking characters by inserting a
1623    // breaking character (zero length space, U+200B / #8203) in front them.
1624    $regex = <<< REGEX
1625(?(?=                                 # start a conditional expression with a positive look ahead ...
1626&\#?\\w{1,6};)                        # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1627&\#?\\w{1,6};                         # yes pattern - a quicker match for the html entity, since we know we have one
1628|
1629[?/,&\#;:]                            # no pattern - any other group of 'special' characters to insert a breaking character after
1630)+                                    # end conditional expression
1631REGEX;
1632
1633    return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1634}
1635
1636/**
1637 * show warning on conflict detection
1638 *
1639 * @author Andreas Gohr <andi@splitbrain.org>
1640 *
1641 * @param string $text
1642 * @param string $summary
1643 */
1644function html_conflict($text,$summary){
1645    global $ID;
1646    global $lang;
1647
1648    print p_locale_xhtml('conflict');
1649    $form = new Doku_Form(array('id' => 'dw__editform'));
1650    $form->addHidden('id', $ID);
1651    $form->addHidden('wikitext', $text);
1652    $form->addHidden('summary', $summary);
1653    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1654    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1655    html_form('conflict', $form);
1656    print '<br /><br /><br /><br />'.NL;
1657}
1658
1659/**
1660 * Prints the global message array
1661 *
1662 * @author Andreas Gohr <andi@splitbrain.org>
1663 */
1664function html_msgarea(){
1665    global $MSG, $MSG_shown;
1666    /** @var array $MSG */
1667    // store if the global $MSG has already been shown and thus HTML output has been started
1668    $MSG_shown = true;
1669
1670    if(!isset($MSG)) return;
1671
1672    $shown = array();
1673    foreach($MSG as $msg){
1674        $hash = md5($msg['msg']);
1675        if(isset($shown[$hash])) continue; // skip double messages
1676        if(info_msg_allowed($msg)){
1677            print '<div class="'.$msg['lvl'].'">';
1678            print $msg['msg'];
1679            print '</div>';
1680        }
1681        $shown[$hash] = 1;
1682    }
1683
1684    unset($GLOBALS['MSG']);
1685}
1686
1687/**
1688 * Prints the registration form
1689 *
1690 * @author Andreas Gohr <andi@splitbrain.org>
1691 */
1692function html_register(){
1693    global $lang;
1694    global $conf;
1695    global $INPUT;
1696
1697    $base_attrs = array('size'=>50,'required'=>'required');
1698    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1699
1700    print p_locale_xhtml('register');
1701    print '<div class="centeralign">'.NL;
1702    $form = new Doku_Form(array('id' => 'dw__register'));
1703    $form->startFieldset($lang['btn_register']);
1704    $form->addHidden('do', 'register');
1705    $form->addHidden('save', '1');
1706    $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1707    if (!$conf['autopasswd']) {
1708        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1709        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1710    }
1711    $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1712    $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1713    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1714    $form->endFieldset();
1715    html_form('register', $form);
1716
1717    print '</div>'.NL;
1718}
1719
1720/**
1721 * Print the update profile form
1722 *
1723 * @author Christopher Smith <chris@jalakai.co.uk>
1724 * @author Andreas Gohr <andi@splitbrain.org>
1725 */
1726function html_updateprofile(){
1727    global $lang;
1728    global $conf;
1729    global $INPUT;
1730    global $INFO;
1731    /** @var DokuWiki_Auth_Plugin $auth */
1732    global $auth;
1733
1734    print p_locale_xhtml('updateprofile');
1735    print '<div class="centeralign">'.NL;
1736
1737    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1738    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1739    $form = new Doku_Form(array('id' => 'dw__register'));
1740    $form->startFieldset($lang['profile']);
1741    $form->addHidden('do', 'profile');
1742    $form->addHidden('save', '1');
1743    $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1744    $attr = array('size'=>'50');
1745    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1746    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1747    $attr = array('size'=>'50', 'class'=>'edit');
1748    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1749    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1750    $form->addElement(form_makeTag('br'));
1751    if ($auth->canDo('modPass')) {
1752        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1753        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1754    }
1755    if ($conf['profileconfirm']) {
1756        $form->addElement(form_makeTag('br'));
1757        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1758    }
1759    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1760    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1761
1762    $form->endFieldset();
1763    html_form('updateprofile', $form);
1764
1765    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1766        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1767        $form_profiledelete->startFieldset($lang['profdeleteuser']);
1768        $form_profiledelete->addHidden('do', 'profile_delete');
1769        $form_profiledelete->addHidden('delete', '1');
1770        $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1771        if ($conf['profileconfirm']) {
1772            $form_profiledelete->addElement(form_makeTag('br'));
1773            $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1774        }
1775        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1776        $form_profiledelete->endFieldset();
1777
1778        html_form('profiledelete', $form_profiledelete);
1779    }
1780
1781    print '</div>'.NL;
1782}
1783
1784/**
1785 * Preprocess edit form data
1786 *
1787 * @author   Andreas Gohr <andi@splitbrain.org>
1788 *
1789 * @triggers HTML_EDITFORM_OUTPUT
1790 */
1791function html_edit(){
1792    global $INPUT;
1793    global $ID;
1794    global $REV;
1795    global $DATE;
1796    global $PRE;
1797    global $SUF;
1798    global $INFO;
1799    global $SUM;
1800    global $lang;
1801    global $conf;
1802    global $TEXT;
1803
1804    if ($INPUT->has('changecheck')) {
1805        $check = $INPUT->str('changecheck');
1806    } elseif(!$INFO['exists']){
1807        // $TEXT has been loaded from page template
1808        $check = md5('');
1809    } else {
1810        $check = md5($TEXT);
1811    }
1812    $mod = md5($TEXT) !== $check;
1813
1814    $wr = $INFO['writable'] && !$INFO['locked'];
1815    $include = 'edit';
1816    if($wr){
1817        if ($REV) $include = 'editrev';
1818    }else{
1819        // check pseudo action 'source'
1820        if(!actionOK('source')){
1821            msg('Command disabled: source',-1);
1822            return;
1823        }
1824        $include = 'read';
1825    }
1826
1827    global $license;
1828
1829    $form = new Doku_Form(array('id' => 'dw__editform'));
1830    $form->addHidden('id', $ID);
1831    $form->addHidden('rev', $REV);
1832    $form->addHidden('date', $DATE);
1833    $form->addHidden('prefix', $PRE . '.');
1834    $form->addHidden('suffix', $SUF);
1835    $form->addHidden('changecheck', $check);
1836
1837    $data = array('form' => $form,
1838                  'wr'   => $wr,
1839                  'media_manager' => true,
1840                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1841                  'intro_locale' => $include);
1842
1843    if ($data['target'] !== 'section') {
1844        // Only emit event if page is writable, section edit data is valid and
1845        // edit target is not section.
1846        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1847    } else {
1848        html_edit_form($data);
1849    }
1850    if (isset($data['intro_locale'])) {
1851        echo p_locale_xhtml($data['intro_locale']);
1852    }
1853
1854    $form->addHidden('target', $data['target']);
1855    if ($INPUT->has('hid')) {
1856        $form->addHidden('hid', $INPUT->str('hid'));
1857    }
1858    if ($INPUT->has('codeblockOffset')) {
1859        $form->addHidden('codeblockOffset', $INPUT->str('codeblockOffset'));
1860    }
1861    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1862    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1863    $form->addElement(form_makeCloseTag('div'));
1864    if ($wr) {
1865        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1866        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1867        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1868        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1869        $form->addElement(form_makeCloseTag('div'));
1870        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1871        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1872        $elem = html_minoredit();
1873        if ($elem) $form->addElement($elem);
1874        $form->addElement(form_makeCloseTag('div'));
1875    }
1876    $form->addElement(form_makeCloseTag('div'));
1877    if($wr && $conf['license']){
1878        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1879        $out  = $lang['licenseok'];
1880        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1881        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1882        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1883        $form->addElement($out);
1884        $form->addElement(form_makeCloseTag('div'));
1885    }
1886
1887    if ($wr) {
1888        // sets changed to true when previewed
1889        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1890        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1891        echo '/*!]]>*/</script>' . NL;
1892    } ?>
1893    <div class="editBox" role="application">
1894
1895    <div class="toolbar group">
1896        <div id="draft__status" class="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1897        <div id="tool__bar" class="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1898            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1899    </div>
1900    <?php
1901
1902    html_form('edit', $form);
1903    print '</div>'.NL;
1904}
1905
1906/**
1907 * Display the default edit form
1908 *
1909 * Is the default action for HTML_EDIT_FORMSELECTION.
1910 *
1911 * @param mixed[] $param
1912 */
1913function html_edit_form($param) {
1914    global $TEXT;
1915
1916    if ($param['target'] !== 'section') {
1917        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1918    }
1919
1920    $attr = array('tabindex'=>'1');
1921    if (!$param['wr']) $attr['readonly'] = 'readonly';
1922
1923    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1924}
1925
1926/**
1927 * Adds a checkbox for minor edits for logged in users
1928 *
1929 * @author Andreas Gohr <andi@splitbrain.org>
1930 *
1931 * @return array|bool
1932 */
1933function html_minoredit(){
1934    global $conf;
1935    global $lang;
1936    global $INPUT;
1937    // minor edits are for logged in users only
1938    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1939        return false;
1940    }
1941
1942    $p = array();
1943    $p['tabindex'] = 3;
1944    if($INPUT->bool('minor')) $p['checked']='checked';
1945    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1946}
1947
1948/**
1949 * prints some debug info
1950 *
1951 * @author Andreas Gohr <andi@splitbrain.org>
1952 */
1953function html_debug(){
1954    global $conf;
1955    global $lang;
1956    /** @var DokuWiki_Auth_Plugin $auth */
1957    global $auth;
1958    global $INFO;
1959
1960    //remove sensitive data
1961    $cnf = $conf;
1962    debug_guard($cnf);
1963    $nfo = $INFO;
1964    debug_guard($nfo);
1965    $ses = $_SESSION;
1966    debug_guard($ses);
1967
1968    print '<html><body>';
1969
1970    print '<p>When reporting bugs please send all the following ';
1971    print 'output as a mail to andi@splitbrain.org ';
1972    print 'The best way to do this is to save this page in your browser</p>';
1973
1974    print '<b>$INFO:</b><pre>';
1975    print_r($nfo);
1976    print '</pre>';
1977
1978    print '<b>$_SERVER:</b><pre>';
1979    print_r($_SERVER);
1980    print '</pre>';
1981
1982    print '<b>$conf:</b><pre>';
1983    print_r($cnf);
1984    print '</pre>';
1985
1986    print '<b>DOKU_BASE:</b><pre>';
1987    print DOKU_BASE;
1988    print '</pre>';
1989
1990    print '<b>abs DOKU_BASE:</b><pre>';
1991    print DOKU_URL;
1992    print '</pre>';
1993
1994    print '<b>rel DOKU_BASE:</b><pre>';
1995    print dirname($_SERVER['PHP_SELF']).'/';
1996    print '</pre>';
1997
1998    print '<b>PHP Version:</b><pre>';
1999    print phpversion();
2000    print '</pre>';
2001
2002    print '<b>locale:</b><pre>';
2003    print setlocale(LC_ALL,0);
2004    print '</pre>';
2005
2006    print '<b>encoding:</b><pre>';
2007    print $lang['encoding'];
2008    print '</pre>';
2009
2010    if($auth){
2011        print '<b>Auth backend capabilities:</b><pre>';
2012        foreach ($auth->getCapabilities() as $cando){
2013            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
2014        }
2015        print '</pre>';
2016    }
2017
2018    print '<b>$_SESSION:</b><pre>';
2019    print_r($ses);
2020    print '</pre>';
2021
2022    print '<b>Environment:</b><pre>';
2023    print_r($_ENV);
2024    print '</pre>';
2025
2026    print '<b>PHP settings:</b><pre>';
2027    $inis = ini_get_all();
2028    print_r($inis);
2029    print '</pre>';
2030
2031    if (function_exists('apache_get_version')) {
2032        $apache = array();
2033        $apache['version'] = apache_get_version();
2034
2035        if (function_exists('apache_get_modules')) {
2036            $apache['modules'] = apache_get_modules();
2037        }
2038        print '<b>Apache</b><pre>';
2039        print_r($apache);
2040        print '</pre>';
2041    }
2042
2043    print '</body></html>';
2044}
2045
2046/**
2047 * Form to request a new password for an existing account
2048 *
2049 * @author Benoit Chesneau <benoit@bchesneau.info>
2050 * @author Andreas Gohr <gohr@cosmocode.de>
2051 */
2052function html_resendpwd() {
2053    global $lang;
2054    global $conf;
2055    global $INPUT;
2056
2057    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2058
2059    if(!$conf['autopasswd'] && $token){
2060        print p_locale_xhtml('resetpwd');
2061        print '<div class="centeralign">'.NL;
2062        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2063        $form->startFieldset($lang['btn_resendpwd']);
2064        $form->addHidden('token', $token);
2065        $form->addHidden('do', 'resendpwd');
2066
2067        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2068        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2069
2070        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2071        $form->endFieldset();
2072        html_form('resendpwd', $form);
2073        print '</div>'.NL;
2074    }else{
2075        print p_locale_xhtml('resendpwd');
2076        print '<div class="centeralign">'.NL;
2077        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2078        $form->startFieldset($lang['resendpwd']);
2079        $form->addHidden('do', 'resendpwd');
2080        $form->addHidden('save', '1');
2081        $form->addElement(form_makeTag('br'));
2082        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2083        $form->addElement(form_makeTag('br'));
2084        $form->addElement(form_makeTag('br'));
2085        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2086        $form->endFieldset();
2087        html_form('resendpwd', $form);
2088        print '</div>'.NL;
2089    }
2090}
2091
2092/**
2093 * Return the TOC rendered to XHTML
2094 *
2095 * @author Andreas Gohr <andi@splitbrain.org>
2096 *
2097 * @param array $toc
2098 * @return string html
2099 */
2100function html_TOC($toc){
2101    if(!count($toc)) return '';
2102    global $lang;
2103    $out  = '<!-- TOC START -->'.DOKU_LF;
2104    $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF;
2105    $out .= '<h3 class="toggle">';
2106    $out .= $lang['toc'];
2107    $out .= '</h3>'.DOKU_LF;
2108    $out .= '<div>'.DOKU_LF;
2109    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2110    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2111    $out .= '<!-- TOC END -->'.DOKU_LF;
2112    return $out;
2113}
2114
2115/**
2116 * Callback for html_buildlist
2117 *
2118 * @param array $item
2119 * @return string html
2120 */
2121function html_list_toc($item){
2122    if(isset($item['hid'])){
2123        $link = '#'.$item['hid'];
2124    }else{
2125        $link = $item['link'];
2126    }
2127
2128    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2129}
2130
2131/**
2132 * Helper function to build TOC items
2133 *
2134 * Returns an array ready to be added to a TOC array
2135 *
2136 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2137 * @param string $text  - what to display in the TOC
2138 * @param int    $level - nesting level
2139 * @param string $hash  - is prepended to the given $link, set blank if you want full links
2140 * @return array the toc item
2141 */
2142function html_mktocitem($link, $text, $level, $hash='#'){
2143    return  array( 'link'  => $hash.$link,
2144            'title' => $text,
2145            'type'  => 'ul',
2146            'level' => $level);
2147}
2148
2149/**
2150 * Output a Doku_Form object.
2151 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2152 *
2153 * @author Tom N Harris <tnharris@whoopdedo.org>
2154 *
2155 * @param string     $name The name of the form
2156 * @param Doku_Form  $form The form
2157 */
2158function html_form($name, &$form) {
2159    // Safety check in case the caller forgets.
2160    $form->endFieldset();
2161    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2162}
2163
2164/**
2165 * Form print function.
2166 * Just calls printForm() on the data object.
2167 *
2168 * @param Doku_Form $data The form
2169 */
2170function html_form_output($data) {
2171    $data->printForm();
2172}
2173
2174/**
2175 * Embed a flash object in HTML
2176 *
2177 * This will create the needed HTML to embed a flash movie in a cross browser
2178 * compatble way using valid XHTML
2179 *
2180 * The parameters $params, $flashvars and $atts need to be associative arrays.
2181 * No escaping needs to be done for them. The alternative content *has* to be
2182 * escaped because it is used as is. If no alternative content is given
2183 * $lang['noflash'] is used.
2184 *
2185 * @author Andreas Gohr <andi@splitbrain.org>
2186 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
2187 *
2188 * @param string $swf      - the SWF movie to embed
2189 * @param int $width       - width of the flash movie in pixels
2190 * @param int $height      - height of the flash movie in pixels
2191 * @param array $params    - additional parameters (<param>)
2192 * @param array $flashvars - parameters to be passed in the flashvar parameter
2193 * @param array $atts      - additional attributes for the <object> tag
2194 * @param string $alt      - alternative content (is NOT automatically escaped!)
2195 * @return string         - the XHTML markup
2196 */
2197function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
2198    global $lang;
2199
2200    $out = '';
2201
2202    // prepare the object attributes
2203    if(is_null($atts)) $atts = array();
2204    $atts['width']  = (int) $width;
2205    $atts['height'] = (int) $height;
2206    if(!$atts['width'])  $atts['width']  = 425;
2207    if(!$atts['height']) $atts['height'] = 350;
2208
2209    // add object attributes for standard compliant browsers
2210    $std = $atts;
2211    $std['type'] = 'application/x-shockwave-flash';
2212    $std['data'] = $swf;
2213
2214    // add object attributes for IE
2215    $ie  = $atts;
2216    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
2217
2218    // open object (with conditional comments)
2219    $out .= '<!--[if !IE]> -->'.NL;
2220    $out .= '<object '.buildAttributes($std).'>'.NL;
2221    $out .= '<!-- <![endif]-->'.NL;
2222    $out .= '<!--[if IE]>'.NL;
2223    $out .= '<object '.buildAttributes($ie).'>'.NL;
2224    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
2225    $out .= '<!--><!-- -->'.NL;
2226
2227    // print params
2228    if(is_array($params)) foreach($params as $key => $val){
2229        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
2230    }
2231
2232    // add flashvars
2233    if(is_array($flashvars)){
2234        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
2235    }
2236
2237    // alternative content
2238    if($alt){
2239        $out .= $alt.NL;
2240    }else{
2241        $out .= $lang['noflash'].NL;
2242    }
2243
2244    // finish
2245    $out .= '</object>'.NL;
2246    $out .= '<!-- <![endif]-->'.NL;
2247
2248    return $out;
2249}
2250
2251/**
2252 * Prints HTML code for the given tab structure
2253 *
2254 * @param array  $tabs        tab structure
2255 * @param string $current_tab the current tab id
2256 */
2257function html_tabs($tabs, $current_tab = null) {
2258    echo '<ul class="tabs">'.NL;
2259
2260    foreach($tabs as $id => $tab) {
2261        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
2262    }
2263
2264    echo '</ul>'.NL;
2265}
2266
2267/**
2268 * Prints a single tab
2269 *
2270 * @author Kate Arzamastseva <pshns@ukr.net>
2271 * @author Adrian Lang <mail@adrianlang.de>
2272 *
2273 * @param string $href - tab href
2274 * @param string $caption - tab caption
2275 * @param boolean $selected - is tab selected
2276 */
2277
2278function html_tab($href, $caption, $selected=false) {
2279    $tab = '<li>';
2280    if ($selected) {
2281        $tab .= '<strong>';
2282    } else {
2283        $tab .= '<a href="' . hsc($href) . '">';
2284    }
2285    $tab .= hsc($caption)
2286         .  '</' . ($selected ? 'strong' : 'a') . '>'
2287         .  '</li>'.NL;
2288    echo $tab;
2289}
2290
2291/**
2292 * Display size change
2293 *
2294 * @param int $sizechange - size of change in Bytes
2295 * @param Doku_Form $form - form to add elements to
2296 */
2297
2298function html_sizechange($sizechange, Doku_Form $form) {
2299    if(isset($sizechange)) {
2300        $class = 'sizechange';
2301        $value = filesize_h(abs($sizechange));
2302        if($sizechange > 0) {
2303            $class .= ' positive';
2304            $value = '+' . $value;
2305        } elseif($sizechange < 0) {
2306            $class .= ' negative';
2307            $value = '-' . $value;
2308        } else {
2309            $value = '±' . $value;
2310        }
2311        $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2312        $form->addElement($value);
2313        $form->addElement(form_makeCloseTag('span'));
2314    }
2315}
2316