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