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