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