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