xref: /dokuwiki/inc/html.php (revision ed7ecb791be76223682b576af6242134cdca9496)
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')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10if(!defined('NL')) define('NL',"\n");
11require_once(DOKU_INC.'inc/parserutils.php');
12
13/**
14 * Convenience function to quickly build a wikilink
15 *
16 * @author Andreas Gohr <andi@splitbrain.org>
17 */
18function html_wikilink($id,$name=NULL,$search=''){
19  static $xhtml_renderer = NULL;
20  if(is_null($xhtml_renderer)){
21    require_once(DOKU_INC.'inc/parser/xhtml.php');
22    $xhtml_renderer = new Doku_Renderer_xhtml();
23  }
24
25  return $xhtml_renderer->internallink($id,$name,$search,true);
26}
27
28/**
29 * Helps building long attribute lists
30 *
31 * @author Andreas Gohr <andi@splitbrain.org>
32 */
33function html_attbuild($attributes){
34  $ret = '';
35  foreach ( $attributes as $key => $value ) {
36    $ret .= $key.'="'.formtext($value).'" ';
37  }
38  return trim($ret);
39}
40
41/**
42 * The loginform
43 *
44 * @author   Andreas Gohr <andi@splitbrain.org>
45 * @triggers HTML_LOGINFORM_INJECTION
46 */
47function html_login(){
48  global $lang;
49  global $conf;
50  global $ID;
51  global $auth;
52
53  print p_locale_xhtml('login');
54  ?>
55    <div class="centeralign">
56    <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"
57          method="post" id="dw__login">
58      <fieldset>
59        <legend><?php echo $lang['btn_login']?></legend>
60        <input type="hidden" name="id" value="<?php echo $ID?>" />
61        <input type="hidden" name="do" value="login" />
62        <label class="block">
63          <span><?php echo $lang['user']?></span>
64          <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>"
65                 class="edit" id="focus__this" />
66        </label><br />
67        <label class="block">
68          <span><?php echo $lang['pass']?></span>
69          <input type="password" name="p" class="edit" />
70        </label><br />
71
72        <?php //bad and dirty event insert hook
73        $evdata = array();
74        trigger_event('HTML_LOGINFORM_INJECTION', $evdata);
75        ?>
76
77        <label for="remember__me" class="simple">
78          <input type="checkbox" name="r" id="remember__me" value="1" />
79          <span><?php echo $lang['remember']?></span>
80        </label>
81        <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
82      </fieldset>
83    </form>
84  <?php
85    if($auth->canDo('addUser') && actionOK('register')){
86      print '<p>';
87      print $lang['reghere'];
88      print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
89      print '</p>';
90    }
91
92    if ($auth->canDo('modPass') && actionOK('resendpwd')) {
93      print '<p>';
94      print $lang['pwdforget'];
95      print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
96      print '</p>';
97    }
98  ?>
99    </div>
100  <?php
101/*
102 FIXME provide new hook
103  if(@file_exists('includes/login.txt')){
104    print io_cacheParse('includes/login.txt');
105  }
106*/
107}
108
109/**
110 * prints a section editing button
111 * used as a callback in html_secedit
112 *
113 * @author Andreas Gohr <andi@splitbrain.org>
114 */
115function html_secedit_button($matches){
116  global $ID;
117  global $INFO;
118
119  $section = $matches[2];
120  $name = $matches[1];
121
122  $secedit  = '';
123  $secedit .= '<div class="secedit">';
124  $secedit .= html_btn('secedit',$ID,'',
125                        array('do'      => 'edit',
126                              'lines'   => "$section",
127                              'rev' => $INFO['lastmod']),
128                              'post', $name);
129  $secedit .= '</div>';
130  return $secedit;
131}
132
133/**
134 * inserts section edit buttons if wanted or removes the markers
135 *
136 * @author Andreas Gohr <andi@splitbrain.org>
137 */
138function html_secedit($text,$show=true){
139  global $INFO;
140
141  if($INFO['writable'] && $show && !$INFO['rev']){
142    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
143                         'html_secedit_button', $text);
144  }else{
145    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
146  }
147
148  return $text;
149}
150
151/**
152 * Just the back to top button (in its own form)
153 *
154 * @author Andreas Gohr <andi@splitbrain.org>
155 */
156function html_topbtn(){
157  global $lang;
158
159  $ret  = '';
160  $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>';
161
162  return $ret;
163}
164
165/**
166 * Displays a button (using its own form)
167 * If tooltip exists, the access key tooltip is replaced.
168 *
169 * @author Andreas Gohr <andi@splitbrain.org>
170 */
171function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
172  global $conf;
173  global $lang;
174
175  $label = $lang['btn_'.$name];
176
177  $ret = '';
178  $tip = '';
179
180  //filter id (without urlencoding)
181  $id = idfilter($id,false);
182
183  //make nice URLs even for buttons
184  if($conf['userewrite'] == 2){
185    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
186  }elseif($conf['userewrite']){
187    $script = DOKU_BASE.$id;
188  }else{
189    $script = DOKU_BASE.DOKU_SCRIPT;
190    $params['id'] = $id;
191  }
192
193  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">';
194
195  if(is_array($params)){
196    reset($params);
197    while (list($key, $val) = each($params)) {
198      $ret .= '<input type="hidden" name="'.$key.'" ';
199      $ret .= 'value="'.htmlspecialchars($val).'" />';
200    }
201  }
202
203  if ($tooltip!='') {
204      $tip = htmlspecialchars($tooltip);
205  }else{
206      $tip = htmlspecialchars($label);
207  }
208
209  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
210  if($akey){
211    $tip .= ' [ALT+'.strtoupper($akey).']';
212    $ret .= 'accesskey="'.$akey.'" ';
213  }
214  $ret .= 'title="'.$tip.'" ';
215  $ret .= '/>';
216  $ret .= '</div></form>';
217
218  return $ret;
219}
220
221/**
222 * show a wiki page
223 *
224 * @author Andreas Gohr <andi@splitbrain.org>
225 */
226function html_show($txt=''){
227  global $ID;
228  global $REV;
229  global $HIGH;
230  //disable section editing for old revisions or in preview
231  if($txt || $REV){
232    $secedit = false;
233  }else{
234    $secedit = true;
235  }
236
237  if ($txt){
238    //PreviewHeader
239    print '<br id="scroll__here" />';
240    print p_locale_xhtml('preview');
241    print '<div class="preview">';
242    print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
243    print '<div class="clearer"></div>';
244    print '</div>';
245
246  }else{
247    if ($REV) print p_locale_xhtml('showrev');
248    $html = p_wiki_xhtml($ID,$REV,true);
249    $html = html_secedit($html,$secedit);
250    print html_hilight($html,$HIGH);
251  }
252}
253
254/**
255 * ask the user about how to handle an exisiting draft
256 *
257 * @author Andreas Gohr <andi@splitbrain.org>
258 */
259function html_draft(){
260  global $INFO;
261  global $ID;
262  global $lang;
263  global $conf;
264  $draft = unserialize(io_readFile($INFO['draft'],false));
265  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
266
267  echo p_locale_xhtml('draft');
268  ?>
269  <form id="dw__editform" method="post" action="<?php echo script()?>"
270   accept-charset="<?php echo $lang['encoding']?>"><div class="no">
271    <input type="hidden" name="id"   value="<?php echo $ID?>" />
272    <input type="hidden" name="date" value="<?php echo $draft['date']?>" /></div>
273    <textarea name="wikitext" id="wiki__text" readonly="readonly" cols="80" rows="10" class="edit"><?php echo "\n".formText($text)?></textarea>
274
275    <div id="draft__status"><?php echo $lang['draftdate'].' '.date($conf['dformat'],filemtime($INFO['draft']))?></div>
276
277    <input class="button" type="submit" name="do[recover]" value="<?php echo $lang['btn_recover']?>" tabindex="1" />
278    <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_draftdel']?>" tabindex="2" />
279    <input class="button" type="submit" name="do[show]" value="<?php echo $lang['btn_cancel']?>" tabindex="3" />
280  </form>
281  <?php
282}
283
284/**
285 * Highlights searchqueries in HTML code
286 *
287 * @author Andreas Gohr <andi@splitbrain.org>
288 * @author Harry Fuecks <hfuecks@gmail.com>
289 */
290function html_hilight($html,$query){
291  //split at common delimiters
292  $queries = preg_split ('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$query,-1,PREG_SPLIT_NO_EMPTY);
293  foreach ($queries as $q){
294     $q = preg_quote($q,'/');
295     $html = preg_replace_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html);
296  }
297  return $html;
298}
299
300/**
301 * Callback used by html_hilight()
302 *
303 * @author Harry Fuecks <hfuecks@gmail.com>
304 */
305function html_hilight_callback($m) {
306  $hlight = unslash($m[0]);
307  if ( !isset($m[2])) {
308    $hlight = '<strong class="search_hit">'.$hlight.'</strong>';
309  }
310  return $hlight;
311}
312
313/**
314 * Run a search and display the result
315 *
316 * @author Andreas Gohr <andi@splitbrain.org>
317 */
318function html_search(){
319  require_once(DOKU_INC.'inc/search.php');
320  require_once(DOKU_INC.'inc/fulltext.php');
321  global $conf;
322  global $QUERY;
323  global $ID;
324  global $lang;
325
326  print p_locale_xhtml('searchpage');
327  flush();
328
329  //check if search is restricted to namespace
330  if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) {
331      $id = cleanID($match[1]);
332      if(empty($id)) {
333        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
334        flush();
335        return;
336      }
337  } else {
338      $id = cleanID($QUERY);
339  }
340
341  //show progressbar
342  print '<div class="centeralign" id="dw__loading">'.NL;
343  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
344  print 'showLoadBar();'.NL;
345  print '//--><!]]></script>'.NL;
346  print '<br /></div>'.NL;
347  flush();
348
349  //do quick pagesearch
350  $data = array();
351
352  $data = ft_pageLookup($id);
353  if(count($data)){
354    sort($data);
355    print '<div class="search_quickresult">';
356    print '<h3>'.$lang['quickhits'].':</h3>';
357    print '<ul class="search_quickhits">';
358    foreach($data as $id){
359      print '<li> ';
360      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id);
361      print '</li> ';
362    }
363    print '</ul> ';
364    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
365    print '<div class="clearer">&nbsp;</div>';
366    print '</div>';
367  }
368  flush();
369
370  //do fulltext search
371  $data = ft_pageSearch($QUERY,$poswords);
372  if(count($data)){
373    $num = 1;
374    foreach($data as $id => $cnt){
375      print '<div class="search_result">';
376      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
377      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
378      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
379        print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
380      }
381      print '</div>';
382      flush();
383      $num++;
384    }
385  }else{
386    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
387  }
388
389  //hide progressbar
390  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
391  print 'hideLoadBar("dw__loading");'.NL;
392  print '//--><!]]></script>'.NL;
393  flush();
394}
395
396/**
397 * Display error on locked pages
398 *
399 * @author Andreas Gohr <andi@splitbrain.org>
400 */
401function html_locked(){
402  global $ID;
403  global $conf;
404  global $lang;
405  global $INFO;
406
407  $locktime = filemtime(wikiLockFN($ID));
408  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
409  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
410
411  print p_locale_xhtml('locked');
412  print '<ul>';
413  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
414  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
415  print '</ul>';
416}
417
418/**
419 * list old revisions
420 *
421 * @author Andreas Gohr <andi@splitbrain.org>
422 * @author Ben Coburn <btcoburn@silicodon.net>
423 */
424function html_revisions($first=0){
425  global $ID;
426  global $INFO;
427  global $conf;
428  global $lang;
429  /* we need to get one additionally log entry to be able to
430   * decide if this is the last page or is there another one.
431   * see html_recent()
432   */
433  $revisions = getRevisions($ID, $first, $conf['recent']+1);
434  if(count($revisions)==0 && $first!=0){
435    $first=0;
436    $revisions = getRevisions($ID, $first, $conf['recent']+1);;
437  }
438  $hasNext = false;
439  if (count($revisions)>$conf['recent']) {
440    $hasNext = true;
441    array_pop($revisions); // remove extra log entry
442  }
443
444  $date = @date($conf['dformat'],$INFO['lastmod']);
445
446  print p_locale_xhtml('revisions');
447  print '<ul>';
448  if($INFO['exists'] && $first==0){
449    print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
450    print '<div class="li">';
451
452    print $date;
453
454    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
455
456    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
457
458    print ' &ndash; ';
459    print $INFO['sum'];
460    print ' <span class="user">';
461    print (empty($INFO['editor']))?('('.$lang['external_edit'].')'):$INFO['editor'];
462    print '</span> ';
463
464    print '('.$lang['current'].')';
465    print '</div>';
466    print '</li>';
467  }
468
469  foreach($revisions as $rev){
470    $date = date($conf['dformat'],$rev);
471    $info = getRevisionInfo($ID,$rev,true);
472
473    print ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
474    print '<div class="li">';
475    print $date;
476
477    if(@file_exists(wikiFN($ID,$rev))){
478      print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
479      $p = array();
480      $p['src']    = DOKU_BASE.'lib/images/diff.png';
481      $p['width']  = 15;
482      $p['height'] = 11;
483      $p['title']  = $lang['diff'];
484      $p['alt']    = $lang['diff'];
485      $att = buildAttributes($p);
486      print "<img $att />";
487      print '</a> ';
488
489      print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a>';
490    }else{
491      print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" /> ';
492      print $ID;
493    }
494
495    print ' &ndash; ';
496    print htmlspecialchars($info['sum']);
497    print ' <span class="user">';
498    if($info['user']){
499      print $info['user'];
500    }else{
501      print $info['ip'];
502    }
503    print '</span>';
504
505    print '</div>';
506    print '</li>';
507  }
508  print '</ul>';
509
510  print '<div class="pagenav">';
511  $last = $first + $conf['recent'];
512  if ($first > 0) {
513    $first -= $conf['recent'];
514    if ($first < 0) $first = 0;
515    print '<div class="pagenav-prev">';
516    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
517    print '</div>';
518  }
519  if ($hasNext) {
520    print '<div class="pagenav-next">';
521    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
522    print '</div>';
523  }
524  print '</div>';
525
526}
527
528/**
529 * display recent changes
530 *
531 * @author Andreas Gohr <andi@splitbrain.org>
532 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
533 * @author Ben Coburn <btcoburn@silicodon.net>
534 */
535function html_recent($first=0){
536  global $conf;
537  global $lang;
538  global $ID;
539  /* we need to get one additionally log entry to be able to
540   * decide if this is the last page or is there another one.
541   * This is the cheapest solution to get this information.
542   */
543  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
544  if(count($recents) == 0 && $first != 0){
545    $first=0;
546    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
547  }
548  $hasNext = false;
549  if (count($recents)>$conf['recent']) {
550    $hasNext = true;
551    array_pop($recents); // remove extra log entry
552  }
553
554  print p_locale_xhtml('recent');
555  print '<ul>';
556
557  foreach($recents as $recent){
558    $date = date($conf['dformat'],$recent['date']);
559    print ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
560    print '<div class="li">';
561
562    print $date.' ';
563
564    print '<a href="'.wl($recent['id'],"do=diff").'">';
565    $p = array();
566    $p['src']    = DOKU_BASE.'lib/images/diff.png';
567    $p['width']  = 15;
568    $p['height'] = 11;
569    $p['title']  = $lang['diff'];
570    $p['alt']    = $lang['diff'];
571    $att = buildAttributes($p);
572    print "<img $att />";
573    print '</a> ';
574
575    print '<a href="'.wl($recent['id'],"do=revisions").'">';
576    $p = array();
577    $p['src']    = DOKU_BASE.'lib/images/history.png';
578    $p['width']  = 12;
579    $p['height'] = 14;
580    $p['title']  = $lang['btn_revs'];
581    $p['alt']    = $lang['btn_revs'];
582    $att = buildAttributes($p);
583    print "<img $att />";
584    print '</a> ';
585
586    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
587    print ' &ndash; '.htmlspecialchars($recent['sum']);
588
589    print ' <span class="user">';
590    if($recent['user']){
591      print $recent['user'];
592    }else{
593      print $recent['ip'];
594    }
595    print '</span>';
596
597    print '</div>';
598    print '</li>';
599  }
600  print '</ul>';
601
602  print '<div class="pagenav">';
603  $last = $first + $conf['recent'];
604  if ($first > 0) {
605    $first -= $conf['recent'];
606    if ($first < 0) $first = 0;
607    print '<div class="pagenav-prev">';
608    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
609    print '</div>';
610  }
611  if ($hasNext) {
612    print '<div class="pagenav-next">';
613    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
614    print '</div>';
615  }
616  print '</div>';
617}
618
619/**
620 * Display page index
621 *
622 * @author Andreas Gohr <andi@splitbrain.org>
623 */
624function html_index($ns){
625  require_once(DOKU_INC.'inc/search.php');
626  global $conf;
627  global $ID;
628  $dir = $conf['datadir'];
629  $ns  = cleanID($ns);
630  #fixme use appropriate function
631  if(empty($ns)){
632    $ns = dirname(str_replace(':','/',$ID));
633    if($ns == '.') $ns ='';
634  }
635  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
636
637  print p_locale_xhtml('index');
638
639  $data = array();
640  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
641  print html_buildlist($data,'idx','html_list_index','html_li_index');
642}
643
644/**
645 * Index item formatter
646 *
647 * User function for html_buildlist()
648 *
649 * @author Andreas Gohr <andi@splitbrain.org>
650 */
651function html_list_index($item){
652  global $ID;
653  $ret = '';
654  $base = ':'.$item['id'];
655  $base = substr($base,strrpos($base,':')+1);
656  if($item['type']=='d'){
657    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir"><strong>';
658    $ret .= $base;
659    $ret .= '</strong></a>';
660  }else{
661    $ret .= html_wikilink(':'.$item['id']);
662  }
663  return $ret;
664}
665
666/**
667 * Index List item
668 *
669 * This user function is used in html_build_lidt to build the
670 * <li> tags for namespaces when displaying the page index
671 * it gives different classes to opened or closed "folders"
672 *
673 * @author Andreas Gohr <andi@splitbrain.org>
674 */
675function html_li_index($item){
676  if($item['type'] == "f"){
677    return '<li class="level'.$item['level'].'">';
678  }elseif($item['open']){
679    return '<li class="open">';
680  }else{
681    return '<li class="closed">';
682  }
683}
684
685/**
686 * Default List item
687 *
688 * @author Andreas Gohr <andi@splitbrain.org>
689 */
690function html_li_default($item){
691  return '<li class="level'.$item['level'].'">';
692}
693
694/**
695 * Build an unordered list
696 *
697 * Build an unordered list from the given $data array
698 * Each item in the array has to have a 'level' property
699 * the item itself gets printed by the given $func user
700 * function. The second and optional function is used to
701 * print the <li> tag. Both user function need to accept
702 * a single item.
703 *
704 * Both user functions can be given as array to point to
705 * a member of an object.
706 *
707 * @author Andreas Gohr <andi@splitbrain.org>
708 */
709function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
710  $level = 0;
711  $opens = 0;
712  $ret   = '';
713
714  foreach ($data as $item){
715
716    if( $item['level'] > $level ){
717      //open new list
718      for($i=0; $i<($item['level'] - $level); $i++){
719        if ($i) $ret .= "<li class=\"clear\">\n";
720        $ret .= "\n<ul class=\"$class\">\n";
721      }
722    }elseif( $item['level'] < $level ){
723      //close last item
724      $ret .= "</li>\n";
725      for ($i=0; $i<($level - $item['level']); $i++){
726        //close higher lists
727        $ret .= "</ul>\n</li>\n";
728      }
729    }else{
730      //close last item
731      $ret .= "</li>\n";
732    }
733
734    //remember current level
735    $level = $item['level'];
736
737    //print item
738    $ret .= call_user_func($lifunc,$item);
739    $ret .= '<div class="li">';
740
741    $ret .= call_user_func($func,$item);
742    $ret .= '</div>';
743  }
744
745  //close remaining items and lists
746  for ($i=0; $i < $level; $i++){
747    $ret .= "</li></ul>\n";
748  }
749
750  return $ret;
751}
752
753/**
754 * display backlinks
755 *
756 * @author Andreas Gohr <andi@splitbrain.org>
757 */
758function html_backlinks(){
759  require_once(DOKU_INC.'inc/fulltext.php');
760  global $ID;
761  global $conf;
762
763  print p_locale_xhtml('backlinks');
764
765  $data = ft_backlinks($ID);
766
767  print '<ul class="idx">';
768  foreach($data as $blink){
769    print '<li><div class="li">';
770    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
771    print '</div></li>';
772  }
773  print '</ul>';
774}
775
776/**
777 * show diff
778 *
779 * @author Andreas Gohr <andi@splitbrain.org>
780 */
781function html_diff($text='',$intro=true){
782  require_once(DOKU_INC.'inc/DifferenceEngine.php');
783  global $ID;
784  global $REV;
785  global $lang;
786  global $conf;
787
788  if($text){
789    $df  = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,''))),
790                    explode("\n",htmlspecialchars(cleanText($text))));
791    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
792              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
793              $lang['current'];
794    $right = $lang['yours'];
795  }else{
796    //check if current revision exist
797    if(!@file_exists(wikiFN($ID))){
798      $revs = getRevisions($ID, 0, 2);
799      $rc = $revs[1];
800    }
801    if($REV){
802      $r = $REV;
803    }else{
804      if(empty($revs)){
805        //use last revision if none given
806        $revs = getRevisions($ID, 0, 1);
807      }
808      $r = $revs[0];
809    }
810
811    if($r){
812      $df  = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,$r))),
813                      explode("\n",htmlspecialchars(rawWiki($ID,''))));
814      $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
815                $ID.' '.date($conf['dformat'],(isset($rc) ? $rc : $r)).'</a>';
816    }else{
817      $df  = new Diff(array(''),
818                      explode("\n",htmlspecialchars(rawWiki($ID,''))));
819      $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
820                $ID.'</a>';
821    }
822    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
823              $ID.' '.date($conf['dformat'],(isset($rc) ? $r : @filemtime(wikiFN($ID)))).'</a> '.
824              $lang['current'];
825  }
826  $tdf = new TableDiffFormatter();
827  if($intro) print p_locale_xhtml('diff');
828  ?>
829    <table class="diff">
830      <tr>
831        <th colspan="2">
832          <?php echo $left?>
833        </th>
834        <th colspan="2">
835          <?php echo $right?>
836        </th>
837      </tr>
838      <?php echo $tdf->format($df)?>
839    </table>
840  <?php
841}
842
843/**
844 * show warning on conflict detection
845 *
846 * @author Andreas Gohr <andi@splitbrain.org>
847 */
848function html_conflict($text,$summary){
849  global $ID;
850  global $lang;
851
852  print p_locale_xhtml('conflict');
853  ?>
854  <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
855  <div class="centeralign">
856    <input type="hidden" name="id" value="<?php echo $ID?>" />
857    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
858    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
859
860    <input class="button" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" />
861    <input class="button" type="submit" name="do[cancel]" value="<?php echo $lang['btn_cancel']?>" />
862  </div>
863  </form>
864  <br /><br /><br /><br />
865  <?php
866}
867
868/**
869 * Prints the global message array
870 *
871 * @author Andreas Gohr <andi@splitbrain.org>
872 */
873function html_msgarea(){
874  global $MSG;
875
876  if(!isset($MSG)) return;
877
878  foreach($MSG as $msg){
879    print '<div class="'.$msg['lvl'].'">';
880    print $msg['msg'];
881    print '</div>';
882  }
883}
884
885/**
886 * Prints the registration form
887 *
888 * @author Andreas Gohr <andi@splitbrain.org>
889 * @triggers HTML_REGISTERFORM_INJECTION
890 */
891function html_register(){
892  global $lang;
893  global $conf;
894  global $ID;
895
896  print p_locale_xhtml('register');
897?>
898  <div class="centeralign">
899  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
900  <fieldset>
901    <input type="hidden" name="do" value="register" />
902    <input type="hidden" name="save" value="1" />
903
904    <legend><?php echo $lang['register']?></legend>
905    <label class="block">
906      <?php echo $lang['user']?>
907      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
908    </label><br />
909
910    <?php
911      if (!$conf['autopasswd']) {
912    ?>
913      <label class="block">
914        <?php echo $lang['pass']?>
915        <input type="password" name="pass" class="edit" size="50" />
916      </label><br />
917      <label class="block">
918        <?php echo $lang['passchk']?>
919        <input type="password" name="passchk" class="edit" size="50" />
920      </label><br />
921    <?php
922      }
923    ?>
924
925    <label class="block">
926      <?php echo $lang['fullname']?>
927      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
928    </label><br />
929    <label class="block">
930      <?php echo $lang['email']?>
931      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
932    </label><br />
933    <?php //bad and dirty event insert hook
934    $evdata = array();
935    trigger_event('HTML_REGISTERFORM_INJECTION', $evdata);
936    ?>
937    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
938  </fieldset>
939  </form>
940  </div>
941<?php
942}
943
944/**
945 * Print the update profile form
946 *
947 * @author Christopher Smith <chris@jalakai.co.uk>
948 * @author Andreas Gohr <andi@splitbrain.org>
949 */
950function html_updateprofile(){
951  global $lang;
952  global $conf;
953  global $ID;
954  global $INFO;
955  global $auth;
956
957  print p_locale_xhtml('updateprofile');
958
959  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
960  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
961?>
962  <div class="centeralign">
963  <form id="dw__register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
964  <fieldset style="width: 80%;">
965    <input type="hidden" name="do" value="profile" />
966    <input type="hidden" name="save" value="1" />
967
968    <legend><?php echo $lang['profile']?></legend>
969    <label class="block">
970      <?php echo $lang['user']?>
971      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
972    </label><br />
973    <label class="block">
974      <?php echo $lang['fullname']?>
975      <input type="text" name="fullname" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
976    </label><br />
977    <label class="block">
978      <?php echo $lang['email']?>
979      <input type="text" name="email" <?php if(!$auth->canDo('modName')) echo 'disabled="disabled"'?> class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
980    </label><br /><br />
981
982    <?php if($auth->canDo('modPass')) { ?>
983    <label class="block">
984      <?php echo $lang['newpass']?>
985      <input type="password" name="newpass" class="edit" size="50" />
986    </label><br />
987    <label class="block">
988      <?php echo $lang['passchk']?>
989      <input type="password" name="passchk" class="edit" size="50" />
990    </label><br />
991    <?php } ?>
992
993    <?php if ($conf['profileconfirm']) { ?>
994      <br />
995      <label class="block">
996      <?php echo $lang['oldpass']?>
997      <input type="password" name="oldpass" class="edit" size="50" />
998    </label><br />
999    <?php } ?>
1000    <?php //bad and dirty event insert hook
1001    $evdata = array();
1002    trigger_event('HTML_PROFILEFORM_INJECTION', $evdata);
1003    ?>
1004    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
1005    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
1006  </fieldset>
1007  </form>
1008  </div>
1009<?php
1010}
1011
1012/**
1013 * This displays the edit form (lots of logic included)
1014 *
1015 * @fixme    this is a huge lump of code and should be modularized
1016 * @triggers HTML_PAGE_FROMTEMPLATE
1017 * @triggers HTML_EDITFORM_INJECTION
1018 * @author   Andreas Gohr <andi@splitbrain.org>
1019 */
1020function html_edit($text=null,$include='edit'){ //FIXME: include needed?
1021  global $ID;
1022  global $REV;
1023  global $DATE;
1024  global $RANGE;
1025  global $PRE;
1026  global $SUF;
1027  global $INFO;
1028  global $SUM;
1029  global $lang;
1030  global $conf;
1031
1032  //set summary default
1033  if(!$SUM){
1034    if($REV){
1035      $SUM = $lang['restored'];
1036    }elseif(!$INFO['exists']){
1037      $SUM = $lang['created'];
1038    }
1039  }
1040
1041  //no text? Load it!
1042  if(!isset($text)){
1043    $pr = false; //no preview mode
1044    if($INFO['exists']){
1045      if($RANGE){
1046        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1047      }else{
1048        $text = rawWiki($ID,$REV);
1049      }
1050    }else{
1051      //try to load a pagetemplate
1052      $data = array($ID);
1053      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
1054    }
1055  }else{
1056    $pr = true; //preview mode
1057  }
1058
1059  $wr = $INFO['writable'];
1060  if($wr){
1061    if ($REV) print p_locale_xhtml('editrev');
1062    print p_locale_xhtml($include);
1063    $ro=false;
1064  }else{
1065    // check pseudo action 'source'
1066    if(!actionOK('source')){
1067      msg('Command disabled: source',-1);
1068      return;
1069    }
1070    print p_locale_xhtml('read');
1071    $ro='readonly="readonly"';
1072  }
1073  if(!$DATE) $DATE = $INFO['lastmod'];
1074
1075
1076?>
1077  <div style="width:99%;">
1078
1079   <div class="toolbar">
1080      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.date($conf['dformat']);?></div>
1081      <div id="tool__bar"><?php if(!$ro){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1082      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1083
1084      <?php if($wr){?>
1085      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
1086        <?php /* sets changed to true when previewed */?>
1087        textChanged = <?php ($pr) ? print 'true' : print 'false' ?>;
1088      //--><!]]></script>
1089      <span id="spell__action"></span>
1090      <div id="spell__suggest"></div>
1091      <?php } ?>
1092   </div>
1093   <div id="spell__result"></div>
1094
1095
1096   <form id="dw__editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>"><div class="no">
1097      <input type="hidden" name="id"   value="<?php echo $ID?>" />
1098      <input type="hidden" name="rev"  value="<?php echo $REV?>" />
1099      <input type="hidden" name="date" value="<?php echo $DATE?>" />
1100      <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
1101      <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
1102    </div>
1103
1104    <textarea name="wikitext" id="wiki__text" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
1105
1106    <?php //bad and dirty event insert hook
1107    $evdata = array('writable' => $wr);
1108    trigger_event('HTML_EDITFORM_INJECTION', $evdata);
1109    ?>
1110
1111    <div id="wiki__editbar">
1112      <div id="size__ctl"></div>
1113      <?php if($wr){?>
1114         <div class="editButtons">
1115            <input class="button" id="edbtn__save" type="submit" name="do[save]" value="<?php echo $lang['btn_save']?>" accesskey="s" title="<?php echo $lang['btn_save']?> [ALT+S]" tabindex="4" />
1116            <input class="button" id="edbtn__preview" type="submit" name="do[preview]" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="<?php echo $lang['btn_preview']?> [ALT+P]" tabindex="5" />
1117            <input class="button" type="submit" name="do[draftdel]" value="<?php echo $lang['btn_cancel']?>" tabindex="6" />
1118         </div>
1119      <?php } ?>
1120      <?php if($wr){ ?>
1121        <div class="summary">
1122           <label for="edit__summary" class="nowrap"><?php echo $lang['summary']?>:</label>
1123           <input type="text" class="edit" name="summary" id="edit__summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1124           <?php html_minoredit()?>
1125        </div>
1126      <?php }?>
1127    </div>
1128  </form>
1129  </div>
1130<?php
1131}
1132
1133/**
1134 * Adds a checkbox for minor edits for logged in users
1135 *
1136 * @author Andrea Gohr <andi@splitbrain.org>
1137 */
1138function html_minoredit(){
1139  global $conf;
1140  global $lang;
1141  // minor edits are for logged in users only
1142  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1143    return;
1144  }
1145
1146  $p = array();
1147  $p['name']     = 'minor';
1148  $p['type']     = 'checkbox';
1149  $p['id']       = 'minoredit';
1150  $p['tabindex'] = 3;
1151  $p['value']    = '1';
1152  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1153  $att = buildAttributes($p);
1154
1155  print '<span class="nowrap">';
1156  print "<input $att />";
1157  print '<label for="minoredit">';
1158  print $lang['minoredit'];
1159  print '</label>';
1160  print '</span>';
1161}
1162
1163/**
1164 * prints some debug info
1165 *
1166 * @author Andreas Gohr <andi@splitbrain.org>
1167 */
1168function html_debug(){
1169  global $conf;
1170  global $lang;
1171  global $auth;
1172  global $INFO;
1173
1174  //remove sensitive data
1175  $cnf = $conf;
1176  $cnf['auth']='***';
1177  $cnf['notify']='***';
1178  $cnf['ftp']='***';
1179  $nfo = $INFO;
1180  $nfo['userinfo'] = '***';
1181  $ses = $_SESSION;
1182  $ses[$conf['title']]['auth'] = '***';
1183
1184  print '<html><body>';
1185
1186  print '<p>When reporting bugs please send all the following ';
1187  print 'output as a mail to andi@splitbrain.org ';
1188  print 'The best way to do this is to save this page in your browser</p>';
1189
1190  print '<b>$INFO:</b><pre>';
1191  print_r($nfo);
1192  print '</pre>';
1193
1194  print '<b>$_SERVER:</b><pre>';
1195  print_r($_SERVER);
1196  print '</pre>';
1197
1198  print '<b>$conf:</b><pre>';
1199  print_r($cnf);
1200  print '</pre>';
1201
1202  print '<b>DOKU_BASE:</b><pre>';
1203  print DOKU_BASE;
1204  print '</pre>';
1205
1206  print '<b>abs DOKU_BASE:</b><pre>';
1207  print DOKU_URL;
1208  print '</pre>';
1209
1210  print '<b>rel DOKU_BASE:</b><pre>';
1211  print dirname($_SERVER['PHP_SELF']).'/';
1212  print '</pre>';
1213
1214  print '<b>PHP Version:</b><pre>';
1215  print phpversion();
1216  print '</pre>';
1217
1218  print '<b>locale:</b><pre>';
1219  print setlocale(LC_ALL,0);
1220  print '</pre>';
1221
1222  print '<b>encoding:</b><pre>';
1223  print $lang['encoding'];
1224  print '</pre>';
1225
1226  if($auth){
1227    print '<b>Auth backend capabilities:</b><pre>';
1228    print_r($auth->cando);
1229    print '</pre>';
1230  }
1231
1232  print '<b>$_SESSION:</b><pre>';
1233  print_r($ses);
1234  print '</pre>';
1235
1236  print '<b>Environment:</b><pre>';
1237  print_r($_ENV);
1238  print '</pre>';
1239
1240  print '<b>PHP settings:</b><pre>';
1241  $inis = ini_get_all();
1242  print_r($inis);
1243  print '</pre>';
1244
1245  print '</body></html>';
1246}
1247
1248function html_admin(){
1249  global $ID;
1250  global $INFO;
1251  global $lang;
1252  global $conf;
1253
1254  print p_locale_xhtml('admin');
1255
1256  // build menu of admin functions from the plugins that handle them
1257  $pluginlist = plugin_list('admin');
1258  $menu = array();
1259  foreach ($pluginlist as $p) {
1260    if($obj =& plugin_load('admin',$p) === NULL) continue;
1261
1262    // check permissions
1263    if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1264
1265    $menu[] = array('plugin' => $p,
1266                    'prompt' => $obj->getMenuText($conf['lang']),
1267                    'sort' => $obj->getMenuSort()
1268                   );
1269  }
1270
1271  usort($menu, 'p_sort_modes');
1272
1273  // output the menu
1274  ptln('<ul>');
1275
1276  foreach ($menu as $item) {
1277    if (!$item['prompt']) continue;
1278    ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
1279  }
1280
1281  ptln('</ul>');
1282}
1283
1284/**
1285 * Form to request a new password for an existing account
1286 *
1287 * @author Benoit Chesneau <benoit@bchesneau.info>
1288 */
1289function html_resendpwd() {
1290  global $lang;
1291  global $conf;
1292  global $ID;
1293
1294  print p_locale_xhtml('resendpwd');
1295?>
1296  <div class="centeralign">
1297  <form id="dw__resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
1298    <fieldset>
1299      <br />
1300      <legend><?php echo $lang['resendpwd']?></legend>
1301      <input type="hidden" name="do" value="resendpwd" />
1302      <input type="hidden" name="save" value="1" />
1303      <label class="block">
1304        <span><?php echo $lang['user']?></span>
1305        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
1306      </label><br />
1307      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
1308    </fieldset>
1309  </form>
1310  </div>
1311<?php
1312}
1313
1314//Setup VIM: ex: et ts=2 enc=utf-8 :
1315