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