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