xref: /dokuwiki/inc/html.php (revision 132bdbfe5a8ce4c57b4ae7d4391e99d05f186d43)
1<?
2include_once("inc/format.php");
3
4/**
5 * Convenience function to quickly build a wikilink
6 */
7function html_wikilink($url,$name='',$search=''){
8  global $conf;
9  $link         = array();
10  $link['url']  = $url;
11  $link['name'] = $name;
12  $link         = format_link_wiki($link);
13
14  if($search){
15    ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
16    $link['url'] .= urlencode($search);
17  }
18
19  return format_link_build($link);
20}
21
22/**
23 * The loginform
24 */
25function html_login(){
26  global $lang;
27  global $conf;
28  global $ID;
29
30  print parsedLocale('login');
31  ?>
32    <div align="center">
33    <form action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" method="post">
34      <fieldset>
35        <legend><?=$lang['btn_login']?></legend>
36        <input type="hidden" name="id" value="<?=$ID?>" />
37        <input type="hidden" name="do" value="login" />
38        <label>
39          <span><?=$lang['user']?></span>
40          <input type="text" name="u" value="<?=formText($_REQUEST['u'])?>" class="edit" />
41        </label><br />
42        <label>
43          <span><?=$lang['pass']?></span>
44          <input type="password" name="p" class="edit" />
45        </label><br />
46        <input type="submit" value="<?=$lang['btn_login']?>" class="button" />
47        <label for="remember" class="simple">
48          <input type="checkbox" name="r" id="remember" value="1" />
49          <span><?=$lang['remember']?></span>
50        </label>
51      </fieldset>
52    </form>
53  <?
54    if($conf['openregister']){
55      print '<p>';
56      print $lang['reghere'];
57      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
58      print '</p>';
59    }
60  ?>
61    </div>
62  <?
63  if(@file_exists('includes/login.txt')){
64    print io_cacheParse('includes/login.txt');
65  }
66}
67
68/**
69 * shows the edit/source/show button dependent on current mode
70 */
71function html_editbutton(){
72  global $ID;
73  global $REV;
74  global $ACT;
75  global $INFO;
76
77  if($ACT == 'show' || $ACT == 'search'){
78    if($INFO['writable']){
79      if($INFO['exists']){
80        $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
81      }else{
82        $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
83      }
84    }else{
85      $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
86    }
87  }else{
88    $r = html_btn('show',$ID,'v',array('do' => 'show'));
89  }
90  return $r;
91}
92
93function html_secedit_button($section,$p){
94  global $ID;
95  global $lang;
96  $secedit  = '';
97  if($p) $secedit .= "</p>\n";
98  $secedit .= '<div class="secedit">';
99  $secedit .= html_btn('secedit',$ID,'',
100                        array('do'      => 'edit',
101                              'lines'   => "$section"),
102                              'post');
103  $secedit .= '</div>';
104  if($p) $secedit .= "\n<p>";
105  return $secedit;
106}
107
108function html_secedit($text,$show=true){
109  global $INFO;
110  if($INFO['writable'] && $show){
111    $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
112                         "html_secedit_button('\\1',true)",
113                         $text);
114    $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
115                         "html_secedit_button('\\1',false)",
116                         $text);
117  }else{
118    $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
119  }
120  return $text;
121}
122
123/**
124 * displays the breadcrumbs trace
125 */
126function html_breadcrumbs(){
127  global $lang;
128  global $conf;
129
130  //check if enabled
131  if(!$conf['breadcrumbs']) return;
132
133  $crumbs = breadcrumbs(); //setup crumb trace
134  print '<div class="breadcrumbs">';
135  print $lang['breadcrumb'].':';
136  foreach ($crumbs as $crumb){
137    print ' &raquo; ';
138    print '<a href="'.wl($crumb).'" class="breadcrumbs" onclick="return svchk()" onkeypress="return svchk()" title="'.$crumb.'">'.noNS($crumb).'</a>';
139  }
140  print '</div>';
141}
142
143/**
144 * display the HTML head and metadata
145 */
146function html_head(){
147  global $ID;
148  global $ACT;
149  global $INFO;
150  global $conf;
151  global $lang;
152
153  print '<'.'?xml version="1.0"?'.">\n";
154  print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"';
155  print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
156  print "\n";
157?>
158  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$conf['lang']?>" lang="<?=$conf['lang']?>" dir="ltr">
159  <head>
160    <title><?=$ID?> [<?=$conf['title']?>]</title>
161    <meta http-equiv="Content-Type" content="text/html; charset=<?=$lang['encoding']?>" />
162    <meta name="generator" content="DokuWiki <?=DOKUWIKIVERSION?>" />
163    <link rel="stylesheet" media="screen" type="text/css" href="<?=getBaseURL()?>style.css" />
164    <link rel="stylesheet" media="print" type="text/css" href="<?=getBaseURL()?>print.css" />
165    <link rel="shortcut icon" href="<?=getBaseURL()?>images/favicon.ico" />
166    <link rel="start" href="<?=wl()?>" />
167    <link rel="contents" href="<?=wl($ID,'do=index')?>" title="<?=$lang['index']?>" />
168    <link rel="alternate" type="application/rss+xml" title="Recent Changes" href="<?=getBaseURL()?>feed.php" />
169    <link rel="alternate" type="application/rss+xml" title="Current Namespace" href="<?=getBaseURL()?>feed.php?mode=list&amp;ns=<?=$INFO['namespace']?>" />
170    <link rel="alternate" type="text/html" title="Plain HTML" href="<?=wl($ID,'do=export_html')?>" />
171    <link rel="alternate" type="text/plain" title="Wiki Markup" href="<?=wl($ID, 'do=export_raw')?>" />
172<?
173  if($ACT=='show' || $ACT=='export_html'){
174    if($INFO['exists']){
175      print '    <meta name="robots" content="index,follow" />'."\n";
176      print '    <meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />'."\n";
177    }else{
178      print '    <meta name="robots" content="noindex,follow" />'."\n";
179    }
180  }else{
181    print '    <meta name="robots" content="noindex,nofollow" />'."\n";
182  }
183?>
184
185    <script language="JavaScript" type="text/javascript">
186      var alertText   = '<?=$lang['qb_alert']?>';
187      var notSavedYet = '<?=$lang['notsavedyet']?>';
188      var baseURL     = '<?=getBaseURL()?>';
189    </script>
190    <script language="JavaScript" type="text/javascript" src="<?=getBaseURL()?>script.js"></script>
191
192    <!--[if gte IE 5]>
193    <style type="text/css">
194      /* that IE 5+ conditional comment makes this only visible in IE 5+ */
195      img { behavior: url("<?=getBaseURL()?>pngbehavior.htc"); } /* IE bugfix for transparent PNGs */
196    </style>
197    <![endif]-->
198
199    <?@include("includes/meta.html")?>
200  </head>
201<?
202}
203
204/**
205 * Displays a button (using it's own form)
206 */
207function html_btn($name,$id,$akey,$params,$method='get'){
208  global $conf;
209  global $lang;
210
211  $label = $lang['btn_'.$name];
212
213  $ret = '';
214
215  $id = idfilter($id);
216
217  //make nice URLs even for buttons
218  $link = getBaseURL().'/';
219  $link = preg_replace('#//$#','/',$link);
220  if(!$conf['userewrite']){
221    $script = $link.'doku.php';
222    $params['id'] = $id;
223  }else{
224    $script = $link.$id;
225  }
226
227  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'" onsubmit="return svchk()">';
228
229  reset($params);
230  while (list($key, $val) = each($params)) {
231    $ret .= '<input type="hidden" name="'.$key.'" ';
232    $ret .= 'value="'.htmlspecialchars($val).'" />';
233  }
234
235  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
236  if($akey){
237    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
238    $ret .= 'accesskey="'.$akey.'" ';
239  }
240  $ret .= '/>';
241  $ret .= '</form>';
242
243  return $ret;
244}
245
246/**
247 * Check for the given permission or prints an error
248 */
249function html_acl($perm){
250  global $INFO;
251  if($INFO['perm'] >= $perm) return true;
252
253  print parsedLocale('denied');
254  return false;
255}
256
257/**
258 * Displays the page header and calls html_head()
259 */
260function html_header(){
261  global $ID;
262  global $REV;
263  global $lang;
264  global $conf;
265  html_head();
266?>
267<body>
268  <div class="all">
269  <?
270    html_msgarea();
271    @include("includes/topheader.html")
272  ?>
273  <div class="header">
274    <div class="pagename">
275      [[<a href="<?=wl($ID,'do=backlink')?>" onclick="return svchk()" onkeypress="return svchk()"><?=$ID?></a>]]
276    </div>
277    <div class="logo">
278      <a href="<?=wl()?>" name="top" accesskey="h" title="[ALT+H]" onclick="return svchk()" onkeypress="return svchk()"><?=$conf['title']?></a>
279    </div>
280  </div>
281  <?@include("includes/header.html")?>
282
283  <div class="bar" id="bar_top">
284    <div class="bar-left" id="bar_topleft">
285      <?=html_editbutton()?>
286      <?=html_btn(revs,$ID,'r',array('do' => 'revisions'))?>
287    </div>
288
289    <div class="bar-right" id="bar_topright">
290      <?=html_btn(recent,'','r',array('do' => 'recent'))?>
291      <form action="<?=wl()?>" accept-charset="<?=$lang['encoding']?>">
292      <input type="hidden" name="do" value="search" />
293      <input type="text" name="id" class="edit" />
294			<input type="submit" value="<?=$lang['btn_search']?>" class="button" />
295      </form>&nbsp;
296    </div>
297  </div>
298
299  <?
300    flush();
301    html_breadcrumbs();
302    @include("includes/pageheader.html");
303  ?>
304  <div class="page">
305  <!-- wikipage start -->
306<?
307}
308
309/**
310 * Displays some Metadata like who's logged in and the last modified
311 * date - do not confuse this with the HTML meta header.
312 */
313function html_metainfo(){
314  global $conf;
315  global $lang;
316  global $INFO;
317  global $REV;
318
319  $fn = $INFO['filepath'];
320  if(!$conf['fullpath']){
321    if($REV){
322      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
323    }else{
324      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
325    }
326  }
327  $date = date($conf['dformat'],$INFO['lastmod']);
328
329  print '<div class="meta">';
330  if($_SERVER['REMOTE_USER']){
331    print '<div class="user">';
332    print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER'];
333    print '</div>';
334  }
335  print ' &nbsp; ';
336  if($INFO['exists']){
337    print $fn;
338    print ' &middot; ';
339    print $lang['lastmod'];
340    print ': ';
341    print $date;
342    if($INFO['locked']){
343      print ' &middot; ';
344      print $lang['lockedby'];
345      print ': ';
346      print $INFO['locked'];
347    }
348  }
349  print '</div>';
350}
351
352function html_footer(){
353  global $ID;
354  global $REV;
355  global $INFO;
356  global $lang;
357  global $conf;
358?>
359  <!-- wikipage stop -->
360  </div>
361  <div class="clearer">&nbsp;</div>
362  <?
363    flush();
364    @include("includes/pagefooter.html");
365    html_metainfo();
366  ?>
367  <div class="bar" id="bar_bottom">
368    <div class="bar-left" id="bar_bottomleft">
369      <?=html_editbutton()?>
370      <?=html_btn(revs,$ID,'r',array('do' => 'revisions'))?>
371    </div>
372
373    <div class="bar-right" id="bar_bottomright">
374      <?
375        if($conf['useacl']){
376          if($_SERVER['REMOTE_USER']){
377            print html_btn('logout',$ID,'',array('do' => 'logout',));
378          }else{
379            print html_btn('login',$ID,'',array('do' => 'login'));
380          }
381        }
382      ?>
383      <?=html_btn(index,$ID,'x',array('do' => 'index'))?>
384      <a href="#top"><input type="button" class="button" value="<?=$lang['btn_top']?>" /></a>&nbsp;
385    </div>
386  </div>
387  <?@include("includes/footer.html")?>
388  </div>
389  </body>
390  </html>
391<?
392}
393
394function html_toc($toc){
395  global $lang;
396  $ret  = '';
397  $ret .= '<div class="toc">';
398  $ret .=   '<div class="tocheader">';
399  $ret .=      $lang['toc'];
400  $ret .=     ' <script type="text/javascript">';
401  $ret .=     'showTocToggle("+","-")';
402  $ret .=     '</script>';
403  $ret .=   '</div>';
404  $ret .=   '<div id="tocinside">';
405  $ret .=   html_buildlist($toc,'toc','html_list_toc');
406  $ret .=   '</div>';
407  $ret .= '</div>';
408  return $ret;
409}
410
411/**
412 * User function for html_buildlist()
413 */
414function html_list_toc($item){
415  $ret  = '';
416  $ret .= '<a href="#'.$item['id'].'" class="toc">';
417  $ret .= $item['name'];
418  $ret .= '</a>';
419  return $ret;
420}
421
422function html_show($text=''){
423  global $ID;
424  global $REV;
425  global $HIGH;
426  //disable section editing for old revisions or in preview
427  if($text || $REV){
428    global $parser;
429    $parser['secedit'] = false;
430  }
431
432  if ($text){
433    //PreviewHeader
434    print parsedLocale('preview');
435    print '<div class="preview">';
436    print html_secedit(parse($text),false);
437    print '</div>';
438  }else{
439    if ($REV) print parsedLocale('showrev');
440    $html = parsedWiki($ID,$REV,true);
441    $html = html_secedit($html);
442    print html_hilight($html,$HIGH);
443  }
444}
445
446/**
447 * Highlights searchqueries in HTML code
448 */
449function html_hilight($html,$query){
450  $queries = preg_split ("/\s/",$query,-1,PREG_SPLIT_NO_EMPTY);
451  foreach ($queries as $q){
452    $q = preg_quote($q,'/');
453    $html = preg_replace("/((<[^>]*)|$q)/ie", '"\2"=="\1"? "\1":"<span class=\"search_hit\">\1</span>"', $html);
454  }
455  return $html;
456}
457
458/**
459 * This function runs a search and displays the result
460 */
461function html_search(){
462  require_once("inc/search.php");
463  global $conf;
464  global $QUERY;
465  global $ID;
466  global $lang;
467
468  print parsedLocale('searchpage');
469  flush();
470
471  //do quick pagesearch
472  $data = array();
473  search($data,$conf['datadir'],'search_pagename',array(query => $QUERY));
474  if(count($data)){
475    sort($data);
476    print '<div class="search_quickresult">';
477    print '<b>'.$lang[quickhits].':</b><br />';
478    foreach($data as $row){
479      print '<div class="search_quickhits">';
480      print html_wikilink(':'.$row['id'],$row['id']);
481      print '</div> ';
482    }
483    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
484    print '<div class="clearer">&nbsp;</div>';
485    print '</div>';
486  }
487  flush();
488
489  //do fulltext search
490  $data = array();
491  search($data,$conf['datadir'],'search_fulltext',array(query => $QUERY));
492  if(count($data)){
493    usort($data,'sort_search_fulltext');
494    foreach($data as $row){
495      print '<div class="search_result">';
496      print html_wikilink(':'.$row['id'],$row['id'],$QUERY);
497      print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
498      print '<div class="search_snippet">'.$row['snippet'].'</div>';
499      print '</div>';
500    }
501  }else{
502    print '<div align="center">'.$lang['nothingfound'].'</div>';
503  }
504}
505
506function html_locked($ip){
507  global $ID;
508  global $conf;
509  global $lang;
510
511  $locktime = filemtime(wikiFN($ID).'.lock');
512  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
513  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
514
515  print parsedLocale('locked');
516  print '<ul>';
517  print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>';
518  print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>';
519  print '</ul>';
520}
521
522function html_revisions(){
523  global $ID;
524  global $INFO;
525  global $conf;
526  global $lang;
527  $revisions = getRevisions($ID);
528  $date = @date($conf['dformat'],$INFO['lastmod']);
529
530  print parsedLocale('revisions');
531  print '<ul>';
532  if($INFO['exists']){
533    print '<li>'.$date.' <a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ('.$lang['current'].')</li>';
534  }
535
536  foreach($revisions as $rev){
537    $date = date($conf['dformat'],$rev);
538    print '<li>';
539    print $date.' <a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
540    print '<a href="'.wl($ID,"rev=$rev,do=diff").'">['.$lang['diff'].']</a>';
541    print '</li>';
542  }
543  print '</ul>';
544}
545
546function html_recent(){
547  global $conf;
548  $recents = getRecents(0,true);
549
550  print parsedLocale('recent');
551  print '<ul>';
552  foreach(array_keys($recents) as $id){
553    $date = date($conf['dformat'],$recents[$id]['date']);
554    print '<li>';
555    print $date.' '.html_wikilink($id,$id);
556    print ' '.htmlspecialchars($recents[$id]['sum']);
557    print ' <span class="user">(';
558    print $recents[$id]['ip'];
559    if($recents[$id]['user']) print ' '.$recents[$id]['user'];
560    print ')</span>';
561    print '</li>';
562  }
563  print '</ul>';
564}
565
566function html_index($ns){
567  require_once("inc/search.php");
568  global $conf;
569  global $ID;
570  $dir = $conf['datadir'];
571  $ns  = cleanID($ns);
572  if(empty($ns)){
573    $ns = dirname(str_replace(':','/',$ID));
574    if($ns == '.') $ns ='';
575  }
576  $ns  = str_replace(':','/',$ns);
577
578  print parsedLocale('index');
579
580  $data = array();
581  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
582  print html_buildlist($data,'idx','html_list_index');
583}
584
585/**
586 * User function for html_buildlist()
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 * Build an unordered list from the given $data array
604 * Each item in the array has to have a 'level' property
605 * the item itself gets printed by the given $func user
606 * function
607 */
608function html_buildlist($data,$class,$func){
609  $level = 0;
610  $opens = 0;
611  $ret   = '';
612
613  foreach ($data as $item){
614
615    if( $item['level'] > $level ){
616      //open new list
617      $ret .= "\n<ul class=\"$class\">\n";
618    }elseif( $item['level'] < $level ){
619      //close last item
620      $ret .= "</li>\n";
621      for ($i=0; $i<($level - $item['level']); $i++){
622        //close higher lists
623        $ret .= "</ul>\n</li>\n";
624      }
625    }else{
626      //close last item
627      $ret .= "</li>\n";
628    }
629
630    //remember current level
631    $level = $item['level'];
632
633    //print item
634    $ret .= '<li class="level'.$item['level'].'">';
635    $ret .= '<span class="li">';
636    $ret .= $func($item); //user function
637    $ret .= '</span>';
638  }
639
640  //close remaining items and lists
641  for ($i=0; $i < $level; $i++){
642    $ret .= "</li></ul>\n";
643  }
644
645  return $ret;
646}
647
648function html_backlinks(){
649  require_once("inc/search.php");
650  global $ID;
651  global $conf;
652
653  if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
654    $opts['ns']   = $matches[1];
655    $opts['name'] = $matches[2];
656  }else{
657    $opts['ns']   = '';
658    $opts['name'] = $ID;
659  }
660
661  print parsedLocale('backlinks');
662
663  $data = array();
664  search($data,$conf['datadir'],'search_backlinks',$opts);
665  sort($data);
666
667  print '<ul class="idx">';
668  foreach($data as $row){
669    print '<li>';
670    print html_wikilink(':'.$row['id'],$row['id']);
671    print '</li>';
672  }
673  print '</ul>';
674}
675
676function html_diff($text='',$intro=true){
677  require_once("inc/DifferenceEngine.php");
678  global $ID;
679  global $REV;
680  global $lang;
681  global $conf;
682  if($text){
683    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
684                    split("\n",htmlspecialchars(cleanText($text))));
685    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
686              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
687              $lang['current'];
688    $right = $lang['yours'];
689  }else{
690    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$REV))),
691                    split("\n",htmlspecialchars(rawWiki($ID,''))));
692    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$REV").'">'.
693              $ID.' '.date($conf['dformat'],$REV).'</a>';
694    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
695              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
696              $lang['current'];
697  }
698  $tdf = new TableDiffFormatter();
699  if($intro) print parsedLocale('diff');
700  ?>
701    <table class="diff" width="100%">
702      <tr>
703        <td colspan="2" width="50%" class="diff-header">
704          <?=$left?>
705        </td>
706        <td colspan="2" width="50%" class="diff-header">
707          <?=$right?>
708        </td>
709      </tr>
710      <?=$tdf->format($df)?>
711    </table>
712  <?
713}
714
715function html_conflict($text,$summary){
716  global $ID;
717  global $lang;
718
719  print parsedLocale('conflict');
720  ?>
721  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
722  <input type="hidden" name="id" value="<?=$ID?>" />
723  <input type="hidden" name="wikitext" value="<?=formText($text)?>" />
724  <input type="hidden" name="summary" value="<?=formText($summary)?>" />
725
726  <div align="center">
727    <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
728    <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" />
729  </div>
730  </form>
731  <br /><br /><br /><br />
732  <?
733}
734
735/**
736 * Prints the glovbal message array
737 */
738function html_msgarea(){
739  global $MSG;
740
741  if(!isset($MSG)) return;
742
743  foreach($MSG as $msg){
744    print '<div class="'.$msg['lvl'].'">';
745    print $msg['msg'];
746    print '</div>';
747  }
748}
749
750/**
751 * Prints the registration form
752 */
753function html_register(){
754  global $lang;
755  global $ID;
756
757  print parsedLocale('register');
758?>
759  <div align="center">
760  <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
761  <input type="hidden" name="do" value="register" />
762  <input type="hidden" name="save" value="1" />
763  <fieldset>
764    <legend><?=$lang['register']?></legend>
765    <label>
766      <?=$lang['user']?>
767      <input type="text" name="login" class="edit" size="50" value="<?=formText($_POST['login'])?>" />
768    </label><br />
769    <label>
770      <?=$lang['fullname']?>
771      <input type="text" name="fullname" class="edit" size="50" value="<?=formText($_POST['fullname'])?>" />
772    </label><br />
773    <label>
774      <?=$lang['email']?>
775      <input type="text" name="email" class="edit" size="50" value="<?=formText($_POST['email'])?>" />
776    </label><br />
777    <input type="submit" class="button" value="<?=$lang['register']?>" />
778  </fieldset>
779  </form>
780  </div>
781<?
782}
783
784/**
785 * This displays the edit form (lots of logic included)
786 */
787function html_edit($text=null,$include='edit'){ //FIXME: include needed?
788  global $ID;
789  global $REV;
790  global $DATE;
791  global $RANGE;
792  global $PRE;
793  global $SUF;
794  global $INFO;
795  global $SUM;
796  global $lang;
797  global $conf;
798
799  //check for create permissions first
800  if(!$INFO['exists'] && !html_acl(AUTH_CREATE)) return;
801
802  //set summary default
803  if(!$SUM){
804    if($REV){
805      $SUM = $lang['restored'];
806    }elseif(!$INFO['exists']){
807      $SUM = $lang['created'];
808    }
809  }
810
811  //no text? Load it!
812  if(!isset($text)){
813    $pr = false; //no preview mode
814    if($RANGE){
815      list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
816    }else{
817      $text = rawWiki($ID,$REV);
818    }
819  }else{
820    $pr = true; //preview mode
821  }
822
823  $wr = $INFO['writable'];
824  if($wr){
825    if ($REV) print parsedLocale('editrev');
826    print parsedLocale($include);
827  }else{
828    print parsedLocale('read');
829    $ro='readonly="readonly"';
830  }
831  if(!$DATE) $DATE = $INFO['lastmod'];
832?>
833  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" onsubmit="return svchk()">
834  <input type="hidden" name="id"   value="<?=$ID?>" />
835  <input type="hidden" name="rev"  value="<?=$REV?>" />
836  <input type="hidden" name="date" value="<?=$DATE?>" />
837  <input type="hidden" name="prefix" value="<?=formText($PRE)?>" />
838  <input type="hidden" name="suffix" value="<?=formText($SUF)?>" />
839  <table style="width:99%">
840    <tr>
841      <td class="toolbar" colspan="3">
842        <?if($wr){?>
843        <script language="JavaScript" type="text/javascript">
844          <?/* sets changed to true when previewed */?>
845          textChanged = <? ($pr) ? print 'true' : print 'false' ?>;
846
847          formatButton('images/bold.png','<?=$lang['qb_bold']?>','**','**','<?=$lang['qb_bold']?>','b');
848          formatButton('images/italic.png','<?=$lang['qb_italic']?>',"\/\/","\/\/",'<?=$lang['qb_italic']?>','i');
849          formatButton('images/underline.png','<?=$lang['qb_underl']?>','__','__','<?=$lang['qb_underl']?>','u');
850          formatButton('images/code.png','<?=$lang['qb_code']?>','\'\'','\'\'','<?=$lang['qb_code']?>','c');
851
852          formatButton('images/fonth1.png','<?=$lang['qb_h1']?>','====== ',' ======\n','<?=$lang['qb_h1']?>','1');
853          formatButton('images/fonth2.png','<?=$lang['qb_h2']?>','===== ',' =====\n','<?=$lang['qb_h2']?>','2');
854          formatButton('images/fonth3.png','<?=$lang['qb_h3']?>','==== ',' ====\n','<?=$lang['qb_h3']?>','3');
855          formatButton('images/fonth4.png','<?=$lang['qb_h4']?>','=== ',' ===\n','<?=$lang['qb_h4']?>','4');
856          formatButton('images/fonth5.png','<?=$lang['qb_h5']?>','== ',' ==\n','<?=$lang['qb_h5']?>','5');
857
858          formatButton('images/link.png','<?=$lang['qb_link']?>','[[',']]','<?=$lang['qb_link']?>','l');
859          formatButton('images/extlink.png','<?=$lang['qb_extlink']?>','[[',']]','http://www.example.com|<?=$lang['qb_extlink']?>');
860
861          formatButton('images/list.png','<?=$lang['qb_ol']?>','  - ','\n','<?=$lang['qb_ol']?>');
862          formatButton('images/list_ul.png','<?=$lang['qb_ul']?>','  * ','\n','<?=$lang['qb_ul']?>');
863
864          insertButton('images/rule.png','<?=$lang['qb_hr']?>','----\n');
865          mediaButton('images/image.png','<?=$lang['qb_media']?>','m','<?=$INFO['namespace']?>');
866
867					<?
868          if($conf['useacl'] && $_SERVER['REMOTE_USER']){
869            echo "insertButton('images/sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
870          }
871          ?>
872        </script>
873        <?}?>
874      </td>
875    </tr>
876    <tr>
877      <td colspan="3">
878        <textarea name="wikitext" id="wikitext" <?=$ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" tabindex="1"><?="\n".formText($text)?></textarea>
879      </td>
880    </tr>
881    <tr>
882      <td>
883      <?if($wr){?>
884        <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" />
885        <input class="button" type="submit" name="do" value="<?=$lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" />
886        <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" tabindex="5" />
887      <?}?>
888      </td>
889      <td>
890      <?if($wr){?>
891        <?=$lang['summary']?>:
892        <input type="text" class="edit" name="summary" size="50" value="<?=formText($SUM)?>" tabindex="2" />
893      <?}?>
894      </td>
895      <td align="right">
896        <script type="text/javascript">
897          showSizeCtl();
898          <?if($wr){?>
899            init_locktimer(<?=$conf['locktime']-60?>,'<?=$lang['willexpire']?>');
900					  document.editform.wikitext.focus();
901          <?}?>
902        </script>
903      </td>
904    </tr>
905  </table>
906  </form>
907<?
908}
909
910/**
911 * prepares the signature string as configured in the config
912 */
913function html_signature(){
914  global $conf;
915  global $INFO;
916
917  $sig = $conf['signature'];
918  $sig = strftime($sig);
919  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
920  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
921  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
922  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
923  return $sig;
924}
925
926/**
927 * prints some debug info
928 */
929function html_debug(){
930  global $conf;
931
932  print '<html><body>';
933
934  print '<p>When reporting bugs please send all the following ';
935  print 'output as a mail to andi@splitbrain.org ';
936  print 'The best way to do this is to save this page in your browser</p>';
937
938  print '<b>$_SERVER:</b><pre>';
939  print_r($_SERVER);
940  print '</pre>';
941
942  print '<b>$conf:</b><pre>';
943  print_r($conf);
944  print '</pre>';
945
946  print '<b>abs baseURL:</b><pre>';
947  print getBaseURL(true);
948  print '</pre>';
949
950  print '<b>rel baseURL:</b><pre>';
951  print dirname($_SERVER['PHP_SELF']).'/';
952  print '</pre>';
953
954  print '<b>PHP Version:</b><pre>';
955  print phpversion();
956  print '</pre>';
957
958  print '<b>locale:</b><pre>';
959  print setlocale(LC_ALL,0);
960  print '</pre>';
961
962  print '<b>Environment:</b><pre>';
963  print_r($_ENV);
964  print '</pre>';
965
966  print '<b>PHP settings:</b><pre>';
967  $inis = ini_get_all();
968  print_r($inis);
969  print '</pre>';
970
971  print '</body></html>';
972}
973
974?>
975