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