xref: /dokuwiki/inc/html.php (revision b5e63f63ddb301be0f0cebc0ce984b10332d72fb)
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
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    $start_level = $data[0]['level'];
1050    $level = $start_level;
1051    $ret   = '';
1052    $open  = 0;
1053
1054    foreach ($data as $item){
1055
1056        if( $item['level'] > $level ){
1057            //open new list
1058            for($i=0; $i<($item['level'] - $level); $i++){
1059                if ($i) $ret .= "<li class=\"clear\">";
1060                $ret .= "\n<ul class=\"$class\">\n";
1061                $open++;
1062            }
1063            $level = $item['level'];
1064
1065        }elseif( $item['level'] < $level ){
1066            //close last item
1067            $ret .= "</li>\n";
1068            while( $level > $item['level'] && $open > 0 ){
1069                //close higher lists
1070                $ret .= "</ul>\n</li>\n";
1071                $level--;
1072                $open--;
1073            }
1074        } elseif ($ret !== '') {
1075            //close previous item
1076            $ret .= "</li>\n";
1077        }
1078
1079        //print item
1080        $ret .= call_user_func($lifunc,$item);
1081        $ret .= '<div class="li">';
1082
1083        $ret .= call_user_func($func,$item);
1084        $ret .= '</div>';
1085    }
1086
1087    //close remaining items and lists
1088    $ret .= "</li>\n";
1089    while($open-- > 0) {
1090        $ret .= "</ul></li>\n";
1091    }
1092
1093    if ($forcewrapper || $start_level < 2) {
1094        // Trigger building a wrapper ul if the first level is
1095        // 0 (we have a root object) or 1 (just the root content)
1096        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1097    }
1098
1099    return $ret;
1100}
1101
1102/**
1103 * display backlinks
1104 *
1105 * @author Andreas Gohr <andi@splitbrain.org>
1106 * @author Michael Klier <chi@chimeric.de>
1107 */
1108function html_backlinks(){
1109    global $ID;
1110    global $lang;
1111
1112    print p_locale_xhtml('backlinks');
1113
1114    $data = ft_backlinks($ID);
1115
1116    if(!empty($data)) {
1117        print '<ul class="idx">';
1118        foreach($data as $blink){
1119            print '<li><div class="li">';
1120            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
1121            print '</div></li>';
1122        }
1123        print '</ul>';
1124    } else {
1125        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1126    }
1127}
1128
1129/**
1130 * Get header of diff HTML
1131 *
1132 * @param string $l_rev   Left revisions
1133 * @param string $r_rev   Right revision
1134 * @param string $id      Page id, if null $ID is used
1135 * @param bool   $media   If it is for media files
1136 * @param bool   $inline  Return the header on a single line
1137 * @return string[] HTML snippets for diff header
1138 */
1139function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1140    global $lang;
1141    if ($id === null) {
1142        global $ID;
1143        $id = $ID;
1144    }
1145    $head_separator = $inline ? ' ' : '<br />';
1146    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1147    $ml_or_wl = $media ? 'ml' : 'wl';
1148    $l_minor = $r_minor = '';
1149
1150    if($media) {
1151        $changelog = new MediaChangeLog($id);
1152    } else {
1153        $changelog = new PageChangeLog($id);
1154    }
1155    if(!$l_rev){
1156        $l_head = '&mdash;';
1157    }else{
1158        $l_info   = $changelog->getRevisionInfo($l_rev);
1159        if($l_info['user']){
1160            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1161            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1162        } else {
1163            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1164        }
1165        $l_user  = '<span class="user">'.$l_user.'</span>';
1166        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1167        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1168
1169        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1170        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1171        $l_head_title.'</a></bdi>'.
1172        $head_separator.$l_user.' '.$l_sum;
1173    }
1174
1175    if($r_rev){
1176        $r_info   = $changelog->getRevisionInfo($r_rev);
1177        if($r_info['user']){
1178            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1179            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1180        } else {
1181            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1182        }
1183        $r_user = '<span class="user">'.$r_user.'</span>';
1184        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1185        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1186
1187        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1188        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1189        $r_head_title.'</a></bdi>'.
1190        $head_separator.$r_user.' '.$r_sum;
1191    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1192        $_info   = $changelog->getRevisionInfo($_rev);
1193        if($_info['user']){
1194            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1195            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1196        } else {
1197            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1198        }
1199        $_user = '<span class="user">'.$_user.'</span>';
1200        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1201        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1202
1203        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1204        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1205        $r_head_title.'</a></bdi> '.
1206        '('.$lang['current'].')'.
1207        $head_separator.$_user.' '.$_sum;
1208    }else{
1209        $r_head = '&mdash; ('.$lang['current'].')';
1210    }
1211
1212    return array($l_head, $r_head, $l_minor, $r_minor);
1213}
1214
1215/**
1216 * Show diff
1217 * between current page version and provided $text
1218 * or between the revisions provided via GET or POST
1219 *
1220 * @author Andreas Gohr <andi@splitbrain.org>
1221 * @param  string $text  when non-empty: compare with this text with most current version
1222 * @param  bool   $intro display the intro text
1223 * @param  string $type  type of the diff (inline or sidebyside)
1224 */
1225function html_diff($text = '', $intro = true, $type = null) {
1226    global $ID;
1227    global $REV;
1228    global $lang;
1229    global $INPUT;
1230    global $INFO;
1231    $pagelog = new PageChangeLog($ID);
1232
1233    /*
1234     * Determine diff type
1235     */
1236    if(!$type) {
1237        $type = $INPUT->str('difftype');
1238        if(empty($type)) {
1239            $type = get_doku_pref('difftype', $type);
1240            if(empty($type) && $INFO['ismobile']) {
1241                $type = 'inline';
1242            }
1243        }
1244    }
1245    if($type != 'inline') $type = 'sidebyside';
1246
1247    /*
1248     * Determine requested revision(s)
1249     */
1250    // we're trying to be clever here, revisions to compare can be either
1251    // given as rev and rev2 parameters, with rev2 being optional. Or in an
1252    // array in rev2.
1253    $rev1 = $REV;
1254
1255    $rev2 = $INPUT->ref('rev2');
1256    if(is_array($rev2)) {
1257        $rev1 = (int) $rev2[0];
1258        $rev2 = (int) $rev2[1];
1259
1260        if(!$rev1) {
1261            $rev1 = $rev2;
1262            unset($rev2);
1263        }
1264    } else {
1265        $rev2 = $INPUT->int('rev2');
1266    }
1267
1268    /*
1269     * Determine left and right revision, its texts and the header
1270     */
1271    $r_minor = '';
1272    $l_minor = '';
1273
1274    if($text) { // compare text to the most current revision
1275        $l_rev = '';
1276        $l_text = rawWiki($ID, '');
1277        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1278            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
1279            $lang['current'];
1280
1281        $r_rev = '';
1282        $r_text = cleanText($text);
1283        $r_head = $lang['yours'];
1284    } else {
1285        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
1286            // make sure order is correct (older on the left)
1287            if($rev1 < $rev2) {
1288                $l_rev = $rev1;
1289                $r_rev = $rev2;
1290            } else {
1291                $l_rev = $rev2;
1292                $r_rev = $rev1;
1293            }
1294        } elseif($rev1) { // single revision given, compare to current
1295            $r_rev = '';
1296            $l_rev = $rev1;
1297        } else { // no revision was given, compare previous to current
1298            $r_rev = '';
1299            $revs = $pagelog->getRevisions(0, 1);
1300            $l_rev = $revs[0];
1301            $REV = $l_rev; // store revision back in $REV
1302        }
1303
1304        // when both revisions are empty then the page was created just now
1305        if(!$l_rev && !$r_rev) {
1306            $l_text = '';
1307        } else {
1308            $l_text = rawWiki($ID, $l_rev);
1309        }
1310        $r_text = rawWiki($ID, $r_rev);
1311
1312        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1313    }
1314
1315    /*
1316     * Build navigation
1317     */
1318    $l_nav = '';
1319    $r_nav = '';
1320    if(!$text) {
1321        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1322    }
1323    /*
1324     * Create diff object and the formatter
1325     */
1326    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
1327
1328    if($type == 'inline') {
1329        $diffformatter = new InlineDiffFormatter();
1330    } else {
1331        $diffformatter = new TableDiffFormatter();
1332    }
1333    /*
1334     * Display intro
1335     */
1336    if($intro) print p_locale_xhtml('diff');
1337
1338    /*
1339     * Display type and exact reference
1340     */
1341    if(!$text) {
1342        ptln('<div class="diffoptions group">');
1343
1344
1345        $form = new Doku_Form(array('action' => wl()));
1346        $form->addHidden('id', $ID);
1347        $form->addHidden('rev2[0]', $l_rev);
1348        $form->addHidden('rev2[1]', $r_rev);
1349        $form->addHidden('do', 'diff');
1350        $form->addElement(
1351             form_makeListboxField(
1352                 'difftype',
1353                 array(
1354                     'sidebyside' => $lang['diff_side'],
1355                     'inline' => $lang['diff_inline']
1356                 ),
1357                 $type,
1358                 $lang['diff_type'],
1359                 '', '',
1360                 array('class' => 'quickselect')
1361             )
1362        );
1363        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1364        $form->printForm();
1365
1366        ptln('<p>');
1367        // link to exactly this view FS#2835
1368        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
1369        ptln('</p>');
1370
1371        ptln('</div>'); // .diffoptions
1372    }
1373
1374    /*
1375     * Display diff view table
1376     */
1377    ?>
1378    <div class="table">
1379    <table class="diff diff_<?php echo $type ?>">
1380
1381        <?php
1382        //navigation and header
1383        if($type == 'inline') {
1384            if(!$text) { ?>
1385                <tr>
1386                    <td class="diff-lineheader">-</td>
1387                    <td class="diffnav"><?php echo $l_nav ?></td>
1388                </tr>
1389                <tr>
1390                    <th class="diff-lineheader">-</th>
1391                    <th <?php echo $l_minor ?>>
1392                        <?php echo $l_head ?>
1393                    </th>
1394                </tr>
1395            <?php } ?>
1396            <tr>
1397                <td class="diff-lineheader">+</td>
1398                <td class="diffnav"><?php echo $r_nav ?></td>
1399            </tr>
1400            <tr>
1401                <th class="diff-lineheader">+</th>
1402                <th <?php echo $r_minor ?>>
1403                    <?php echo $r_head ?>
1404                </th>
1405            </tr>
1406        <?php } else {
1407            if(!$text) { ?>
1408                <tr>
1409                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1410                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1411                </tr>
1412            <?php } ?>
1413            <tr>
1414                <th colspan="2" <?php echo $l_minor ?>>
1415                    <?php echo $l_head ?>
1416                </th>
1417                <th colspan="2" <?php echo $r_minor ?>>
1418                    <?php echo $r_head ?>
1419                </th>
1420            </tr>
1421        <?php }
1422
1423        //diff view
1424        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1425
1426    </table>
1427    </div>
1428<?php
1429}
1430
1431/**
1432 * Create html for revision navigation
1433 *
1434 * @param PageChangeLog $pagelog changelog object of current page
1435 * @param string        $type    inline vs sidebyside
1436 * @param int           $l_rev   left revision timestamp
1437 * @param int           $r_rev   right revision timestamp
1438 * @return string[] html of left and right navigation elements
1439 */
1440function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1441    global $INFO, $ID;
1442
1443    // last timestamp is not in changelog, retrieve timestamp from metadata
1444    // note: when page is removed, the metadata timestamp is zero
1445    if(!$r_rev) {
1446        if(isset($INFO['meta']['last_change']['date'])) {
1447            $r_rev = $INFO['meta']['last_change']['date'];
1448        } else {
1449            $r_rev = 0;
1450        }
1451    }
1452
1453    //retrieve revisions with additional info
1454    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1455    $l_revisions = array();
1456    if(!$l_rev) {
1457        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1458    }
1459    foreach($l_revs as $rev) {
1460        $info = $pagelog->getRevisionInfo($rev);
1461        $l_revisions[$rev] = array(
1462            $rev,
1463            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1464            $r_rev ? $rev >= $r_rev : false //disable?
1465        );
1466    }
1467    $r_revisions = array();
1468    if(!$r_rev) {
1469        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1470    }
1471    foreach($r_revs as $rev) {
1472        $info = $pagelog->getRevisionInfo($rev);
1473        $r_revisions[$rev] = array(
1474            $rev,
1475            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1476            $rev <= $l_rev //disable?
1477        );
1478    }
1479
1480    //determine previous/next revisions
1481    $l_index = array_search($l_rev, $l_revs);
1482    $l_prev = $l_revs[$l_index + 1];
1483    $l_next = $l_revs[$l_index - 1];
1484    if($r_rev) {
1485        $r_index = array_search($r_rev, $r_revs);
1486        $r_prev = $r_revs[$r_index + 1];
1487        $r_next = $r_revs[$r_index - 1];
1488    } else {
1489        //removed page
1490        if($l_next) {
1491            $r_prev = $r_revs[0];
1492        } else {
1493            $r_prev = null;
1494        }
1495        $r_next = null;
1496    }
1497
1498    /*
1499     * Left side:
1500     */
1501    $l_nav = '';
1502    //move back
1503    if($l_prev) {
1504        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1505        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1506    }
1507    //dropdown
1508    $form = new Doku_Form(array('action' => wl()));
1509    $form->addHidden('id', $ID);
1510    $form->addHidden('difftype', $type);
1511    $form->addHidden('rev2[1]', $r_rev);
1512    $form->addHidden('do', 'diff');
1513    $form->addElement(
1514         form_makeListboxField(
1515             'rev2[0]',
1516             $l_revisions,
1517             $l_rev,
1518             '', '', '',
1519             array('class' => 'quickselect')
1520         )
1521    );
1522    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1523    $l_nav .= $form->getForm();
1524    //move forward
1525    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1526        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1527    }
1528
1529    /*
1530     * Right side:
1531     */
1532    $r_nav = '';
1533    //move back
1534    if($l_rev < $r_prev) {
1535        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1536    }
1537    //dropdown
1538    $form = new Doku_Form(array('action' => wl()));
1539    $form->addHidden('id', $ID);
1540    $form->addHidden('rev2[0]', $l_rev);
1541    $form->addHidden('difftype', $type);
1542    $form->addHidden('do', 'diff');
1543    $form->addElement(
1544         form_makeListboxField(
1545             'rev2[1]',
1546             $r_revisions,
1547             $r_rev,
1548             '', '', '',
1549             array('class' => 'quickselect')
1550         )
1551    );
1552    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1553    $r_nav .= $form->getForm();
1554    //move forward
1555    if($r_next) {
1556        if($pagelog->isCurrentRevision($r_next)) {
1557            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1558        } else {
1559            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1560        }
1561        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1562    }
1563    return array($l_nav, $r_nav);
1564}
1565
1566/**
1567 * Create html link to a diff defined by two revisions
1568 *
1569 * @param string $difftype display type
1570 * @param string $linktype
1571 * @param int $lrev oldest revision
1572 * @param int $rrev newest revision or null for diff with current revision
1573 * @return string html of link to a diff
1574 */
1575function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
1576    global $ID, $lang;
1577    if(!$rrev) {
1578        $urlparam = array(
1579            'do' => 'diff',
1580            'rev' => $lrev,
1581            'difftype' => $difftype,
1582        );
1583    } else {
1584        $urlparam = array(
1585            'do' => 'diff',
1586            'rev2[0]' => $lrev,
1587            'rev2[1]' => $rrev,
1588            'difftype' => $difftype,
1589        );
1590    }
1591    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1592                '<span>' . $lang[$linktype] . '</span>' .
1593            '</a>' . "\n";
1594}
1595
1596/**
1597 * Insert soft breaks in diff html
1598 *
1599 * @param string $diffhtml
1600 * @return string
1601 */
1602function html_insert_softbreaks($diffhtml) {
1603    // search the diff html string for both:
1604    // - html tags, so these can be ignored
1605    // - long strings of characters without breaking characters
1606    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1607}
1608
1609/**
1610 * callback which adds softbreaks
1611 *
1612 * @param array $match array with first the complete match
1613 * @return string the replacement
1614 */
1615function html_softbreak_callback($match){
1616    // if match is an html tag, return it intact
1617    if ($match[0]{0} == '<') return $match[0];
1618
1619    // its a long string without a breaking character,
1620    // make certain characters into breaking characters by inserting a
1621    // breaking character (zero length space, U+200B / #8203) in front them.
1622    $regex = <<< REGEX
1623(?(?=                                 # start a conditional expression with a positive look ahead ...
1624&\#?\\w{1,6};)                        # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1625&\#?\\w{1,6};                         # yes pattern - a quicker match for the html entity, since we know we have one
1626|
1627[?/,&\#;:]                            # no pattern - any other group of 'special' characters to insert a breaking character after
1628)+                                    # end conditional expression
1629REGEX;
1630
1631    return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1632}
1633
1634/**
1635 * show warning on conflict detection
1636 *
1637 * @author Andreas Gohr <andi@splitbrain.org>
1638 *
1639 * @param string $text
1640 * @param string $summary
1641 */
1642function html_conflict($text,$summary){
1643    global $ID;
1644    global $lang;
1645
1646    print p_locale_xhtml('conflict');
1647    $form = new Doku_Form(array('id' => 'dw__editform'));
1648    $form->addHidden('id', $ID);
1649    $form->addHidden('wikitext', $text);
1650    $form->addHidden('summary', $summary);
1651    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1652    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1653    html_form('conflict', $form);
1654    print '<br /><br /><br /><br />'.NL;
1655}
1656
1657/**
1658 * Prints the global message array
1659 *
1660 * @author Andreas Gohr <andi@splitbrain.org>
1661 */
1662function html_msgarea(){
1663    global $MSG, $MSG_shown;
1664    /** @var array $MSG */
1665    // store if the global $MSG has already been shown and thus HTML output has been started
1666    $MSG_shown = true;
1667
1668    if(!isset($MSG)) return;
1669
1670    $shown = array();
1671    foreach($MSG as $msg){
1672        $hash = md5($msg['msg']);
1673        if(isset($shown[$hash])) continue; // skip double messages
1674        if(info_msg_allowed($msg)){
1675            print '<div class="'.$msg['lvl'].'">';
1676            print $msg['msg'];
1677            print '</div>';
1678        }
1679        $shown[$hash] = 1;
1680    }
1681
1682    unset($GLOBALS['MSG']);
1683}
1684
1685/**
1686 * Prints the registration form
1687 *
1688 * @author Andreas Gohr <andi@splitbrain.org>
1689 */
1690function html_register(){
1691    global $lang;
1692    global $conf;
1693    global $INPUT;
1694
1695    $base_attrs = array('size'=>50,'required'=>'required');
1696    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1697
1698    print p_locale_xhtml('register');
1699    print '<div class="centeralign">'.NL;
1700    $form = new Doku_Form(array('id' => 'dw__register'));
1701    $form->startFieldset($lang['btn_register']);
1702    $form->addHidden('do', 'register');
1703    $form->addHidden('save', '1');
1704    $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1705    if (!$conf['autopasswd']) {
1706        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1707        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1708    }
1709    $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1710    $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1711    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1712    $form->endFieldset();
1713    html_form('register', $form);
1714
1715    print '</div>'.NL;
1716}
1717
1718/**
1719 * Print the update profile form
1720 *
1721 * @author Christopher Smith <chris@jalakai.co.uk>
1722 * @author Andreas Gohr <andi@splitbrain.org>
1723 */
1724function html_updateprofile(){
1725    global $lang;
1726    global $conf;
1727    global $INPUT;
1728    global $INFO;
1729    /** @var DokuWiki_Auth_Plugin $auth */
1730    global $auth;
1731
1732    print p_locale_xhtml('updateprofile');
1733    print '<div class="centeralign">'.NL;
1734
1735    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1736    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1737    $form = new Doku_Form(array('id' => 'dw__register'));
1738    $form->startFieldset($lang['profile']);
1739    $form->addHidden('do', 'profile');
1740    $form->addHidden('save', '1');
1741    $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1742    $attr = array('size'=>'50');
1743    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1744    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1745    $attr = array('size'=>'50', 'class'=>'edit');
1746    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1747    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1748    $form->addElement(form_makeTag('br'));
1749    if ($auth->canDo('modPass')) {
1750        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1751        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1752    }
1753    if ($conf['profileconfirm']) {
1754        $form->addElement(form_makeTag('br'));
1755        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1756    }
1757    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1758    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1759
1760    $form->endFieldset();
1761    html_form('updateprofile', $form);
1762
1763    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1764        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1765        $form_profiledelete->startFieldset($lang['profdeleteuser']);
1766        $form_profiledelete->addHidden('do', 'profile_delete');
1767        $form_profiledelete->addHidden('delete', '1');
1768        $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1769        if ($conf['profileconfirm']) {
1770            $form_profiledelete->addElement(form_makeTag('br'));
1771            $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1772        }
1773        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1774        $form_profiledelete->endFieldset();
1775
1776        html_form('profiledelete', $form_profiledelete);
1777    }
1778
1779    print '</div>'.NL;
1780}
1781
1782/**
1783 * Preprocess edit form data
1784 *
1785 * @author   Andreas Gohr <andi@splitbrain.org>
1786 *
1787 * @triggers HTML_EDITFORM_OUTPUT
1788 */
1789function html_edit(){
1790    global $INPUT;
1791    global $ID;
1792    global $REV;
1793    global $DATE;
1794    global $PRE;
1795    global $SUF;
1796    global $INFO;
1797    global $SUM;
1798    global $lang;
1799    global $conf;
1800    global $TEXT;
1801
1802    if ($INPUT->has('changecheck')) {
1803        $check = $INPUT->str('changecheck');
1804    } elseif(!$INFO['exists']){
1805        // $TEXT has been loaded from page template
1806        $check = md5('');
1807    } else {
1808        $check = md5($TEXT);
1809    }
1810    $mod = md5($TEXT) !== $check;
1811
1812    $wr = $INFO['writable'] && !$INFO['locked'];
1813    $include = 'edit';
1814    if($wr){
1815        if ($REV) $include = 'editrev';
1816    }else{
1817        // check pseudo action 'source'
1818        if(!actionOK('source')){
1819            msg('Command disabled: source',-1);
1820            return;
1821        }
1822        $include = 'read';
1823    }
1824
1825    global $license;
1826
1827    $form = new Doku_Form(array('id' => 'dw__editform'));
1828    $form->addHidden('id', $ID);
1829    $form->addHidden('rev', $REV);
1830    $form->addHidden('date', $DATE);
1831    $form->addHidden('prefix', $PRE . '.');
1832    $form->addHidden('suffix', $SUF);
1833    $form->addHidden('changecheck', $check);
1834
1835    $data = array('form' => $form,
1836                  'wr'   => $wr,
1837                  'media_manager' => true,
1838                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1839                  'intro_locale' => $include);
1840
1841    if ($data['target'] !== 'section') {
1842        // Only emit event if page is writable, section edit data is valid and
1843        // edit target is not section.
1844        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1845    } else {
1846        html_edit_form($data);
1847    }
1848    if (isset($data['intro_locale'])) {
1849        echo p_locale_xhtml($data['intro_locale']);
1850    }
1851
1852    $form->addHidden('target', $data['target']);
1853    if ($INPUT->has('hid')) {
1854        $form->addHidden('hid', $INPUT->str('hid'));
1855    }
1856    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1857    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1858    $form->addElement(form_makeCloseTag('div'));
1859    if ($wr) {
1860        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1861        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1862        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1863        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1864        $form->addElement(form_makeCloseTag('div'));
1865        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1866        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1867        $elem = html_minoredit();
1868        if ($elem) $form->addElement($elem);
1869        $form->addElement(form_makeCloseTag('div'));
1870    }
1871    $form->addElement(form_makeCloseTag('div'));
1872    if($wr && $conf['license']){
1873        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1874        $out  = $lang['licenseok'];
1875        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1876        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1877        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1878        $form->addElement($out);
1879        $form->addElement(form_makeCloseTag('div'));
1880    }
1881
1882    if ($wr) {
1883        // sets changed to true when previewed
1884        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1885        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1886        echo '/*!]]>*/</script>' . NL;
1887    } ?>
1888    <div class="editBox" role="application">
1889
1890    <div class="toolbar group">
1891        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1892        <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']?>"
1893            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1894    </div>
1895    <?php
1896
1897    html_form('edit', $form);
1898    print '</div>'.NL;
1899}
1900
1901/**
1902 * Display the default edit form
1903 *
1904 * Is the default action for HTML_EDIT_FORMSELECTION.
1905 *
1906 * @param mixed[] $param
1907 */
1908function html_edit_form($param) {
1909    global $TEXT;
1910
1911    if ($param['target'] !== 'section') {
1912        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1913    }
1914
1915    $attr = array('tabindex'=>'1');
1916    if (!$param['wr']) $attr['readonly'] = 'readonly';
1917
1918    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1919}
1920
1921/**
1922 * Adds a checkbox for minor edits for logged in users
1923 *
1924 * @author Andreas Gohr <andi@splitbrain.org>
1925 *
1926 * @return array|bool
1927 */
1928function html_minoredit(){
1929    global $conf;
1930    global $lang;
1931    global $INPUT;
1932    // minor edits are for logged in users only
1933    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1934        return false;
1935    }
1936
1937    $p = array();
1938    $p['tabindex'] = 3;
1939    if($INPUT->bool('minor')) $p['checked']='checked';
1940    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1941}
1942
1943/**
1944 * prints some debug info
1945 *
1946 * @author Andreas Gohr <andi@splitbrain.org>
1947 */
1948function html_debug(){
1949    global $conf;
1950    global $lang;
1951    /** @var DokuWiki_Auth_Plugin $auth */
1952    global $auth;
1953    global $INFO;
1954
1955    //remove sensitive data
1956    $cnf = $conf;
1957    debug_guard($cnf);
1958    $nfo = $INFO;
1959    debug_guard($nfo);
1960    $ses = $_SESSION;
1961    debug_guard($ses);
1962
1963    print '<html><body>';
1964
1965    print '<p>When reporting bugs please send all the following ';
1966    print 'output as a mail to andi@splitbrain.org ';
1967    print 'The best way to do this is to save this page in your browser</p>';
1968
1969    print '<b>$INFO:</b><pre>';
1970    print_r($nfo);
1971    print '</pre>';
1972
1973    print '<b>$_SERVER:</b><pre>';
1974    print_r($_SERVER);
1975    print '</pre>';
1976
1977    print '<b>$conf:</b><pre>';
1978    print_r($cnf);
1979    print '</pre>';
1980
1981    print '<b>DOKU_BASE:</b><pre>';
1982    print DOKU_BASE;
1983    print '</pre>';
1984
1985    print '<b>abs DOKU_BASE:</b><pre>';
1986    print DOKU_URL;
1987    print '</pre>';
1988
1989    print '<b>rel DOKU_BASE:</b><pre>';
1990    print dirname($_SERVER['PHP_SELF']).'/';
1991    print '</pre>';
1992
1993    print '<b>PHP Version:</b><pre>';
1994    print phpversion();
1995    print '</pre>';
1996
1997    print '<b>locale:</b><pre>';
1998    print setlocale(LC_ALL,0);
1999    print '</pre>';
2000
2001    print '<b>encoding:</b><pre>';
2002    print $lang['encoding'];
2003    print '</pre>';
2004
2005    if($auth){
2006        print '<b>Auth backend capabilities:</b><pre>';
2007        foreach ($auth->getCapabilities() as $cando){
2008            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
2009        }
2010        print '</pre>';
2011    }
2012
2013    print '<b>$_SESSION:</b><pre>';
2014    print_r($ses);
2015    print '</pre>';
2016
2017    print '<b>Environment:</b><pre>';
2018    print_r($_ENV);
2019    print '</pre>';
2020
2021    print '<b>PHP settings:</b><pre>';
2022    $inis = ini_get_all();
2023    print_r($inis);
2024    print '</pre>';
2025
2026    if (function_exists('apache_get_version')) {
2027        $apache = array();
2028        $apache['version'] = apache_get_version();
2029
2030        if (function_exists('apache_get_modules')) {
2031            $apache['modules'] = apache_get_modules();
2032        }
2033        print '<b>Apache</b><pre>';
2034        print_r($apache);
2035        print '</pre>';
2036    }
2037
2038    print '</body></html>';
2039}
2040
2041/**
2042 * Form to request a new password for an existing account
2043 *
2044 * @author Benoit Chesneau <benoit@bchesneau.info>
2045 * @author Andreas Gohr <gohr@cosmocode.de>
2046 */
2047function html_resendpwd() {
2048    global $lang;
2049    global $conf;
2050    global $INPUT;
2051
2052    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2053
2054    if(!$conf['autopasswd'] && $token){
2055        print p_locale_xhtml('resetpwd');
2056        print '<div class="centeralign">'.NL;
2057        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2058        $form->startFieldset($lang['btn_resendpwd']);
2059        $form->addHidden('token', $token);
2060        $form->addHidden('do', 'resendpwd');
2061
2062        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2063        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2064
2065        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2066        $form->endFieldset();
2067        html_form('resendpwd', $form);
2068        print '</div>'.NL;
2069    }else{
2070        print p_locale_xhtml('resendpwd');
2071        print '<div class="centeralign">'.NL;
2072        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2073        $form->startFieldset($lang['resendpwd']);
2074        $form->addHidden('do', 'resendpwd');
2075        $form->addHidden('save', '1');
2076        $form->addElement(form_makeTag('br'));
2077        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2078        $form->addElement(form_makeTag('br'));
2079        $form->addElement(form_makeTag('br'));
2080        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2081        $form->endFieldset();
2082        html_form('resendpwd', $form);
2083        print '</div>'.NL;
2084    }
2085}
2086
2087/**
2088 * Return the TOC rendered to XHTML
2089 *
2090 * @author Andreas Gohr <andi@splitbrain.org>
2091 *
2092 * @param array $toc
2093 * @return string html
2094 */
2095function html_TOC($toc){
2096    if(!count($toc)) return '';
2097    global $lang;
2098    $out  = '<!-- TOC START -->'.DOKU_LF;
2099    $out .= '<div id="dw__toc">'.DOKU_LF;
2100    $out .= '<h3 class="toggle">';
2101    $out .= $lang['toc'];
2102    $out .= '</h3>'.DOKU_LF;
2103    $out .= '<div>'.DOKU_LF;
2104    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2105    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2106    $out .= '<!-- TOC END -->'.DOKU_LF;
2107    return $out;
2108}
2109
2110/**
2111 * Callback for html_buildlist
2112 *
2113 * @param array $item
2114 * @return string html
2115 */
2116function html_list_toc($item){
2117    if(isset($item['hid'])){
2118        $link = '#'.$item['hid'];
2119    }else{
2120        $link = $item['link'];
2121    }
2122
2123    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2124}
2125
2126/**
2127 * Helper function to build TOC items
2128 *
2129 * Returns an array ready to be added to a TOC array
2130 *
2131 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2132 * @param string $text  - what to display in the TOC
2133 * @param int    $level - nesting level
2134 * @param string $hash  - is prepended to the given $link, set blank if you want full links
2135 * @return array the toc item
2136 */
2137function html_mktocitem($link, $text, $level, $hash='#'){
2138    return  array( 'link'  => $hash.$link,
2139            'title' => $text,
2140            'type'  => 'ul',
2141            'level' => $level);
2142}
2143
2144/**
2145 * Output a Doku_Form object.
2146 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2147 *
2148 * @author Tom N Harris <tnharris@whoopdedo.org>
2149 *
2150 * @param string     $name The name of the form
2151 * @param Doku_Form  $form The form
2152 */
2153function html_form($name, &$form) {
2154    // Safety check in case the caller forgets.
2155    $form->endFieldset();
2156    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2157}
2158
2159/**
2160 * Form print function.
2161 * Just calls printForm() on the data object.
2162 *
2163 * @param Doku_Form $data The form
2164 */
2165function html_form_output($data) {
2166    $data->printForm();
2167}
2168
2169/**
2170 * Embed a flash object in HTML
2171 *
2172 * This will create the needed HTML to embed a flash movie in a cross browser
2173 * compatble way using valid XHTML
2174 *
2175 * The parameters $params, $flashvars and $atts need to be associative arrays.
2176 * No escaping needs to be done for them. The alternative content *has* to be
2177 * escaped because it is used as is. If no alternative content is given
2178 * $lang['noflash'] is used.
2179 *
2180 * @author Andreas Gohr <andi@splitbrain.org>
2181 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
2182 *
2183 * @param string $swf      - the SWF movie to embed
2184 * @param int $width       - width of the flash movie in pixels
2185 * @param int $height      - height of the flash movie in pixels
2186 * @param array $params    - additional parameters (<param>)
2187 * @param array $flashvars - parameters to be passed in the flashvar parameter
2188 * @param array $atts      - additional attributes for the <object> tag
2189 * @param string $alt      - alternative content (is NOT automatically escaped!)
2190 * @return string         - the XHTML markup
2191 */
2192function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
2193    global $lang;
2194
2195    $out = '';
2196
2197    // prepare the object attributes
2198    if(is_null($atts)) $atts = array();
2199    $atts['width']  = (int) $width;
2200    $atts['height'] = (int) $height;
2201    if(!$atts['width'])  $atts['width']  = 425;
2202    if(!$atts['height']) $atts['height'] = 350;
2203
2204    // add object attributes for standard compliant browsers
2205    $std = $atts;
2206    $std['type'] = 'application/x-shockwave-flash';
2207    $std['data'] = $swf;
2208
2209    // add object attributes for IE
2210    $ie  = $atts;
2211    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
2212
2213    // open object (with conditional comments)
2214    $out .= '<!--[if !IE]> -->'.NL;
2215    $out .= '<object '.buildAttributes($std).'>'.NL;
2216    $out .= '<!-- <![endif]-->'.NL;
2217    $out .= '<!--[if IE]>'.NL;
2218    $out .= '<object '.buildAttributes($ie).'>'.NL;
2219    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
2220    $out .= '<!--><!-- -->'.NL;
2221
2222    // print params
2223    if(is_array($params)) foreach($params as $key => $val){
2224        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
2225    }
2226
2227    // add flashvars
2228    if(is_array($flashvars)){
2229        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
2230    }
2231
2232    // alternative content
2233    if($alt){
2234        $out .= $alt.NL;
2235    }else{
2236        $out .= $lang['noflash'].NL;
2237    }
2238
2239    // finish
2240    $out .= '</object>'.NL;
2241    $out .= '<!-- <![endif]-->'.NL;
2242
2243    return $out;
2244}
2245
2246/**
2247 * Prints HTML code for the given tab structure
2248 *
2249 * @param array  $tabs        tab structure
2250 * @param string $current_tab the current tab id
2251 */
2252function html_tabs($tabs, $current_tab = null) {
2253    echo '<ul class="tabs">'.NL;
2254
2255    foreach($tabs as $id => $tab) {
2256        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
2257    }
2258
2259    echo '</ul>'.NL;
2260}
2261
2262/**
2263 * Prints a single tab
2264 *
2265 * @author Kate Arzamastseva <pshns@ukr.net>
2266 * @author Adrian Lang <mail@adrianlang.de>
2267 *
2268 * @param string $href - tab href
2269 * @param string $caption - tab caption
2270 * @param boolean $selected - is tab selected
2271 */
2272
2273function html_tab($href, $caption, $selected=false) {
2274    $tab = '<li>';
2275    if ($selected) {
2276        $tab .= '<strong>';
2277    } else {
2278        $tab .= '<a href="' . hsc($href) . '">';
2279    }
2280    $tab .= hsc($caption)
2281         .  '</' . ($selected ? 'strong' : 'a') . '>'
2282         .  '</li>'.NL;
2283    echo $tab;
2284}
2285
2286/**
2287 * Display size change
2288 *
2289 * @param int $sizechange - size of change in Bytes
2290 * @param Doku_Form $form - form to add elements to
2291 */
2292
2293function html_sizechange($sizechange, Doku_Form $form) {
2294    if(isset($sizechange)) {
2295        $class = 'sizechange';
2296        $value = filesize_h(abs($sizechange));
2297        if($sizechange > 0) {
2298            $class .= ' positive';
2299            $value = '+' . $value;
2300        } elseif($sizechange < 0) {
2301            $class .= ' negative';
2302            $value = '-' . $value;
2303        } else {
2304            $value = '±' . $value;
2305        }
2306        $form->addElement(form_makeOpenTag('span', array('class' => $class)));
2307        $form->addElement($value);
2308        $form->addElement(form_makeCloseTag('span'));
2309    }
2310}
2311