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