xref: /dokuwiki/inc/html.php (revision 247c1c5d1105cce361fd81b965640bc8e25aa09e)
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><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
398  print '<li><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</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
420    print $date;
421
422    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" border="0" width="15" height="11" alt="" /> ';
423
424    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
425
426    print $INFO['sum'];
427    print ' <span class="user">';
428    print $INFO['editor'];
429    print '</span> ';
430
431    print '('.$lang['current'].')';
432    print '</li>';
433  }
434
435  foreach($revisions as $rev){
436    $date = date($conf['dformat'],$rev);
437    $info = getRevisionInfo($ID,$rev);
438
439    print ($info['minor']) ? '<li class="minor">' : '<li>';
440    print $date;
441
442    print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
443    $p = array();
444    $p['src']    = DOKU_BASE.'lib/images/diff.png';
445    $p['border'] = 0;
446    $p['width']  = 15;
447    $p['height'] = 11;
448    $p['title']  = $lang['diff'];
449    $p['alt']    = $lang['diff'];
450    $att = buildAttributes($p);
451    print "<img $att />";
452    print '</a> ';
453
454    print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
455
456    print htmlspecialchars($info['sum']);
457    print ' <span class="user">';
458    if($info['user']){
459      print $info['user'];
460    }else{
461      print $info['ip'];
462    }
463    print '</span>';
464
465    print '</li>';
466  }
467  print '</ul>';
468}
469
470/**
471 * display recent changes
472 *
473 * @author Andreas Gohr <andi@splitbrain.org>
474 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
475 */
476function html_recent($first=0){
477  global $conf;
478  global $lang;
479  global $ID;
480  /* we need to get one additionally log entry to be able to
481   * decide if this is the last page or is there another one.
482   * This is the cheapest solution to get this information.
483   */
484  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
485  if(count($recents) == 0 && $first != 0){
486    $first=0;
487    $recents = getRecents(0,$conf['recent'] + 1,getNS($ID));
488  }
489  $cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent'];
490
491  print p_locale_xhtml('recent');
492  print '<ul>';
493
494  foreach($recents as $recent){
495    $date = date($conf['dformat'],$recent['date']);
496    print ($recent['minor']) ? '<li class="minor">' : '<li>';
497
498    print $date.' ';
499
500    print '<a href="'.wl($recent['id'],"do=diff").'">';
501    $p = array();
502    $p['src']    = DOKU_BASE.'lib/images/diff.png';
503    $p['border'] = 0;
504    $p['width']  = 15;
505    $p['height'] = 11;
506    $p['title']  = $lang['diff'];
507    $p['alt']    = $lang['diff'];
508    $att = buildAttributes($p);
509    print "<img $att />";
510    print '</a> ';
511
512    print '<a href="'.wl($recent['id'],"do=revisions").'">';
513    $p = array();
514    $p['src']    = DOKU_BASE.'lib/images/history.png';
515    $p['border'] = 0;
516    $p['width']  = 12;
517    $p['height'] = 14;
518    $p['title']  = $lang['btn_revs'];
519    $p['alt']    = $lang['btn_revs'];
520    $att = buildAttributes($p);
521    print "<img $att />";
522    print '</a> ';
523
524    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
525    print ' '.htmlspecialchars($recent['sum']);
526
527    print ' <span class="user">';
528    if($recent['user']){
529      print $recent['user'];
530    }else{
531      print $recent['ip'];
532    }
533    print '</span>';
534
535    print '</li>';
536  }
537  print '</ul>';
538
539  print '<div class="pagenav">';
540  $last = $first + $conf['recent'];
541  if ($first > 0) {
542    $first -= $conf['recent'];
543    if ($first < 0) $first = 0;
544    print '<div class="pagenav-prev">';
545    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
546    print '</div>';
547  }
548  if ($conf['recent'] < count($recents)) {
549    print '<div class="pagenav-next">';
550    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
551    print '</div>';
552  }
553  print '</div>';
554}
555
556/**
557 * Display page index
558 *
559 * @author Andreas Gohr <andi@splitbrain.org>
560 */
561function html_index($ns){
562  require_once(DOKU_INC.'inc/search.php');
563  global $conf;
564  global $ID;
565  $dir = $conf['datadir'];
566  $ns  = cleanID($ns);
567  #fixme use appropriate function
568  if(empty($ns)){
569    $ns = dirname(str_replace(':','/',$ID));
570    if($ns == '.') $ns ='';
571  }
572  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
573
574  print p_locale_xhtml('index');
575
576  $data = array();
577  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
578  print html_buildlist($data,'idx','html_list_index','html_li_index');
579}
580
581/**
582 * Index item formatter
583 *
584 * User function for html_buildlist()
585 *
586 * @author Andreas Gohr <andi@splitbrain.org>
587 */
588function html_list_index($item){
589  $ret = '';
590  $base = ':'.$item['id'];
591  $base = substr($base,strrpos($base,':')+1);
592  if($item['type']=='d'){
593    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
594    $ret .= $base;
595    $ret .= '</a>';
596  }else{
597    $ret .= html_wikilink(':'.$item['id']);
598  }
599  return $ret;
600}
601
602/**
603 * Index List item
604 *
605 * This user function is used in html_build_lidt to build the
606 * <li> tags for namespaces when displaying the page index
607 * it gives different classes to opened or closed "folders"
608 *
609 * @author Andreas Gohr <andi@splitbrain.org>
610 */
611function html_li_index($item){
612  if($item['type'] == "f"){
613    return '<li class="level'.$item['level'].'">';
614  }elseif($item['open']){
615    return '<li class="open">';
616  }else{
617    return '<li class="closed">';
618  }
619}
620
621/**
622 * Default List item
623 *
624 * @author Andreas Gohr <andi@splitbrain.org>
625 */
626function html_li_default($item){
627  return '<li class="level'.$item['level'].'">';
628}
629
630/**
631 * Build an unordered list
632 *
633 * Build an unordered list from the given $data array
634 * Each item in the array has to have a 'level' property
635 * the item itself gets printed by the given $func user
636 * function. The second and optional function is used to
637 * print the <li> tag. Both user function need to accept
638 * a single item.
639 *
640 * @author Andreas Gohr <andi@splitbrain.org>
641 */
642function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
643  $level = 0;
644  $opens = 0;
645  $ret   = '';
646
647  foreach ($data as $item){
648
649    if( $item['level'] > $level ){
650      //open new list
651      for($i=0; $i<($item['level'] - $level); $i++){
652        if ($i) $ret .= "<li class=\"clear\">\n";
653        $ret .= "\n<ul class=\"$class\">\n";
654      }
655    }elseif( $item['level'] < $level ){
656      //close last item
657      $ret .= "</li>\n";
658      for ($i=0; $i<($level - $item['level']); $i++){
659        //close higher lists
660        $ret .= "</ul>\n</li>\n";
661      }
662    }else{
663      //close last item
664      $ret .= "</li>\n";
665    }
666
667    //remember current level
668    $level = $item['level'];
669
670    //print item
671    $ret .= $lifunc($item); //user function
672    $ret .= '<span class="li">';
673    $ret .= $func($item); //user function
674    $ret .= '</span>';
675  }
676
677  //close remaining items and lists
678  for ($i=0; $i < $level; $i++){
679    $ret .= "</li></ul>\n";
680  }
681
682  return $ret;
683}
684
685/**
686 * display backlinks
687 *
688 * @author Andreas Gohr <andi@splitbrain.org>
689 */
690function html_backlinks(){
691  require_once(DOKU_INC.'inc/fulltext.php');
692  global $ID;
693  global $conf;
694
695  print p_locale_xhtml('backlinks');
696
697  $data = ft_backlinks($ID);
698
699  print '<ul class="idx">';
700  foreach($data as $blink){
701    print '<li>';
702    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
703    print '</li>';
704  }
705  print '</ul>';
706}
707
708/**
709 * show diff
710 *
711 * @author Andreas Gohr <andi@splitbrain.org>
712 */
713function html_diff($text='',$intro=true){
714  require_once(DOKU_INC.'inc/DifferenceEngine.php');
715  global $ID;
716  global $REV;
717  global $lang;
718  global $conf;
719  if($text){
720    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
721                    split("\n",htmlspecialchars(cleanText($text))));
722    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
723              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
724              $lang['current'];
725    $right = $lang['yours'];
726  }else{
727    if($REV){
728      $r = $REV;
729    }else{
730      //use last revision if none given
731      $revs = getRevisions($ID);
732      $r = $revs[0];
733    }
734
735    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))),
736                    split("\n",htmlspecialchars(rawWiki($ID,''))));
737    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
738              $ID.' '.date($conf['dformat'],$r).'</a>';
739    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
740              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
741              $lang['current'];
742  }
743  $tdf = new TableDiffFormatter();
744  if($intro) print p_locale_xhtml('diff');
745  ?>
746    <table class="diff" width="100%">
747      <tr>
748        <td colspan="2" width="50%" class="diff-header">
749          <?php echo $left?>
750        </td>
751        <td colspan="2" width="50%" class="diff-header">
752          <?php echo $right?>
753        </td>
754      </tr>
755      <?php echo $tdf->format($df)?>
756    </table>
757  <?php
758}
759
760/**
761 * show warning on conflict detection
762 *
763 * @author Andreas Gohr <andi@splitbrain.org>
764 */
765function html_conflict($text,$summary){
766  global $ID;
767  global $lang;
768
769  print p_locale_xhtml('conflict');
770  ?>
771  <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
772  <div class="centeralign">
773    <input type="hidden" name="id" value="<?php echo $ID?>" />
774    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
775    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
776
777    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
778    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" />
779  </div>
780  </form>
781  <br /><br /><br /><br />
782  <?php
783}
784
785/**
786 * Prints the global message array
787 *
788 * @author Andreas Gohr <andi@splitbrain.org>
789 */
790function html_msgarea(){
791  global $MSG;
792
793  if(!isset($MSG)) return;
794
795  foreach($MSG as $msg){
796    print '<div class="'.$msg['lvl'].'">';
797    print $msg['msg'];
798    print '</div>';
799  }
800}
801
802/**
803 * Prints the registration form
804 *
805 * @author Andreas Gohr <andi@splitbrain.org>
806 */
807function html_register(){
808  global $lang;
809  global $conf;
810  global $ID;
811
812  print p_locale_xhtml('register');
813?>
814  <div class="centeralign">
815  <form name="register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
816  <fieldset>
817    <input type="hidden" name="do" value="register" />
818    <input type="hidden" name="save" value="1" />
819
820    <legend><?php echo $lang['register']?></legend>
821    <label class="block">
822      <?php echo $lang['user']?>
823      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
824    </label><br />
825
826    <?php
827      if (!$conf['autopasswd']) {
828    ?>
829      <label class="block">
830        <?php echo $lang['pass']?>
831        <input type="password" name="pass" class="edit" size="50" />
832      </label><br />
833      <label class="block">
834        <?php echo $lang['passchk']?>
835        <input type="password" name="passchk" class="edit" size="50" />
836      </label><br />
837    <?php
838      }
839    ?>
840
841    <label class="block">
842      <?php echo $lang['fullname']?>
843      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
844    </label><br />
845    <label class="block">
846      <?php echo $lang['email']?>
847      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
848    </label><br />
849    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
850  </fieldset>
851  </form>
852  </div>
853<?php
854}
855
856/**
857 * Print the update profile form
858 *
859 * @author Christopher Smith <chris@jalakai.co.uk>
860 * @author Andreas Gohr <andi@splitbrain.org>
861 */
862function html_updateprofile(){
863  global $lang;
864  global $conf;
865  global $ID;
866  global $INFO;
867
868  print p_locale_xhtml('updateprofile');
869
870  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
871  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
872?>
873  <div class="centeralign">
874  <form name="register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
875  <fieldset style="width: 80%;">
876    <input type="hidden" name="do" value="profile" />
877    <input type="hidden" name="save" value="1" />
878
879    <legend><?php echo $lang['profile']?></legend>
880    <label class="block">
881      <?php echo $lang['user']?>
882      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
883    </label><br />
884    <label class="block">
885      <?php echo $lang['fullname']?>
886      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
887    </label><br />
888    <label class="block">
889      <?php echo $lang['email']?>
890      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
891    </label><br /><br />
892    <label class="block">
893      <?php echo $lang['newpass']?>
894      <input type="password" name="newpass" class="edit" size="50" />
895    </label><br />
896    <label class="block">
897      <?php echo $lang['passchk']?>
898      <input type="password" name="passchk" class="edit" size="50" />
899    </label><br />
900
901    <?php if ($conf['profileconfirm']) { ?>
902      <br />
903      <label class="block">
904      <?php echo $lang['oldpass']?>
905      <input type="password" name="oldpass" class="edit" size="50" />
906    </label><br />
907    <?php } ?>
908
909    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
910    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
911  </fieldset>
912  </form>
913  </div>
914<?php
915}
916
917/**
918 * This displays the edit form (lots of logic included)
919 *
920 * @fixme  this is a huge lump of code and should be modularized
921 * @author Andreas Gohr <andi@splitbrain.org>
922 */
923function html_edit($text=null,$include='edit'){ //FIXME: include needed?
924  global $ID;
925  global $REV;
926  global $DATE;
927  global $RANGE;
928  global $PRE;
929  global $SUF;
930  global $INFO;
931  global $SUM;
932  global $lang;
933  global $conf;
934
935  //set summary default
936  if(!$SUM){
937    if($REV){
938      $SUM = $lang['restored'];
939    }elseif(!$INFO['exists']){
940      $SUM = $lang['created'];
941    }
942  }
943
944  //no text? Load it!
945  if(!isset($text)){
946    $pr = false; //no preview mode
947    if($INFO['exists']){
948      if($RANGE){
949        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
950      }else{
951        $text = rawWiki($ID,$REV);
952      }
953    }else{
954      //try to load a pagetemplate
955      $text = pageTemplate($ID);
956    }
957  }else{
958    $pr = true; //preview mode
959  }
960
961  $wr = $INFO['writable'];
962  if($wr){
963    if ($REV) print p_locale_xhtml('editrev');
964    print p_locale_xhtml($include);
965  }else{
966    print p_locale_xhtml('read');
967    $ro='readonly="readonly"';
968  }
969  if(!$DATE) $DATE = $INFO['lastmod'];
970
971
972?>
973  <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
974  <table style="width:99%">
975    <tr>
976      <td class="toolbar" colspan="2">
977        <div id="toolbar"></div>
978        <input type="hidden" name="id"   value="<?php echo $ID?>" />
979        <input type="hidden" name="rev"  value="<?php echo $REV?>" />
980        <input type="hidden" name="date" value="<?php echo $DATE?>" />
981        <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
982        <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
983
984        <?php if($wr){?>
985        <script type="text/javascript" charset="utf-8">
986          <?php /* sets changed to true when previewed */?>
987          textChanged = <?php ($pr) ? print 'true' : print 'false' ?>;
988        </script>
989        <span id="spell_action"></span>
990        <?php } ?>
991      </td>
992      <td>
993        <div id="spell_suggest"></div>
994      </td>
995    </tr>
996    <tr>
997      <td colspan="3">
998        <div id="spell_result"></div>
999        <textarea name="wikitext" id="wikitext" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
1000      </td>
1001    </tr>
1002    <tr id="wikieditbar">
1003      <td>
1004      <?php if($wr){?>
1005        <input class="button" id="edbtn_save" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" tabindex="4" />
1006        <input class="button" id="edbtn_preview" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" tabindex="5" />
1007        <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="5" />
1008      <?php } ?>
1009      </td>
1010      <td>
1011      <?php if($wr){ ?>
1012        <?php echo $lang['summary']?>:
1013        <input type="text" class="edit" name="summary" id="summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1014        <?php html_minoredit()?>
1015      <?php }?>
1016      </td>
1017      <td class="rightalign">
1018        <div id="sizectl"></div>
1019      </td>
1020    </tr>
1021  </table>
1022  </form>
1023<?php
1024}
1025
1026/**
1027 * Adds a checkbox for minor edits for logged in users
1028 *
1029 * @author Andrea Gohr <andi@splitbrain.org>
1030 */
1031function html_minoredit(){
1032  global $conf;
1033  global $lang;
1034  // minor edits are for logged in users only
1035  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1036    return;
1037  }
1038
1039  $p = array();
1040  $p['name']     = 'minor';
1041  $p['type']     = 'checkbox';
1042  $p['id']       = 'minoredit';
1043  $p['tabindex'] = 3;
1044  $p['value']    = '1';
1045  if($_REQUEST['minor']) $p['checked']='checked';
1046  $att = buildAttributes($p);
1047
1048  print "<input $att />";
1049  print '<label for="minoredit">';
1050  print $lang['minoredit'];
1051  print '</label>';
1052}
1053
1054/**
1055 * prints some debug info
1056 *
1057 * @author Andreas Gohr <andi@splitbrain.org>
1058 */
1059function html_debug(){
1060  global $conf;
1061  global $lang;
1062  //remove sensitive data
1063  $cnf = $conf;
1064  $cnf['auth']='***';
1065  $cnf['notify']='***';
1066  $cnf['ftp']='***';
1067
1068  print '<html><body>';
1069
1070  print '<p>When reporting bugs please send all the following ';
1071  print 'output as a mail to andi@splitbrain.org ';
1072  print 'The best way to do this is to save this page in your browser</p>';
1073
1074  print '<b>$_SERVER:</b><pre>';
1075  print_r($_SERVER);
1076  print '</pre>';
1077
1078  print '<b>$conf:</b><pre>';
1079  print_r($cnf);
1080  print '</pre>';
1081
1082  print '<b>DOKU_BASE:</b><pre>';
1083  print DOKU_BASE;
1084  print '</pre>';
1085
1086  print '<b>abs DOKU_BASE:</b><pre>';
1087  print DOKU_URL;
1088  print '</pre>';
1089
1090  print '<b>rel DOKU_BASE:</b><pre>';
1091  print dirname($_SERVER['PHP_SELF']).'/';
1092  print '</pre>';
1093
1094  print '<b>PHP Version:</b><pre>';
1095  print phpversion();
1096  print '</pre>';
1097
1098  print '<b>locale:</b><pre>';
1099  print setlocale(LC_ALL,0);
1100  print '</pre>';
1101
1102  print '<b>encoding:</b><pre>';
1103  print $lang['encoding'];
1104  print '</pre>';
1105
1106  print '<b>$_SESSION:</b><pre>';
1107  print_r($_SESSION);
1108  print '</pre>';
1109
1110  print '<b>Environment:</b><pre>';
1111  print_r($_ENV);
1112  print '</pre>';
1113
1114  print '<b>PHP settings:</b><pre>';
1115  $inis = ini_get_all();
1116  print_r($inis);
1117  print '</pre>';
1118
1119  print '</body></html>';
1120}
1121
1122function html_admin(){
1123  global $ID;
1124  global $lang;
1125  global $conf;
1126
1127  print p_locale_xhtml('admin');
1128
1129  // build menu of admin functions from the plugins that handle them
1130  $pluginlist = plugin_list('admin');
1131  $menu = array();
1132  foreach ($pluginlist as $p) {
1133    if($obj =& plugin_load('admin',$p) === NULL) continue;
1134    $menu[] = array('plugin' => $p,
1135                    'prompt' => $obj->getMenuText($conf['lang']),
1136                    'sort' => $obj->getMenuSort()
1137                   );
1138  }
1139
1140  usort($menu, p_sort_modes);
1141
1142  // output the menu
1143  ptln('<ul>');
1144
1145  foreach ($menu as $item) {
1146    if (!$item['prompt']) continue;
1147    ptln('  <li><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></li>');
1148  }
1149
1150  // add in non-plugin functions
1151  if (!$conf['openregister']){
1152    ptln('<li><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></li>');
1153  }
1154
1155  ptln('</ul>');
1156}
1157
1158/**
1159 * Form to request a new password for an existing account
1160 *
1161 * @author Benoit Chesneau <benoit@bchesneau.info>
1162 */
1163function html_resendpwd() {
1164  global $lang;
1165  global $conf;
1166  global $ID;
1167
1168  print p_locale_xhtml('resendpwd');
1169?>
1170  <div class="centeralign">
1171  <form name="resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
1172    <fieldset>
1173      <br />
1174      <legend><?php echo $lang['resendpwd']?></legend>
1175      <input type="hidden" name="do" value="resendpwd" />
1176      <input type="hidden" name="save" value="1" />
1177      <label class="block">
1178        <span><?php echo $lang['user']?></span>
1179        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
1180      </label><br />
1181      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
1182    </fieldset>
1183  </form>
1184  </div>
1185<?php
1186}
1187
1188//Setup VIM: ex: et ts=2 enc=utf-8 :
1189