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