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