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