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