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