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