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