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